How to use the command glances (with examples)
Glances is a cross-platform system monitoring tool that provides real-time information about CPU, memory, disk usage, network traffic, and other system statistics. It can be run in the terminal or as a web server to display the results in a browser. Additionally, Glances supports server mode, allowing connections from other Glances clients.
Use case 1: Run Glances in the terminal
Code:
glances
Motivation: Running Glances in the terminal provides a quick and convenient way to monitor system resources without the need for a graphical user interface. This is especially useful for remote server management or when working on a command-line only system.
Explanation: Running the glances
command without any arguments starts Glances in the terminal mode. This will display real-time system statistics, including CPU usage, memory usage, network activity, and more.
Example output:
-----------------------------------
Glances >= v3.0.0 with psutil >= v5.7.0
-----------------------------------
CPU 6% 3% 9% 9%
Mem 15% 1.7/10GiB
Swap 0B 0B/6.0GiB
Use case 2: Run Glances in web server mode
Code:
glances -w
Motivation: Running Glances in web server mode allows you to access the system monitoring information through a web browser. This can be useful when you want to remotely monitor system resources from another device.
Explanation: Adding the -w
flag starts Glances in web server mode. This will launch a web server that serves the system monitoring information on a specified port (default is 61208). You can then access the information by opening a web browser and navigating to <your_ip_address>:61208
.
Example output: N/A (The output will be displayed in the web browser)
Use case 3: Run Glances in server mode
Code:
glances -s
Motivation: Running Glances in server mode allows multiple Glances clients to connect and monitor the same system simultaneously. This can be useful in situations where you want to monitor a server from multiple devices or distribute the system monitoring load across different clients.
Explanation: Including the -s
flag starts Glances in server mode, enabling connections from other Glances clients. This will open up a port (default is 61209) and listen for incoming connections.
Example output: N/A (Glances will continue running in server mode without displaying any output)
Use case 4: Connect to a Glances server
Code:
glances -c hostname
Motivation: Connecting to a Glances server allows you to monitor the system resources of a remote machine. This can be useful when you want to monitor and analyze the performance of a server located elsewhere.
Explanation: Using the -c
flag followed by the hostname or IP address of the Glances server allows you to connect to that server and receive real-time system monitoring information. This command establishes a client-server connection and retrieves the data from the server.
Example output:
-----------------------------------
glances@remote-host
-----------------------------------
CPU 12% 10% 8% 11%
Mem 36% 5.0/16GiB
Swap 0B 0B/4.0GiB
Use case 5: Require a password in (web) server mode
Code:
glances -s --password
Motivation: Requiring a password in web server mode adds an additional layer of security to the Glances web server. This can be useful when exposing the monitoring information over the internet or when shared access to the server is a concern.
Explanation: Adding the --password
flag to the -s
command enables the password requirement for accessing the Glances web server. Upon accessing the web interface, users will be prompted to enter a password to view the system monitoring information.
Example output: N/A (The output will be displayed in the web browser)
Conclusion:
Glances is a powerful system monitoring tool that provides real-time information about various system resources. By using different command-line arguments, you can customize its behavior and access the monitoring information in various ways. Whether you choose to run it in the terminal for quick access, as a web server for remote monitoring, or in server mode to allow multiple clients, Glances offers flexibility and ease of use for monitoring your system’s performance.