今天發現了一個比較有意思的監控工具,是基於Django開發的,開發大牛已經開放了原始碼,向大牛致敬,同時研究研究,目前感覺這個監控比較直觀,可以針對個人伺服器使用,同時涉及的環境比較簡單,部署起來很方便。
安裝pyDash
安裝python、pip、git
首先工具是基於python開發的,所以我們需要python以及pip工具,簡單的是,一般情況下我們的伺服器在安裝系統時就已經安裝好python2.x環境了,python2.x已經完全可以支撐此監控工具的執行了,所以這點我們不需要擔心太多,安裝git是因為我們需要克隆原始碼。
yum -y install epel-release python pip git
克隆pyDash原始碼
git clone https://gitlab.com/k3oni/pydash.git
安裝相應版本的Django
不難理解,因為是基於Django開發,所以我們必須有相應的環境,才能支援軟體的執行。
cd pydash
pip install -r requirements.txt
需要相應的Django版本號,作者已經寫入
requirements.txt
配置檔案,我們只需要使用pip
指定檔案進行安裝即可。
修改加密檔案
vi pydash/settings.py
"""
Django settings for pydash project.
For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# SITE_ID = 1
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '111aaa...'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
TEMPLATE_DEBUG = False
ADMINS = (
)
MANAGERS = ADMINS
#All refresh values are in miliseconds, 1 second = 1000 miliseconds
#Adjust accordingly as you wish
TIME_JS_REFRESH = 30000
TIME_JS_REFRESH_LONG = 120000
TIME_JS_REFRESH_NET = 2000
VERSION = "1.4.6"
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = (
#'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
#'django.contrib.sites',
'django.contrib.staticfiles',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'pydash.urls'
WSGI_APPLICATION = 'pydash.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3')
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'),)
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/
STATIC_ROOT = os.path.join(os.path.dirname(__file__), '..', 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
try:
from local_settings import *
except ImportError:
pass
修改配置檔案中SECRET_KEY = '111aaa...'
配置即可,修改後儲存退出。
建立管理員賬戶
python manage.py syncdb
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use 'root'): admin
Email address: federicosun@163.com
Password:
Password (again):
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
根據相關提示設定即可。
啟動pyDash服務
nohup python manage.py runserver 0.0.0.0:1234 &
檢視展示介面
使用我們剛剛設定的賬號密碼進行登入。
麻雀雖小五臟俱全,向大牛學習,爭取自己早日可以自己編出實用程式。