微信公眾號:wanpython
關注即可獲取python網路爬蟲、資料分析、機器學習、大資料等學習資料,期待你的加入!
如有建議意見,歡迎留言
今日突發奇想,想檢視一下伺服器各硬體的負載情況,但是使用free、top等這些linux命令,智慧看到一堆資料,不能視覺化展現網路、記憶體、記憶體使用情況
於是,經過查資料,發現了一個比較好用的工具:pydash
pydash
是一個基於python和django的效能監測工具。可以執行在centos、ubuntu等主流的linux發行版本上,能夠統計伺服器資源,監控伺服器效能
效果展示
話不多說,先來幾張圖片看看效果:
講真,效果還是可以的
安裝過程
建議初次安裝,請儘量在測試機上實現
1. 使用git克隆pydash到本地
此處認為你已經安裝好了git和python(無論是python2.x,還是python3.x)
克隆pydash到本地
git clone https://gitlab.com/k3oni/pydash.git
cd pydash
複製程式碼
顯示結果:
正克隆到 'pydash'...
remote: Enumerating objects: 1230, done.
remote: Counting objects: 100% (1230/1230), done.
remote: Compressing objects: 100% (588/588), done.
remote: Total 1230 (delta 625), reused 1230 (delta 625)
接收物件中: 100% (1230/1230), 1.25 MiB | 683.00 KiB/s, done.
處理 delta 中: 100% (625/625), done.
複製程式碼
2. 建立虛擬環境
為了不與伺服器上現有環境衝突,此處建立虛擬環境,所有操作在虛擬環境中進行
pip install virtualenv
virtualenv pydashtest
複製程式碼
如果建立python2.7版本的虛擬環境,建立命令如下:
virtualenv pydashtest --python=python2.7
複製程式碼
此時就建立好了虛擬環境pydashtest
Using base prefix '/usr/local'
New python executable in /home/jh/pydash/pydashtest/bin/python3.6
Also creating executable in /home/jh/pydash/pydashtest/bin/python
Installing setuptools, pip, wheel...
done.
複製程式碼
3. 啟用虛擬環境
source pydashtest/bin/activate
複製程式碼
此時會發現shell介面發生了變化:
(pydashtest) [jh@localhost pydash]$
說明已經進入虛擬環境,如果需要退出當前虛擬環境,使用命令
deactivate
複製程式碼
即可退出
4. 安裝django
由於pydash是基於python和django的,所以需要安裝django
有兩種方式,一種直接使用pydash
下的requirements.txt
檔案進行安裝
pip install -r requirements.txt
複製程式碼
此時,實際上安裝了django的1.6.8版本,如果python的版本高於3.5的話,在後續使用django命令建立專案的時候,會報如下錯誤:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/jh/pydash/pydashtest/lib/python3.6/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/home/jh/pydash/pydashtest/lib/python3.6/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/jh/pydash/pydashtest/lib/python3.6/site-packages/django/core/management/__init__.py", line 261, in fetch_command
commands = get_commands()
File "/home/jh/pydash/pydashtest/lib/python3.6/site-packages/django/core/management/__init__.py", line 107, in get_commands
apps = settings.INSTALLED_APPS
File "/home/jh/pydash/pydashtest/lib/python3.6/site-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/home/jh/pydash/pydashtest/lib/python3.6/site-packages/django/conf/__init__.py", line 50, in _setup
self._configure_logging()
File "/home/jh/pydash/pydashtest/lib/python3.6/site-packages/django/conf/__init__.py", line 72, in _configure_logging
from django.utils.log import DEFAULT_LOGGING
File "/home/jh/pydash/pydashtest/lib/python3.6/site-packages/django/utils/log.py", line 7, in <module>
from django.views.debug import ExceptionReporter, get_exception_reporter_filter
File "/home/jh/pydash/pydashtest/lib/python3.6/site-packages/django/views/debug.py", line 12, in <module>
from django.template import Template, Context, TemplateDoesNotExist
File "/home/jh/pydash/pydashtest/lib/python3.6/site-packages/django/template/__init__.py", line 53, in <module>
from django.template.base import (ALLOWED_VARIABLE_CHARS, BLOCK_TAG_END,
File "/home/jh/pydash/pydashtest/lib/python3.6/site-packages/django/template/base.py", line 19, in <module>
from django.utils.html import escape
File "/home/jh/pydash/pydashtest/lib/python3.6/site-packages/django/utils/html.py", line 14, in <module>
from .html_parser import HTMLParser, HTMLParseError
File "/home/jh/pydash/pydashtest/lib/python3.6/site-packages/django/utils/html_parser.py", line 12, in <module>
HTMLParseError = _html_parser.HTMLParseError
AttributeError: module 'html.parser' has no attribute 'HTMLParseError'
複製程式碼
原因:
HTMLParseError is deprecated from Python 3.3 onwards and removed in Python 3.5.
解決辦法:
- 降低python的版本
- 升級django的版本
此處採用第二種方法,直接安裝django較高版本為最方便最快捷的辦法
pip install django==1.8
複製程式碼
5. 建立專案資料庫,安裝Django身份驗證系統
python manage.py syncdb
複製程式碼
輸入使用者資訊:
Operations to perform:
Synchronize unmigrated apps: staticfiles, messages
Apply all migrations: contenttypes, sessions, auth
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Installing custom SQL...
Running migrations:
Rendering model states... DONE
Applying contenttypes.0001_initial... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0001_initial... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying sessions.0001_initial... OK
You have installed Django's auth system, and don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use 'jh'):
Email address: linupy@163.com
Password:
Password (again):
Superuser created successfully.
複製程式碼
此處的Username
和Password
,就是監控系統登入的使用者名稱和密碼,郵箱可寫可不寫
6. 啟動服務(後臺)
以上步驟無誤後,就可以啟動服務了,此處採用後臺執行的方式
nohup python ./manage.py runserver 192.168.0.3:8000 &
複製程式碼
結果:
Performing system checks...
System check identified no issues (0 silenced).
April 03, 2019 - 00:58:37
Django version 1.8, using settings 'pydash.settings'
Starting development server at http://192.168.0.3:8000/
Quit the server with CONTROL-C.
複製程式碼
瀏覽器輸入192.168.0.3:8000
,即可進入使用者登入介面
輸入第5步設定的使用者名稱和密碼就能登入系統了
關注我,不迷路
下面的是我的公眾號二維碼圖片,歡迎關注。