Linux glances Command
Complete List of Linux Commands
glances is a cross-platform command-line system monitoring tool that intuitively displays various performance metrics of Linux systems. Compared with traditional top or htop commands, glances provides richer monitoring dimensions and a more user-friendly interface.
Key Features:
- Real-time monitoring of core metrics such as CPU, memory, disk, and network
- Supports color display and dynamic refresh
- Remote access via Web interface
- Low resource usage, suitable for long-term operation
- Supports plugin extension features
Install glances
Ubuntu/Debian Systems
Example
sudo apt install glances
CentOS/RHEL Systems
Example
sudo yum install glances
Install using pip (all Linux distributions)
pip install glances
Basic Usage
The simplest way to start glances is to directly enter the command:
glances
After startup, you will see a dynamic monitoring interface similar to this:
CPU[|||||||||||||||||||||||||90.5%] RAM[|||||||||||||||||65.2%] SWAP[|3.1%] Load average: 1.78 1.23 0.89 NETWORK Rx/s Tx/s DISK I/O R/s W/s eth0 1.2Mb 560Kb sda 450Kb 1.2Mb wlan0 320Kb 120Kb sdb 0Kb 0Kb Processes: 156 total, 3 running, 153 sleeping
Common Shortcut Keys and Interactive Commands
In the glances running interface, you can use the following shortcut keys:
| Shortcut Key | Function Description |
|---|---|
qorESC |
Exit glances |
c |
Sort processes by CPU usage |
m |
Sort processes by memory usage |
i |
Show/hide I/O rates |
d |
Show/hide disk I/O |
n |
Show/hide network information |
f |
Show/hide file system information |
s |
Show/hide sensor information |
w |
Delete warning logs |
h |
Show help information |
Important Command Line Options
glances provides a rich set of command line options to customize monitoring behavior:
Display Control Options
Example
glances --disable-plugins fs,ip # Disable file system and IP plugins
glances --percpu # Display the usage of each CPU core
Output Format Options
Example
glances --json # JSON format output
glances --export influxdb # Output to InfluxDB database
Remote Monitoring Options
Example
glances -c @192.168.1.100 # Connect to a remote glances server
glances -w # Enable web server mode (default port 61208)
Practical Application Examples
Example 1: Monitor Specific Processes
glances --process-name nginx # 只监控nginx相关进程
Example 2: Generate System Snapshot
glances --export csv --export-csv-file /tmp/system_stats.csv
Example 3: Set Alert Thresholds
glances --alert cpu:80,mem:90 # CPU超过80%或内存超过90%时告警
Example 4: Remote Web Monitoring
Example
firefox http://localhost:61208 # View in browser
glances Configuration File
The glances configuration file is usually located at~/.config/glances/glances.conf, and you can permanently modify the default settings by editing this file.
Common Configuration Items:
Example
refresh=2 # Refresh interval(second)
theme=white # Interface theme(white/dark)
disable_plugin=fs # Disabled plugins
Comparison Between glances and Similar Tools
| Tool | Features | Applicable Scenarios |
|---|---|---|
| glances | Comprehensive features, user-friendly interface, supports extensions | Daily system monitoring, remote monitoring |
| top | Linux built-in, basic functionality | Quickly view process information |
| htop | Enhanced version of top, good interactivity | Process management and monitoring |
| nmon | Professional performance monitoring, supports historical data | Performance testing and analysis |
| vmstat | Focused on system resource statistics | System bottleneck analysis |
Best Practice Recommendations
- Long-term Monitoring: For systems that require long-term monitoring, consider using
glances --exportto export data to files or a database - Remote Management: Use on the server
glances -sto start the server mode, making it convenient to connect and view from a local machine - Alert Settings: Combine
--alertparameter to set reasonable thresholds, promptly detecting system anomalies - Plugin Utilization: Enable/disable plugins based on requirements to reduce unnecessary resource consumption
- Color Recognition: Pay attention to the color indicators in the interface (green: normal, yellow: warning, red: dangerous)
Frequently Asked Questions
Q1: What is the difference between glances and top?A: glances provides a more comprehensive system monitoring view (including network, disk, etc.), while top mainly focuses on process-level CPU and memory usage.
Q2: How do I monitor a remote server?A: First run on the remote serverglances -s, then use on the local machineglances -c @远程IPto connect.
Q3: Does glances consume a lot of system resources?A: glances is designed as a lightweight tool and usually consumes very little system resources (<1% CPU).
Q4: How do I customize the displayed monitoring items?A: You can disable unnecessary plugins via command line options, or edit the configuration file to permanently modify the display settings.
Q5: Does glances support Windows systems?A: Yes, glances is a cross-platform tool and can also be installed and used via pip on Windows.
Through the study of this article, you should have mastered the basic usage and advanced techniques of glances, a powerful system monitoring tool. Whether for daily system maintenance or performance troubleshooting, glances provides a comprehensive and intuitive view of system status. It is recommended to practice more in actual work and gradually explore more advanced features of glances.
Other Extensions