手把手教你安裝Linux性能監控工具——pydash

微信公衆號:wanpython
關注便可獲取python網絡爬蟲、數據分析、機器學習、大數據等學習資料,期待你的加入!
若有建議意見,歡迎留言html

今日突發奇想,想查看一下服務器各硬件的負載狀況,可是使用free、top等這些linux命令,智能看到一堆數據,不能可視化展示網絡、內存、內存使用狀況python

因而,通過查資料,發現了一個比較好用的工具:pydashlinux

pydash是一個基於python和django的性能監測工具。能夠運行在centos、ubuntu等主流的linux發行版本上,可以統計服務器資源,監控服務器性能git

效果展現

話很少說,先來幾張圖片看看效果:
shell




講真,效果仍是能夠的

安裝過程

建議初次安裝,請儘可能在測試機上實現數據庫

1. 使用git克隆pydash到本地

此處認爲你已經安裝好了git和python(不管是python2.x,仍是python3.x)django

克隆pydash到本地ubuntu

git clone https://gitlab.com/k3oni/pydash.git
cd pydash
複製代碼

顯示結果:centos

正克隆到 '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. 建立虛擬環境

爲了避免與服務器上現有環境衝突,此處建立虛擬環境,全部操做在虛擬環境中進行python3.x

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 10in <module>
    execute_from_command_line(sys.argv)
  File "/home/jh/pydash/pydashtest/lib/python3.6/site-packages/django/core/management/__init__.py", line 399in execute_from_command_line
    utility.execute()
  File "/home/jh/pydash/pydashtest/lib/python3.6/site-packages/django/core/management/__init__.py", line 392in 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 261in fetch_command
    commands = get_commands()
  File "/home/jh/pydash/pydashtest/lib/python3.6/site-packages/django/core/management/__init__.py", line 107in get_commands
    apps = settings.INSTALLED_APPS
  File "/home/jh/pydash/pydashtest/lib/python3.6/site-packages/django/conf/__init__.py", line 54in __getattr__
    self._setup(name)
  File "/home/jh/pydash/pydashtest/lib/python3.6/site-packages/django/conf/__init__.py", line 50in _setup
    self._configure_logging()
  File "/home/jh/pydash/pydashtest/lib/python3.6/site-packages/django/conf/__init__.py", line 72in _configure_logging
    from django.utils.log import DEFAULT_LOGGING
  File "/home/jh/pydash/pydashtest/lib/python3.6/site-packages/django/utils/log.py", line 7in <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 12in <module>
    from django.template import TemplateContext, TemplateDoesNotExist
  File "/home/jh/pydash/pydashtest/lib/python3.6/site-packages/django/template/__init__.py", line 53in <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 19in <module>
    from django.utils.html import escape
  File "/home/jh/pydash/pydashtest/lib/python3.6/site-packages/django/utils/html.py", line 14in <module>
    from .html_parser import HTMLParser, HTMLParseError
  File "/home/jh/pydash/pydashtest/lib/python3.6/site-packages/django/utils/html_parser.py", line 12in <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.

解決辦法:

  1. 下降python的版本
  2. 升級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.
複製代碼

此處的UsernamePassword,就是監控系統登陸的用戶名和密碼,郵箱可寫可不寫

6. 啓動服務(後臺)

以上步驟無誤後,就能夠啓動服務了,此處採用後臺運行的方式

nohup python ./manage.py runserver 192.168.0.3:8000 &
複製代碼

結果:

Performing system checks...

System check identified no issues (0 silenced).
April 032019 - 00:58:37
Django version 1.8using 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步設置的用戶名和密碼就能登陸系統了

關注我,不迷路

下面的是個人公衆號二維碼圖片,歡迎關注。

相關文章
相關標籤/搜索