安装Glances

https://github.com/nicolargo/glances # github

https://glances.readthedocs.io/en/latest/ # 官方文档

Requirements
  • python>=2.7 or python>=3.4
  • psutil>=5.3.0 (better with latest version)
  • defusedxml (in order to monkey patch xmlrpc)
  • future (for Python 2 support)

python和pip安装:

ubuntu安装py

安装glances:

curl -L https://bit.ly/glances | /bin/bash 或

wget -O- https://bit.ly/glances | /bin/bash

脚本有问题,修改内容在gitee sh仓库

直接 sudo bash glances.sh就可以运行

启动Glances:

<font style="background-color:rgb(250, 250, 250);">glances</font>
退出 Glances 终端,按 ESC 键或 Ctrl + C

默认情况下,时间间隔(LCTT 译注:显示数据刷新的时间间隔)是 1 秒,不过你可以在从终端启动 Glances 时自定义时间间隔

把时间间隔设为 5 秒,

<font style="background-color:rgb(250, 250, 250);">glances -t 5</font>

psensor

https://wpitchoune.net/psensor/


Glances访问

pip install bottle 依赖包安装

glances -w 命令即可开启

ufw allow 61208/tcp 开启防火墙

通过浏览器ip:port就可访问

配置服务

sudo vi /usr/lib/systemd/system/glancesweb.service

  1. [Unit]
  2. Description = Glances in Web Server Mode
  3. After = network.target
  4. [Service]
  5. ExecStart = glances -w -t 30
  6. [Install]
  7. WantedBy = multi-user.target

保存并关闭文件,然后使用以下命令重新载入 systemd 守护进程:

sudo systemctl daemon-reload

启动 Glances 服务并使其在系统重新启动时启动:

sudo systemctl start glancesweb
systemctl enable glancesweb

systemctl disable glancesweb

状态检查:

systemctl status glancesweb

Glances - 图1

温度监控

apt install lm-sensors # 安装 lm-sensors

sudo sensors-detect 然后一直回车即可# 配置 lm-sensors

sensors

Glances - 图2

  • Tctl 和 Tdie 都是cpu温度 据说Tdie准确一点,不了解这个

glances交互模式快捷键

  • 2 显示隐藏整个侧栏
  • <font style="color:rgb(77, 77, 77);">d</font> 磁盘
  • <font style="color:rgb(77, 77, 77);">f</font> 文件系统
  • <font style="color:rgb(77, 77, 77);">n</font> 网络
  • <font style="color:rgb(77, 77, 77);">s</font> 传感器

glances使用

Glances 有 4 种颜色标记,分别表示不同的紧急程度:

  • 绿色:OK
  • 蓝色:CAREFUL
  • 紫色:WARNING
  • 红色:CRITICAL

glances 是一个命令行工具包括如下命令选项:

  • -b:显示网络连接速度 Byte/ 秒
  • -B @IP|host :绑定服务器端 IP 地址或者主机名称
  • -c @IP|host:连接 glances 服务器端
  • -C file:设置配置文件默认是 /etc/glances/glances.conf
  • -d:关闭磁盘 I/O 模块
  • -e:显示传感器温度
  • -f file:设置输出文件(格式是 HTML 或者 CSV)
  • -m:关闭挂载的磁盘模块
  • -n:关闭网络模块
  • -p PORT:设置运行端口默认是 61209
  • -P password:设置客户端 / 服务器密码
  • -s:设置 glances 运行模式为服务器
  • -t sec:设置屏幕刷新的时间间隔,单位为秒,默认值为 2 秒,数值范围:1~32767
  • -h : 显示帮助信息
  • -v : 显示版本信息

glances 可以使用交互式的方式运行该工具,用户可以使用如下快捷键:

  • h :显示帮助信息
  • q :离开程序退出
  • c :按照 CPU 实时负载对系统进程进行排序
  • m :按照内存使用状况对系统进程排序
  • i:按照 I/O 使用状况对系统进程排序
  • p:按照进程名称排序
  • d :显示磁盘读写状况
  • w :删除日志文件
  • l :显示日志
  • s:显示传感器信息
  • f :显示系统信息
  • 1 :轮流显示每个 CPU 内核的使用情况