How to use the command 'glances' (with examples)
Glances is an advanced, cross-platform system monitoring tool that offers a comprehensive overview of system statistics and resource utilization within a terminal interface. Designed to be adaptable and extend beyond just displaying real-time data, Glances can function in various modes to fit different needs, such as running locally, acting as a server, or being accessed through a web interface.
Use case 1: Running Glances in the terminal
Code:
glances
Motivation: Running Glances in the terminal provides a quick and detailed snapshot of the system’s current resource usage, like CPU, memory, disk, network, and more. This is essential for system administrators or users who need to monitor system performance, troubleshoot potential issues, or optimize the resource allocation of running processes.
Explanation: The glances
command, when executed without additional arguments, opens the Glances tool in the terminal, offering real-time monitoring of system parameters. This is the most straightforward use of the command, making it accessible for users who simply want to keep track of their system’s health without any network complexity.
Example Output:
Glances v3.1.7.1 - Darwin - 3.9.0 (Shell 10.14.6 - py3.8)
CPU: 21% [ & ] 2 cores
MEM: 3.2/8.0GB (40%)
SWAP: 0/1.0GB (0%)
...
Use case 2: Running Glances in web server mode to show results in a browser
Code:
glances -w
Motivation: Running Glances in web server mode allows users to visualize system statistics remotely via a web browser. This is particularly useful for users who need to monitor multiple systems or simply prefer a graphical representation of data over terminal-based views.
Explanation: The -w
flag enables the web server mode, launching a simple HTTP server that serves the Glances interface. Users can then access this interface from any browser by navigating to the host machine’s IP address and the designated port (default is 61208).
Example Output:
When accessed via a browser, users would see a comprehensive dashboard of system statistics similar to what is normally seen in the terminal, but presented in a more structured web format.
Open your web browser to http://localhost:61208
Use case 3: Running Glances in server mode to allow connections from other Glances clients
Code:
glances -s
Motivation: Server mode is key when there is a need to monitor or manage multiple machines from a central location. This setup allows the machine running the -s
command to serve data to remote clients, making it integral for centralized network monitoring systems.
Explanation: The -s
argument starts Glances in server mode, allowing the machine to accept connections from other Glances clients. In a distributed system environment, this makes system resource data available across different machines for remote monitoring and management.
Example Output:
Running in this mode, Glances will listen for client connections. The console will reflect that it’s operating in server mode, ready for connections.
Starting Glances server mode on 0.0.0.0:61208
Use case 4: Connecting to a Glances server
Code:
glances -c hostname
Motivation: By connecting to a Glances server, a user can remotely monitor another system that has Glances running in server mode. This use case is particularly beneficial for administrators needing to manage and view multiple systems from a single point of control.
Explanation: The -c
flag followed by the hostname
or IP address of the server to connect specifies that the Glances client should establish a connection to a remote server running Glances in server mode. This client-mode operation gathers and displays data from the remote host, providing insights into its resource status.
Example Output:
When connected, the Glances client will display the system stats from the server it is connected to, showing similar information as local monitoring would.
Connected to the server at hostname
Use case 5: Requiring a password in (web) server mode
Code:
glances -s --password
Motivation: Implementing a password for web server mode adds a layer of security, ensuring that only authorized users can access the system’s resource data via the web interface. This is crucial for protecting sensitive system information from unauthorized access.
Explanation: The --password
argument paired with the -s
flag requires users to enter a password to access the Glances interface in web server mode. When launching in this configuration, the system prompts the user to create a password initially and then requires its entry upon access.
Example Output:
Users will be asked to input and confirm a new password when starting Glances in this mode. Accessing the web server then requires entering this password.
Starting Glances server mode on 0.0.0.0:61208
Please set your Glances password:
Conclusion:
Glances is a versatile and powerful system monitoring tool that caters to various requirements, from local monitoring on a single machine to complex networked environments where centralized monitoring of multiple systems is necessary. By offering different modes of operation and the ability to secure connections, Glances provides a comprehensive solution for managing and monitoring system resources efficiently.