005、Glances命令
本文最后更新于 65 天前,其中的信息可能已经过时,如有错误请发送邮件到wuxianglongblog@163.com

Glances命令

一 Glances简介

1.1 glances介绍

Glances是一个跨平台的监控工具,旨在通过curses 或基于Web 的界面呈现大量监控信息。该信息根据用户界面的大小动态调整。
它也可以在客户端/服务器模式下工作。远程监控可以通过终端、Web 界面或 API(XML-RPC 和 RESTful)完成。统计数据也可以导出到文件或外部时间/值数据库。
Glances 是用 Python 编写的,并使用库从您的系统中获取信息。它基于开放式架构,开发人员可以在其中添加新插件或导出模块。
更强大的 htop / top 代替者。

1.2 参考文档

https://glances.readthedocs.io/en/latest/install.html
https://nicolargo.github.io/glances/
https://github.com/nicolargo/glances

二 glances 安装

2.1 glances 安装方式

2.2.1 安装要求
python>=2.7 or python>=3.4
2.2.2 自动安装脚本
2.2.2.1 方式一

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

2.2.2.2 方式二

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

2.2.3 基于pip
2.2.3.1 pip命令安装glances

按需执行, 三选一即可

$ pip install glances
$ pip install glances[all]
$ pip install glances[action,browser,cloud,cpuinfo,docker,export,folders,gpu,graph,ip,raid,snmp,web,wifi]

2.2.3.2 pip命令升级glances

按需执行,三选一

$ pip install --upgrade glances
$ pip install --upgrade psutil
$ pip install --upgrade glances[all]

2.2.4 基于源安装
2.2.4.1 ubuntu系统

root@wgs:~# apt -y install glances

2.2.4.2 centos7系统

[root@wgs ~]# yum -y install glances

三 glances 使用帮助

root@wgs:~# glances -h
usage: glances [-h] [-V] [-d] [-C CONF_FILE] [--modules-list] [--disable-plugin DISABLE_PLUGIN] [--enable-plugin ENABLE_PLUGIN] [--disable-process] [--disable-webui] [--light] [-0] [-1] [-2] [-3] [-4] [-5] [-6] [--disable-history] [--disable-bold] [--disable-bg]
               [--enable-irq] [--enable-process-extended] [--export EXPORT] [--export-csv-file EXPORT_CSV_FILE] [--export-csv-overwrite] [--export-json-file EXPORT_JSON_FILE] [--export-graph-path EXPORT_GRAPH_PATH] [-c CLIENT] [-s] [--browser] [--disable-autodiscover]
               [-p PORT] [-B BIND_ADDRESS] [--username] [--password] [-u USERNAME_USED] [--snmp-community SNMP_COMMUNITY] [--snmp-port SNMP_PORT] [--snmp-version SNMP_VERSION] [--snmp-user SNMP_USER] [--snmp-auth SNMP_AUTH] [--snmp-force] [-t TIME] [-w]
               [--cached-time CACHED_TIME] [--open-web-browser] [-q] [-f PROCESS_FILTER] [--process-short-name] [--stdout STDOUT] [--stdout-csv STDOUT_CSV] [--hide-kernel-threads] [-b] [--diskio-show-ramfs] [--diskio-iops] [--fahrenheit] [--fs-free-space]
               [--sparkline] [--theme-white] [--disable-check-update]

optional arguments:
  -h, --help            show this help message and exit
  -V, --version         show program's version number and exit
  -d, --debug           enable debug mode
  -C CONF_FILE, --config CONF_FILE
                        path to the configuration file
  --modules-list, --module-list
                        display modules (plugins & exports) list and exit
  --disable-plugin DISABLE_PLUGIN, --disable-plugins DISABLE_PLUGIN
                        disable plugin (comma separed list)
  --enable-plugin ENABLE_PLUGIN, --enable-plugins ENABLE_PLUGIN
                        enable plugin (comma separed list)
  --disable-process     disable process module
  --disable-webui       disable the Web Interface
  --light, --enable-light
                        light mode for Curses UI (disable all but top menu)
  -0, --disable-irix    task's cpu usage will be divided by the total number of CPUs
  -1, --percpu                                          #start Glances in per CPU mode
  -2, --disable-left-sidebar                            #禁用网络、磁盘 I/O、FS 和传感器模块
  -3, --disable-quicklook                               #禁用快速查看模块
  -4, --full-quicklook                                  #禁用除快速查看和加载之外的所有功能
  -5, --disable-top                                     #禁用顶部菜单(QL、CPU、MEM、SWAP 和 LOAD)
  -6, --meangpu                                         #start Glances in mean GPU mode
  --disable-history                                     #禁用统计历史
  --disable-bold                                        #在终端中禁用粗体模式
  --disable-bg                                          #禁用终端中的背景颜色
  --enable-irq                                          #启用 IRQ 模块
  -enable-process-extended                              #启用顶级进程的扩展统计信息
  --export EXPORT                                       #启用导出模块(逗号分隔列表)
  --export-csv-file EXPORT_CSV_FILE                     #CSV 导出器的文件路径
  --export-csv-overwrite                                #覆盖现有的 CSV 文件
  --export-json-file EXPORT_JSON_FILE                   #JSON 导出器的文件路径
  --export-graph-path EXPORT_GRAPH_PATH                 # 图形导出器的路径
  -c CLIENT, --client CLIENT                            #通过 IPv4/IPv6 地址或主机名连接到 Glances 服务器
  -s, --server                                          #在服务器模式下运行 Glances
  --browser                                             #启动客户端浏览器(服务器列表)
  --disable-autodiscover                                #禁用自动发现功能
  -p PORT, --port PORT                                  #定义客户端/服务器 TCP 端口 [默认:61209]
  -B BIND_ADDRESS, --bind BIND_ADDRESS                  #将服务器绑定到给定的 IPv4/IPv6 地址或主机名
  --username                                            #定义客户端/服务器用户名
  --password                                            #定义客户端/服务器密码
  -u USERNAME_USED                                      #使用给定的客户端/服务器用户名
 --snmp-community SNMP_COMMUNITY                        #SNMP community
  --snmp-port SNMP_PORT                                 #SNMP端口
  --snmp-version SNMP_VERSION                           #SNMP 版本(1、2c 或 3)
  --snmp-user SNMP_USER                                 #SNMP 用户名(仅适用于 SNMPv3)
  --snmp-auth SNMP_AUTH                                 #SNMP 认证密钥(仅适用于 SNMPv3)
  --snmp-force                                          #强制 SNMP 模式
  -t TIME, --time TIME                                  #以秒为单位设置刷新时间 [默认:3 秒]
  -w, --webserver                                       #在网络服务器模式下运行 Glances
  --cached-time CACHED_TIME                             #设置服务器缓存时间 [默认:1 秒]
  --open-web-browser                                    #尝试在默认 Web 浏览器中打开 Web UI
  -q, --quiet                                           #不显示curses界面
  -f PROCESS_FILTER, --process-filter PROCESS_FILTER    #设置进程过滤模式(正则表达式)
  --process-short-name                                  #强制进程名称的简称
  --stdout STDOUT                                       #向标准输出显示统计数据,每行一个统计数据(插件/plugins.attribute 的逗号分隔列表)
  --stdout-csv STDOUT_CSV                               #将统计信息显示为标准输出,csv 格式(插件/plugins.attribute 的逗号分隔列表)
  --hide-kernel-threads                                 #在进程列表中隐藏内核线程(在 Windows 上不可用)   
  -b, --byte                                            #以每秒字节数显示网络速率
  --diskio-show-ramfs                                   #在 DiskIO 插件中显示 RAM Fs
  --diskio-iops                                         #在 DiskIO 插件中显示每秒 IO
  --fahrenheit                                          #以华氏度显示温度(默认为摄氏度)
  --fs-free-space                                       #显示 FS 可用空间而不是已用空间
  --sparkline                                           #在curses界面中显示迷你图而不是条形图
  --theme-white                                         #优化白色背景的显示颜色
  --disable-check-update                                #禁用在线 Glances 版本检查

Examples of use:
  Monitor local machine (standalone mode):
    $ glances

  Display all Glances modules (plugins and exporters) and exit:
    $ glances --module-list

  Monitor local machine with the Web interface and start RESTful server:
    $ glances -w
    Glances web server started on http://0.0.0.0:61208/

  Only start RESTful API (without the WebUI):
    $ glances -w --disable-webui
    Glances API available on http://0.0.0.0:61208/api/

  Monitor local machine and export stats to a CSV file (standalone mode):
    $ glances --export csv --export-csv-file /tmp/glances.csv

  Monitor local machine and export stats to a InfluxDB server with 5s refresh time (standalone mode):
    $ glances -t 5 --export influxdb

  Start a Glances XML/RCP server (server mode):
    $ glances -s

  Connect Glances to a Glances XML/RCP server (client mode):
    $ glances -c <ip_server>

  Connect Glances to a Glances server and export stats to a StatsD server (client mode):
    $ glances -c <ip_server> --export statsd

  Start the client browser (browser mode):
    $ glances --browser

  Display stats to stdout (one stat per line):
    $ glances --stdout now,cpu.user,mem.used,load

  Display CSV stats to stdout (all stats in one line):
    $ glances --stdout-csv now,cpu.user,mem.used,load

  Disable some plugins (comma separated list):
    $ glances --disable-plugin network,ports

  Enable some plugins (comma separated list):
    $ glances --enable-plugin sensors

四 glances 运行模式

4.1 Standalone Mode

更强大的 htop / top 代替者
如果要监视本地计算机,请打开控制台/终端并运行glances,按“q”或“ESC”退出

img

root@wgs:~# glances
使用交互式的方式运行该工具,用户可以使用如下快捷键:
 h : 显示帮助信息
q : 离开程序退出
c :按照 CPU 实时负载对系统进程进行排序
m :按照内存使用状况对系统进程排序
 i:按照 I/O 使用状况对系统进程排序
p: 按照进程名称排序
d : 显示磁盘读写状况 
w : 删除日志文件
l :显示日志
s: 显示传感器信息
f : 显示系统信息
1 :轮流显示每个 CPU 内核的使用情况

4.2 glances C/S模式

4.2.1 server端

在服务器模式下,您可以使用-B ADDRESS设置绑定地址和-p PORT 指定TCP端口。
默认绑定地址是0.0.0.0(Glances 会监听所有可用的网络接口),TCP 端口是61209.

root@server:~# glances -s
4.2.2 client端

@server 替换成自己server端IP

root@client:~# glances -c @server

4.3 web server mode

4.3.1 server端
root@server:~# glances -w
4.3.2 client端

浏览器访问 http://@server:61208
@server 替换成server端的IP

4.3.3 更改页面刷新率

10s刷新一次
http://@server:61208/10
@server 替换成server端的IP

谨此笔记,记录过往。凭君阅览,如能收益,莫大奢望。
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇