编译自:http://www.tecmint.com/pydash-a-web-based-linux-performance-monitoring-tool/作者: Ravi Saive

<span style="text-align: left; color: rgb(153, 153, 153); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: &quot;Lantinghei SC&quot;, &quot;Helvetica Neue&quot;, &quot;Microsoft YaHei&quot;, 微软雅黑, Arial, STHeiti, &quot;WenQuanYi Micro Hei&quot;, SimSun, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; word-spacing: 0px; white-space: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;">原创:[LCTT](https://linux.cn/lctt/)<span style="background-color: inherit;">&nbsp;</span>[https://linux.cn/article-8462-1.html](https://linux.cn/article-8462-1.html)</span><span style="text-align: left; color: rgb(153, 153, 153); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: &quot;Lantinghei SC&quot;, &quot;Helvetica Neue&quot;, &quot;Microsoft YaHei&quot;, 微软雅黑, Arial, STHeiti, &quot;WenQuanYi Micro Hei&quot;, SimSun, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; word-spacing: 0px; white-space: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;">译者:<span style="background-color: inherit;">&nbsp;</span>[ucasFL](https://linux.cn/lctt/ucasFL)</span>

`pyDash` 是一个轻量且[基于 web 的 Linux 性能监测工具](http://www.tecmint.com/command-line-tools-to-monitor-linux-performance/),它是用 Python 和 [Django](http://www.tecmint.com/install-and-configure-django-web-framework-in-centos-debian-ubuntu/) 加上 Chart.js 来写的。经测试,在下面这些主流 Linux 发行版上可运行:CentOS、Fedora、Ubuntu、Debian、Raspbian 以及 Pidora 。

你可以使用这个工具来监视你的 Linux 个人电脑/服务器资源,比如 CPU、内存、网络统计,包括在线用户的进程以及更多。仪表盘完全由主要的 Python 发行版本所提供的 Python 库开发,因此它的依赖关系很少,你不需要安装许多包或库来运行它。

在这篇文章中,我将展示如何安装 `pyDash` 来监测 Linux 服务器性能。

###
如何在 Linux 系统下安装 pyDash

1、首先,像下面这样安装需要的软件包 `git` 和 `Python pip`:
  1. <span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">--------------</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">在</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> </span><span class="typ" style="color: rgb(137, 189, 255); -ms-word-wrap: break-word;">Debian</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">/</span><span class="typ" style="color: rgb(137, 189, 255); -ms-word-wrap: break-word;">Ubuntu</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">上</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">--------------</span>
  2. <span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">$ </span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word;">sudo</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> </span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word;">apt-get</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> install </span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word;">git</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> python</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">-</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">pip</span>
  3. <span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">--------------</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">在</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> </span><span class="typ" style="color: rgb(137, 189, 255); -ms-word-wrap: break-word;">CentOS</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">/</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">RHEL </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">上</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">--------------</span>
  4. <span class="com" style="color: rgb(174, 174, 174); font-style: italic; -ms-word-wrap: break-word;">#</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> </span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word;">yum</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> install epel</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">-</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">release</span>
  5. <span class="com" style="color: rgb(174, 174, 174); font-style: italic; -ms-word-wrap: break-word;">#</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> </span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word;">yum</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> install </span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word;">git</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> python</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">-</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">pip</span>
  6. <span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">--------------</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">在</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> </span><span class="typ" style="color: rgb(137, 189, 255); -ms-word-wrap: break-word;">Fedora</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> </span><span class="lit" style="color: rgb(51, 135, 204); -ms-word-wrap: break-word;">22</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">+</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">上</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">--------------</span>
  7. <span class="com" style="color: rgb(174, 174, 174); font-style: italic; -ms-word-wrap: break-word;">#</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> dnf install </span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word;">git</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> python</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">-</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">pip</span>

    2、如果安装好了 git 和 Python pip,那么接下来,像下面这样安装 virtualenv,它有助于处理针对 Python 项目的依赖关系:

  8. <span class="com" style="color: rgb(174, 174, 174); font-style: italic; -ms-word-wrap: break-word;">#</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> pip install virtualenv</span>

  9. <span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">或</span>
  10. <span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">$ </span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word;">sudo</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> pip install virtualenv</span>

    3、现在,像下面这样使用 git 命令,把 pyDash 仓库克隆到 home 目录中:

  11. <span class="com" style="color: rgb(174, 174, 174); font-style: italic; -ms-word-wrap: break-word;">#</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> </span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word;">git</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> </span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word;">clone</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> https</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">:</span><span class="com" style="color: rgb(174, 174, 174); font-style: italic; -ms-word-wrap: break-word;">//github.com/k3oni/pydash.git</span>

  12. <span class="com" style="color: rgb(174, 174, 174); font-style: italic; -ms-word-wrap: break-word;">#</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> </span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word;">cd</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> pydash</span>

    4、下一步,使用下面的 virtualenv 命令为项目创建一个叫做 pydashtest 虚拟环境:

  13. <span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">$ virtualenv pydashtest </span><span class="com" style="color: rgb(174, 174, 174); font-style: italic; -ms-word-wrap: break-word;">#</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">give a name </span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word;">for</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> your </span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word;">virtual</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> environment like pydashtest</span>

    Create Virtual Environment

    创建虚拟环境

    重要:请注意,上面的屏幕截图中,虚拟环境的 bin 目录被高亮显示,你的可能和这不一样,取决于你把 pyDash 目录克隆到什么位置。

    5、创建好虚拟环境(pydashtest)以后,你需要在使用前像下面这样激活它:

  14. <span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">$ source </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">/</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">home</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">/</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">aaronkilik</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">/</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">pydash</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">/</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">pydashtest</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">/</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">bin</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">/</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">activate</span>

    Active Virtual Environment

    激活虚拟环境

    从上面的屏幕截图中,你可以注意到,提示字符串 1(PS1)已经发生改变,这表明虚拟环境已经被激活,而且可以开始使用。

    6、现在,安装 pydash 项目 requirements;如何你好奇的话,可以使用 cat 命令查看 requirements.txt 的内容,然后像下面所示那样进行安装:

  15. <span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">$ </span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word;">cat</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> requirements</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">.</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">txt</span>

  16. <span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">$ pip install </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">-</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">r requirements</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">.</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">txt</span>

    7、现在,进入 pydash 目录,里面包含一个名为 settings.py 的文件,也可直接运行下面的命令打开这个文件,然后把 SECRET_KEY 改为一个特定值:

  17. <span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">$ </span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word;">vi</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> pydash</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">/</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">settings</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">.</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">py</span>

    Set Secret Key

    设置密匙

    保存文件然后退出。

    8、之后,运行下面的命令来创建一个项目数据库和安装 Django 的身份验证系统,并创建一个项目的超级用户:

  18. <span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">$ python manage</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">.</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">py syncdb</span>

    根据你的情况回答下面的问题:

  19. <span class="typ" style="color: rgb(137, 189, 255); -ms-word-wrap: break-word;">Would</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> you like to create one now</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">?</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">(</span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word;">yes</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">/</span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word;">no</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">):</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> </span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word;">yes</span>

  20. <span class="typ" style="color: rgb(137, 189, 255); -ms-word-wrap: break-word;">Username</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">(</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">leave blank to </span><span class="kwd" style="color: rgb(226, 137, 100); -ms-word-wrap: break-word;">use</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> </span><span class="str" style="color: rgb(101, 176, 66); -ms-word-wrap: break-word;">&#39;root&#39;</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">):</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> admin</span>
  21. <span class="typ" style="color: rgb(137, 189, 255); -ms-word-wrap: break-word;">Email</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> address</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">:</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> aaronkilik@gmail</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">.</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">com</span>
  22. <span class="typ" style="color: rgb(137, 189, 255); -ms-word-wrap: break-word;">Password</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">:</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> </span><span class="com" style="color: rgb(174, 174, 174); font-style: italic; -ms-word-wrap: break-word;">###########</span>
  23. <span class="typ" style="color: rgb(137, 189, 255); -ms-word-wrap: break-word;">Password</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> </span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">(</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">again</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">):</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;"> </span><span class="com" style="color: rgb(174, 174, 174); font-style: italic; -ms-word-wrap: break-word;">############</span>

    Create Project Database

    创建项目数据库

    9、这个时候,一切都设置好了,然后,运行下面的命令来启用 Django 开发服务器:

  24. <span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">$ python manage</span><span class="pun" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">.</span><span class="pln" style="color: rgb(184, 255, 184); -ms-word-wrap: break-word;">py runserver</span>

    10、接下来,打开你的 web 浏览器,输入网址:http://127.0.0.1:8000/ 进入 web 控制台登录界面,输入你在第 8 步中创建数据库和安装 Django 身份验证系统时创建的超级用户名和密码,然后点击登录。

    pyDash Login Interface

    pyDash 登录界面

    11、登录到 pydash 主页面以后,你将会可以看到监测系统的基本信息,包括 CPU、内存和硬盘使用量以及系统平均负载。

    向下滚动便可查看更多部分的信息。

    pyDash Server Performance Overview

    pydash 服务器性能概述

    12、下一个屏幕截图显示的是一段 pydash 的跟踪界面,包括 IP 地址、互联网流量、硬盘读/写、在线用户以及 netstats 。

    pyDash Network Overview

    pyDash 网络概述

    13、下一个 pydash 主页面的截图显示了一部分系统中被监视的活跃进程。

    pyDash Active Linux Processes

    pyDash 监视活跃 Linux 进程

    如果想了解更多信息,请在 GitHub 上查看 pydash:https://github.com/k3oni/pydash

    这就是全部内容了。在这篇文章中,我们展示了在 Linux 中如何安装 pyDash 并测试它的主要特性。如果你有什么想法,可以通过下面的反馈部分联系我们;如果你知道任何有用或类似的工具,也可以在评论中告知我们。