glances 命令详解与参数实测(Ubuntu 22.04)
在 Ubuntu 22.04(Glances 3.2.4.2 + PsUtil 5.9.0)上逐参数实测 glances:standalone 默认界面逐区解读、-1/-2/-0/-b/--fs-free-space/--sparkline/--disable-plugin/-f/--sort-processes 等 TUI 变体、--stdout/--stdout-csv 非交互输出、--issue/--api-doc/--modules-list、-s/-c 客户机服务器模式与 -w Web 模式 RESTful API 实测、--export 落盘行为与 curses 管道报错边界,全部命令与回显真实可复现。
glances 命令详解与参数实测(Ubuntu 22.04)
目标:全面掌握 glances 的核心参数——standalone 默认界面逐区解读、
-1逐核 /-2隐藏左栏 /-0CPU 口径 /-b字节网速 /--fs-free-space/--sparkline/--disable-plugin/-f进程过滤 /--sort-processes排序、--stdout/--stdout-csv非交互输出、--issue/--api-doc/--modules-list诊断三件套、-s/-c客户机服务器模式与-wWeb 模式 RESTful API,以及--export落盘行为与 curses 管道报错等边界,全部命令与回显已在 Ubuntu 22.04(Glances 3.2.4.2)实测通过。
一、环境信息
本篇所有命令均在以下环境中逐条实测,回显逐字照抄:
- 操作系统:Ubuntu 22.04.5 LTS(代号 jammy),内核 6.8.0-138-generic(x86_64)
- Glances 版本:v3.2.4.2,依赖 PsUtil 5.9.0,Python 3.10.12(由
glances --issue回显证实,模块位于/usr/lib/python3/dist-packages/glances) - CPU / 内存:12 逻辑核 / 31.3 GB / Swap 2 GB;测试环境 swap 挂满(界面将如实显示 SWAP 99.8%~100%)
- 终端规格 120 列 × 38 行;界面抓屏为真实终端输出还原;共享测试环境中另有少量其他会话进程,如实保留
版本与环境实测回显:
$ grep PRETTY_NAME /etc/os-release
PRETTY_NAME="Ubuntu 22.04.5 LTS"
$ glances --version
Glances v3.2.4.2 with PsUtil v5.9.0
Log file: /root/.local/share/glances/glances.log
$ pip3 show glances | head -4
Name: Glances
Version: 3.2.4.2
Summary: A cross-platform curses-based monitoring tool
Home-page: https://github.com/nicolargo/glances
二、命令概览
2.1 四种运行模式
glances 的参数围绕四种运行模式组织,--help 末尾的官方示例原文:
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
Only start RESTful API (without the WebUI):
$ glances -w --disable-webui
Monitor local machine and export stats to a CSV file (standalone mode):
$ glances --export csv --export-csv-file /tmp/glances.csv
Start a Glances XML-RPC server (server mode):
$ glances -s
Connect Glances to a Glances XML-RPC server (client mode):
$ glances -c <ip_server>
| 模式 | 启动参数 | 说明 |
|---|---|---|
| standalone | glances | 本机全屏 TUI(默认,2 秒刷新) |
| server / client | glances -s / glances -c <ip> | 中心化监控:服务器暴露、客户端连入 |
| web | glances -w | Web UI + RESTful API(默认端口 61208) |
| export | glances --export <模块> | 把统计导出到 csv/influxdb/kafka 等 18 种目标 |
2.2 参数全景(--help 分组摘录)
glances --help 全文 172 行,按功能分组摘录关键参数(均为实测依据):
-1, --percpu start Glances in per CPU mode
-0, --disable-irix task's cpu usage will be divided by the total number of CPUs
-2, --disable-left-sidebar
disable network, disk I/O, FS and sensors modules
-3, --disable-quicklook
disable quick look module
-4, --full-quicklook disable all but quick look and load
-5, --disable-top disable top menu (QL, CPU, MEM, SWAP and LOAD)
--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)
-b, --byte display network rate in byte per second
--fs-free-space display FS free space instead of used
--sparkline display sparklines instead of bar in the curses interface
-f PROCESS_FILTER, --process-filter PROCESS_FILTER
set the process filter pattern (regular expression)
--sort-processes {cpu_percent,memory_percent,username,cpu_times,io_counters,name}
Sort processes by: cpu_percent, memory_percent, username,
cpu_times, io_counters, name
--enable-process-extended
enable extended stats on top process
-t TIME, --time TIME set minumum refresh rate in seconds [default: 2 sec]
--stdout STDOUT display stats to stdout, one stat per line (comma
separated list of plugins/plugins.attribute)
--stdout-csv STDOUT_CSV
display stats to stdout, csv format (comma separated
list of plugins/plugins.attribute)
--issue test all plugins and exit (please copy/paste the
output if you open an issue)
--api-doc display fields descriptions
三、--modules-list:插件与导出目标清单
$ glances --modules-list
Plugins list: alert, amps, cloud, connections, core, cpu, diskio, docker, folders, fs, gpu, help, ip, irq, load, mem, memswap, network, now, percpu, ports, processcount, processlist, psutilversion, quicklook, raid, sensors, smart, system, uptime, wifi
Exporters list: cassandra, couchdb, csv, elasticsearch, graph, graphite, influxdb, influxdb2, json, kafka, mqtt, opentsdb, prometheus, rabbitmq, restful, riemann, statsd, zeromq
31 个插件 + 18 个导出目标。--stdout/--stdout-csv/--disable-plugin 的取值都以这份清单为准(如 now、cpu、mem 是插件名)。
四、standalone 默认界面逐区解读
$ glances
实测抓屏(120×38,已省略中段重复行):
CPU 16.9% idle: 90.7% ctx_sw 37K MEM 58.0% SWAP 99.8% LOAD 12-core
CPU [ 16.9%] user 5.3% irq 0.0% inter 26K total 31.3G total 2.00G 1 min: 1.59
MEM [ 58.0%] system 2.5% nice 0.0% sw_int 5K used 18.2G used 2.00G 5 min: 1.47
SWAP [ 99.8%] iowait 0.1% steal 0.0% free 13.1G free 4.05M 15 min: 1.39
NETWORK Rx/s Tx/s TASKS 29 (30 thr), 1 run, 11 slp, 17 oth sorted automatically by memory consumption
eth0 0b 288b
lo 392b 392b CPU% MEM% VIRT RES PID USER TIME+ THR NI S R/s W/s
>0.0 0.1 339M 42.2M 3381 root 0:03 1 0 S ? ? python3 /usr/bin/gl
DefaultGateway 2ms 0.0 0.1 334M 37.4M 4380 root 0:01 2 0 R ? ? python3 /usr/bin/gl
0.0 0.0 6.89M 4.20M 2250 root 0:00 1 0 S ? ? su demo -c sleep 36
DISK I/O R/s W/s 0.0 0.0 4.26M 3.19M 2231 root 0:00 1 0 S ? ? bash -c sleep 3600;
sda 0 30.4M 0.0 0.0 4.26M 3.06M 2256 demo 0:00 1 0 S ? ? bash -c sleep 3600
sda2 0 0 0.0 0.0 2.73M 1.62M 2237 root 0:00 1 0 S ? ? sleep 3600
sda3 0 30.4M 0.0 0.0 2.73M 1.61M 2238 root 0:00 1 0 S ? ? sleep 3600
0.0 0.0 0 0 1970 root 0:00 1 0 Z ? ? [pkill]
FILE SYS Used Total 0.0 0.0 0 0 2216 root 0:00 1 0 Z ? ? [pkill]
_c/hostname 653G 786G …(中段僵尸/演示进程行省略)…
/etc/hosts 653G 786G
_esolv.conf 653G 786G
High swap (paging) usage
2026-10-17 03:13:10 UTC 2026-10-17 03:13:08 (ongoing) - MEMSWAP (99.8): glances, glances, su
逐区解读:
- 顶部摘要行:CPU/内存/交换百分比 +
ctx_sw(上下文切换)/inter(中断)/sw_int(软中断)计数 + LOAD 12-core 三档负载。 - 左上仪表:CPU/MEM/SWAP 三条百分比条;条色随阈值变绿/黄/红(单色抓屏不可见)。
- CPU 细分列:user/system/iowait/nice/irq/steal 六项百分比。
- MEM/SWAP 细分:total/used/free 三行。
- NETWORK 区:网卡 Rx/s Tx/s(默认 bit 计量,
0b/288b),DefaultGateway 2ms为 ping 网关延时。 - DISK I/O 区:
sda 0 30.4M——R/s、W/s 两列。 - FILE SYS 区:挂载点 Used/Total(本环境 653G/786G)。
- 右侧进程表:列头
CPU% MEM% VIRT RES PID USER TIME+ THR NI S R/s W/s;TASKS 行注明sorted automatically by memory consumption(默认按内存排序)。 - 底部告警行:
High swap (paging) usage … (ongoing) - MEMSWAP (99.8): glances, glances, su——alert 插件的实时告警,列出占用 swap 的进程名;左下角时间戳。
五、TUI 参数变体实测
5.1 -1 / --percpu:逐核展开
$ glances -1
左栏 CPU 单条变为 CPU0-CPU11 逐核条,右上 CPU 细分变为整行百分比表,MEM 细分多出 active/inactive/buffers/cached 四行:
user system idle iowait steal MEM 57.9% active 11.4G SWAP 99.8% LOAD 12-cor
CPU0 [ 17.8%] 1.5% 1.5% 82.2% 0.0% 0.0% total 31.3G inactive 15.2G total 2.00G 1 min: 1.4
CPU1 [ 7.7%] 3.4% 1.7% 92.3% 0.0% 0.0% used 18.1G buffers 1.10G used 2.00G 5 min: 1.4
CPU2 [ 11.2%] 7.8% 2.6% 88.8% 0.9% 0.0% free 13.2G cached 12.6G free 4.06M 15 min: 1.3
CPU3 [ 3.4%] 0.9% 1.7% 96.6% 0.0% 0.0%
CPU4 [ 23.5%] 20.9% 2.6% 76.5% 0.0% 0.0%
CPU5 [ 13.9%] 7.0% 5.2% 86.1% 0.0% 0.0%
CPU6 [ 70.9%] 69.2% 1.7% 29.1% 0.0% 0.0%
…(CPU7-CPU11 同构省略)…
5.2 -2 / --disable-left-sidebar:隐藏左栏
$ glances -2
左栏 NETWORK/DISK I/O/FILE SYS 三块整体消失,进程区获得全部宽度:
TASKS 30 (33 thr), 1 run, 12 slp, 17 oth sorted automatically by memory consumption
CPU% MEM% VIRT RES PID USER TIME+ THR NI S R/s W/s Command ('k' to kill)
注意进程表命令列随之变宽,列头尾部出现 Command ('k' to kill)。
5.3 -b / --byte:网络速率改字节
$ glances -b
NETWORK 区从 bit 计量(0b/288b/2Kb)变为 Byte 计量:
NETWORK Rx/s Tx/s
eth0 211 90
lo 0 0
默认单位是 bit(b 后缀),-b 切成 Byte——排查带宽账单口径差异时常用。
5.4 --fs-free-space:文件系统显示剩余量
$ glances --fs-free-space
FILE SYS 区列头 Used → Free,数值同步换算:
# 默认 # --fs-free-space
FILE SYS Used Total FILE SYS Free Total
_c/hostname 653G 786G _c/hostname 98.1G 786G
5.5 -f / --process-filter:进程过滤(正则)
$ glances -f sleep
进程表只剩命令匹配 sleep 的行,TASKS 行上方出现过滤器状态行:
NETWORK Rx/s Tx/s Processes filter: sleep ('ENTER' to edit, 'E' to reset)
…(进程表仅剩 sleep 3600 各行)…
-f 接正则表达式;运行中 ENTER 编辑、E 重置。
5.6 --sort-processes:进程排序
$ glances --sort-processes memory_percent
TASKS 行的排序说明由 sorted automatically by memory consumption 变为 sorted by memory consumption(去掉 automatically,表示用户显式指定)。可选值以 --help 为准:cpu_percent, memory_percent, username, cpu_times, io_counters, name。
5.7 --disable-plugin:关闭指定插件
$ glances --disable-plugin network,ports
左栏第一块由 NETWORK 变为 DISK I/O(network 区块整体消失):
DISK I/O R/s W/s
sda 0 30.5M
sda1 0 0
插件名取自第三章清单,逗号分隔可多个;未知插件名静默忽略、不报错(见 9.3 负例)。
5.8 其余 TUI 参数
-t 1:刷新间隔降为 1 秒(默认 2 秒),界面布局无变化,仅数值跳动更频。--sparkline:把 CPU/MEM/SWAP 条形换为迷你 sparkline,彩色终端可见,单色文本抓屏与默认无差异。--enable-process-extended:为选中进程追加扩展统计(上下文切换、IO 延时等,回车详情页可见),进程表头无变化。-0/--disable-irix:CPU 口径参数——默认 Irix 模式下进程 CPU% 单进程可到 100%(单核打满),-0后按"占总核数比例"计(单核打满显示 100/12≈8.3%)。界面布局无差异,数值口径不同。--theme-white:白底终端配色优化,文本抓屏无差异。-3/-4/-5:quick look 相关布局裁剪,均为界面区块开关,机制同-2。
六、非交互输出:--stdout 与 --stdout-csv
--stdout 接受 插件[.属性] 逗号清单,连续输出(每轮刷新一行),自动化采集时需外层 timeout 或管道限量:
$ glances --stdout now,cpu.user,mem.used,load
now: 2026-10-17 03:06:00 UTC
cpu.user: 13.9
mem.used: 17407000576
load: {'min1': 1.28515625, 'min5': 1.2822265625, 'min15': 1.30029296875, 'cpucore': 12}
now: 2026-10-17 03:06:02 UTC
cpu.user: 4.6
mem.used: 17441722368
load: {'min1': 1.28515625, 'min5': 1.2822265625, 'min15': 1.30029296875, 'cpucore': 12}
--stdout-csv 首行输出表头、每轮一行:
$ glances --stdout-csv now,cpu.total,mem.total,mem.used
now,cpu.total,mem.total,mem.used
2026-10-17 03:06:07 UTC,17.0,33607307264,17557643264
2026-10-17 03:06:09 UTC,9.8,33607307264,17529417728
七、诊断三件套:--issue / --api-doc / --modules-list
7.1 --issue:全插件自检(一次性退出)
$ glances --issue
===============================================================================
Glances 3.2.4.2 (/usr/lib/python3/dist-packages/glances/__init__.py)
Python 3.10.12 (/usr/bin/python3)
PsUtil 5.9.0 (/usr/lib/python3/dist-packages/psutil/__init__.py)
===============================================================================
alert [OK] 0.00001s [[1792206383.0, -1, 'CRITICAL', 'MEMSW
amps [OK] 0.00009s key=name [{'key': 'name', 'name': 'Dro
cloud [OK] 0.00002s {}
connections [N/A]
core [OK] 0.00039s {'phys': 12, 'log': 12}
cpu [OK] 0.00026s {'total': 21.1, 'user': 11.3, 'nice':
…(全部 31 插件逐行,略)…
wifi [N/A]
每个插件一行:状态 [OK]/[N/A](本环境 connections/ip/irq/raid/smart/wifi 为 N/A)+ 耗时 + 采样值预览。报 issue 时官方要求附上这份输出。
7.2 --api-doc:字段文档
--api-doc(不带值)打印内置 RESTful API 的 RST 文档头部:
API (Restfull/JSON) documentation
=================================
The Glances Restfull/API server could be ran using the following command line:
…(说明 api/3 与 api/2 版本路径差异,略)…
--api-doc cpu 这类带值写法不被接受——argparse 直接打 usage 报错(见 9.3)。
7.3 --modules-list
见第三章(插件 + 导出目标清单)。
八、客户机/服务器与 Web 模式实测
8.1 -w:Web 模式 + RESTful API
$ glances -w
Glances web server started on http://0.0.0.0:61208/
后台启动后用 curl 验证 RESTful API(实测回显):
$ curl -s http://127.0.0.1:61208/api/3/cpu
{"total": 9.2, "user": 5.0, "nice": 0.0, "system": 3.0, "idle": 87.5, "iowait": 3.4, "irq": 0.0, "softirq": 1.2, "steal": 0.0, "guest": 0.0, "guest_nice": 0.0, "time_since_update": 3.669874429702759, "cpucore": 12, "ctx_switches": 156475, "interrupts": 110131, "soft_interrupts": 20061, "syscalls": 0}
Web UI 在同端口浏览器可开,API 前缀 /api/3/(Glances 2.x 为 /api/2/)。
8.2 -s / -c:server / client 模式
# 服务器侧
$ glances -s -p 61209
# 确认监听(ss 回显)
LISTEN 0 5 0.0.0.0:61209 0.0.0.0:* users:(("glances",pid=4063,fd=4))
# 客户端侧(伪终端内实测,界面与本地 standalone 同构,数据来自 61209)
$ glances -c 127.0.0.1 -p 61209
CPU 10.3% idle: 89.7% ctx_sw 34K MEM 57.8% SWAP 100.0% LOAD 12-core
CPU [ 10.3%] user 6.5% irq 0.0% inter 25K total 31.3G total 2.00G 1 min: 1.55
MEM [ 57.8%] system 2.3% nice 0.0% sw_int 5K used 18.1G used 2.00G 5 min: 1.42
SWAP [100.0%] iowait 0.1% steal 0.0% free 13.2G free 72K 15 min: 1.37
NETWORK Rx/s Tx/s TASKS 29 (29 thr), 1 run, 12 slp, 16 oth sorted automatically by memory consumption
eth0 1Kb 920b
client 界面与 standalone 完全同构,区别只在数据源是远端 server。-p 在 server 侧指监听端口(client/server 模式默认 61209,Web 模式默认 61208);-B 绑定地址、--username/--password 用于鉴权(本环境内网免密直连)。
九、导出与报错边界
9.1 --export:命令可跑,落盘看退出方式
$ glances --export csv --export-csv-file /tmp/gl_test.csv --export-csv-overwrite -t 2
实测行为(3.2.4.2):命令被接受、界面正常、无任何报错,csv 文件被创建;但进程被信号终止(timeout 的 SIGTERM/SIGINT、q 退出)时文件保持 0 字节——导出缓冲未落盘。--export json --export-json-file 同样表现。自动化场景请用第六章 --stdout-csv 替代;需要 influxdb/prometheus 等长驻导出时以服务化部署让 glances 自然运行、由 exporter 周期写出。
9.2 curses 管道报错
glances 是 curses 程序,stdin/终端不可用时启动即崩(实测回显):
setupterm(term=_os.environ.get("TERM", "unknown"),
_curses.error: setupterm: could not find terminal
TERM 缺失或值非法时同样报 _curses.error;配合 -c 的 client 模式在无终端下崩于 curses.cbreak()。解法:给足 TERM=xterm 并在伪终端中运行;纯管道场景一律走 --stdout/--stdout-csv。
9.3 静默与 usage 负例
$ glances --stdout nosuchplugin.field
(无任何输出、无报错,进程照常循环刷新——未知插件静默跳过)
$ glances --disable-plugin nosuchplugin --stdout now
now: 2026-10-17 03:06:19 UTC
now: 2026-10-17 03:06:21 UTC
(未知插件名同样静默,正常输出)
$ glances --api-doc cpu
usage: glances [-h] [-V] [-d] [-C CONF_FILE] [--modules-list] …
(--api-doc 为无值开关,'cpu' 被当作多余参数触发 argparse usage)
十、速查表
| 场景 | 命令 |
|---|---|
| 版本 / 日志路径 | glances --version |
| 插件与导出清单 | glances --modules-list |
| 全插件自检 | glances --issue |
| 逐核视图 | glances -1 |
| 隐藏左栏(纯进程表) | glances -2 |
| 网速 Byte 计量 | glances -b |
| 文件系统显示剩余 | glances --fs-free-space |
| 进程正则过滤 | glances -f sleep |
| 按内存排序 | glances --sort-processes memory_percent |
| 刷新 1 秒 | glances -t 1 |
| 单行/CSV 连续输出 | glances --stdout now,cpu.user,mem.used,load / glances --stdout-csv … |
| Web 模式 + API | glances -w → curl http://127.0.0.1:61208/api/3/cpu |
| 服务器 / 客户端 | glances -s -p 61209 / glances -c <ip> -p 61209 |
| 导出(注意落盘) | glances --export csv --export-csv-file …(信号终止不落盘,见 9.1) |
| 未知插件 | 静默忽略;--api-doc 带值报 usage |
一句话收束:glances 的参数轴是"模式(standalone/client/server/web/export)× 视图(-1/-2/-b/--fs-free-space…)× 输出(TUI/--stdout/--export)";交互排查用默认 TUI,自动化采集用 --stdout-csv,多机汇总用 -s/-c 或 -w 的 RESTful API。