Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux glances Command

Linux glances Command

Linux Command Reference Linux Command Reference


glances is a cross-platform command-line system monitoring tool that presents various performance metrics of a Linux system in an intuitive way. Compared with traditional commands such as top or htop, glances offers richer monitoring dimensions and a friendlier user interface.

Main Features:


Installing glances

Ubuntu/Debian systems

Example

sudo

apt update

sudo

apt

install

glances

CentOS/RHEL systems

Example

sudo

yum install

epel-release

sudo

yum install

glances

Install with pip (all Linux distributions)

pip install glances


Basic Usage

The simplest way to start glances is to enter the command directly:

glances

After starting, you will see a dynamic monitoring interface like 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 shortcuts and interactive commands

In the glances interface, you can use the following shortcuts:

Keyboard shortcut Description
q or ESC 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 filesystem information
s Show/hide sensor information
w Clear alert logs
h Display help information

Important command-line options

glances provides a rich set of command-line options to customize monitoring behavior:

Display control options

Example

glances

-t

2

         

Set the refresh interval to 2 seconds (default 1 second)

glances

--disable-plugins

fs,

ip

 

Disable the filesystem and IP plugins

glances

--percpu

     

Show the usage of each CPU core

Output format options

Example

glances

--csv

       

CSV format output

glances

--json

       

JSON format output

glances

--export

influxdb  

Output to an InfluxDB database

Remote monitoring options

Example

glances

-s

           

Start glances in server mode

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 a specific process

glances --process-name nginx  # 只监控nginx相关进程

Example 2: Generate a 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

glances

-w

&

amp;                  

Start the web service

firefox http:

//

localhost:

61208

View in a browser


glances configuration file

The glances configuration file is usually located at ~/.config/glances/glances.conf; you can edit this file to permanently change the default settings.

Common configuration items:

Example

[global]

refresh

=

2 # Refresh interval (seconds)

theme

=

white # Interface theme (white/dark)

disable_plugin

=

fs # Disabled plugins


glances compared with similar tools

Tool Feature Applicable scenarios
glances Full-featured, friendly interface, supports extensions Daily system monitoring, remote monitoring
top Built into Linux, 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

  1. Long-term Monitoring: For systems that require long-term monitoring, consider using glances --export to export data to a file or database
  2. Remote management: On the server, use glances -s to start the server side, making it easy to connect and view from a local machine
  3. Alert settings: Combine with --alert to set reasonable thresholds and detect system anomalies in a timely manner
  4. Plugin usage: Enable/disable plugins as needed to reduce unnecessary resource consumption
  5. Color recognition: Pay attention to the color cues in the interface (green for normal, yellow for warning, red for danger)

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 glances -son the remote server, then use glances -c @远程IP to connect locally.

Q3: Does glances consume a lot of system resources? A: glances is designed as a lightweight tool, usually consuming very few system resources (<1% CPU).

Q4: How do I customize the displayed monitoring items? A: You can disable unwanted plugins via command-line options, or edit the configuration file to permanently change the display settings.

Q5: Does glances support Windows? A: Yes, glances is a cross-platform tool and can also be installed and used on Windows via pip.


Through 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 troubleshooting performance issues, glances provides a comprehensive and intuitive view of system status. It is recommended to practice more in real work and gradually explore more advanced features of glances.


Linux Command Reference Linux Command Reference