手把手教你安装Linux性能监控工具——pydash

微信公众号:wanpython
关注便可获取python网络爬虫、数据分析、机器学习、大数据等学习资料,期待你的加入!
若有建议意见,欢迎留言css

今日突发奇想,想查看一下服务器各硬件的负载状况,可是使用free、top等这些linux命令,智能看到一堆数据,不能可视化展示网络、内存、内存使用状况html

因而,通过查资料,发现了一个比较好用的工具:pydashpython

pydash是一个基于python和django的性能监测工具。能够运行在centos、ubuntu等主流的linux发行版本上,可以统计服务器资源,监控服务器性能linux

效果展现

话很少说,先来几张图片看看效果:
nginx




讲真,效果仍是能够的

安装过程

建议初次安装,请尽可能在测试机上实现git

1. 使用git克隆pydash到本地

此处认为你已经安装好了git和python(不管是python2.x,仍是python3.x)sql

克隆pydash到本地shell

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. 建立虚拟环境

为了避免与服务器上现有环境冲突,此处建立虚拟环境,全部操做在虚拟环境中进行django

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步设置的用户名和密码就能登陆系统了

关注我,不迷路

下面的是个人公众号二维码图片,欢迎关注。

相关文章
相关标签/搜索