تخطَّ إلى المحتوى

Glances Cheatsheet

Glances Cheatsheet

Installation

PlatformCommand
Ubuntu/Debiansudo apt update && sudo apt install glances
RHEL/CentOS/Fedorasudo dnf install glances or sudo yum install epel-release && sudo yum install glances
Arch Linuxsudo pacman -S glances
macOS (Homebrew)brew install glances
Windows (pip)pip install glances
Windows (Chocolatey)choco install glances
Dockerdocker pull nicolargo/glances
Python pip (all platforms)pip3 install glances
With all featurespip3 install 'glances[all]'
From sourcegit clone https://github.com/nicolargo/glances.git && cd glances && python setup.py install

Basic Commands

CommandDescription
glancesLaunch glances with default settings
glances -t 5Set refresh interval to 5 seconds
glances -VDisplay version information
glances --helpShow help and available options
glances --percpuShow per-CPU statistics by default
glances --process-short-nameShow only active processes with short names
glances --process-filter="python"Filter processes by name (e.g., “python”)
glances --process-filter="user:nginx"Show processes for specific user
glances --theme-whiteUse white theme (black background)
glances --disable-bgDisable background colors
glances --fahrenheitDisplay temperature in Fahrenheit instead of Celsius
glances --byteDisplay network rate in bytes per second
glances --process-max 50Limit displayed processes to 50
glances --no-kernel-threadsHide kernel threads from process list
glances --disable-boldDisable bold text in interface

Interactive Keyboard Shortcuts

KeyDescription
q or ESCQuit glances
hDisplay help screen
cSort processes by CPU usage
mSort processes by memory usage
pSort processes by process name
iSort processes by I/O rate
tSort processes by process time
uSort processes by user
kKill selected process (requires confirmation)
rRenice (change priority) selected process
1Toggle between global CPU and per-CPU statistics
dShow/hide disk I/O stats
fShow/hide filesystem stats
nShow/hide network stats
sShow/hide sensors
2Show/hide left sidebar
zShow/hide processes list
bToggle network rate between bits/s and bytes/s
wDelete warning logs
xDelete warning and critical logs
DShow/hide Docker containers
TToggle process tree view
UP/DOWNNavigate through process list
SPACETag/untag process for bulk operations

Advanced Usage

CommandDescription
glances -sStart in server mode (default port 61209)
glances -s -p 8080Start server on custom port 8080
glances -s --passwordStart server with password authentication
glances -s -B 192.168.1.100Bind server to specific IP address
glances -c 192.168.1.100Connect to remote glances server
glances -c 192.168.1.100 -p 8080Connect to server on custom port
glances -wStart web server mode (default port 61208)
glances -w --port 8080Start web server on custom port
glances -w --username admin --password secretWeb server with authentication
glances -w -B 0.0.0.0Make web server accessible from all interfaces
glances --dockerEnable Docker container monitoring
glances --export csv --export-csv-file /tmp/glances.csvExport metrics to CSV file
glances --export influxdbExport metrics to InfluxDB
glances --export prometheusExport metrics for Prometheus scraping
glances --export json --export-json-file /tmp/glances.jsonExport metrics to JSON file
glances --disable-plugin cpu,memDisable specific plugins
glances --snmp-community publicStart SNMP server mode
glances -c 192.168.1.100 --snmp-version 2c --snmp-community publicConnect via SNMP
glances --logfile /var/log/glances.logLog output to file
glances --debugEnable debug logging

Docker Usage

Run Glances in Docker Container

# Basic container with web interface
docker run -d --restart="always" \
  -p 61208-61209:61208-61209 \
  -e GLANCES_OPT="-w" \
  -v /var/run/docker.sock:/var/run/docker.sock:ro \
  --pid host \
  nicolargo/glances

# With custom configuration file
docker run -d \
  -v /path/to/glances.conf:/glances/conf/glances.conf \
  -p 61208-61209:61208-61209 \
  -e GLANCES_OPT="-w" \
  nicolargo/glances

# Server mode only
docker run -d \
  -p 61209:61209 \
  -e GLANCES_OPT="-s" \
  --pid host \
  nicolargo/glances

Configuration

Glances uses a configuration file located at:

  • Linux: ~/.config/glances/glances.conf or /etc/glances/glances.conf
  • macOS: ~/Library/Application Support/glances/glances.conf
  • Windows: %APPDATA%\glances\glances.conf

Basic Configuration Example

[global]
# Refresh rate in seconds
refresh=2
# Check for updates
check_update=false

[cpu]
# CPU thresholds (%)
careful=50
warning=70
critical=90

[mem]
# Memory thresholds (%)
careful=50
warning=70
critical=90

[memswap]
# Swap thresholds (%)
careful=50
warning=70
critical=90

[load]
# Load average thresholds (per CPU)
careful=0.7
warning=1.0
critical=5.0

[network]
# Hide network interfaces
hide=lo,docker.*
# Show cumulative values
cumulative=False

[diskio]
# Hide disk devices
hide=loop.*,/dev/loop.*

[fs]
# Hide filesystems
hide=/boot.*,/snap.*
# Careful threshold (%)
careful=50
warning=70
critical=90

[folders]
# Monitor specific folders
folder_1_path=/home
folder_1_careful=2500
folder_1_warning=3000
folder_1_critical=3500

[sensors]
# Temperature thresholds (Celsius)
temperature_core_careful=60
temperature_core_warning=70
temperature_core_critical=80

[processlist]
# CPU thresholds for processes (%)
cpu_careful=50
cpu_warning=70
cpu_critical=90
# Memory thresholds for processes (%)
mem_careful=50
mem_warning=70
mem_critical=90

[docker]
# Enable Docker monitoring
disable=False
# Maximum containers to display
max_name_size=20

Web Server Configuration

[outputs]
# Export to CSV
export_csv_file=/tmp/glances.csv
export_csv_overwrite=False

# Export to InfluxDB
export_influxdb=True
influxdb_host=localhost
influxdb_port=8086
influxdb_user=root
influxdb_password=root
influxdb_db=glances

# Export to Prometheus
export_prometheus=True
prometheus_port=9091
prometheus_prefix=glances

[serverlist]
# Remote servers to monitor
server_1_name=prod-server-1
server_1_alias=Production 1
server_1_host=192.168.1.100
server_1_port=61209
server_2_name=prod-server-2
server_2_alias=Production 2
server_2_host=192.168.1.101
server_2_port=61209

RESTful API Usage

API Endpoints

EndpointDescription
GET /api/3/statusGet server status
GET /api/3/configGet server configuration
GET /api/3/allGet all stats in JSON format
GET /api/3/cpuGet CPU statistics
GET /api/3/memGet memory statistics
GET /api/3/memswapGet swap memory statistics
GET /api/3/loadGet load average
GET /api/3/networkGet network statistics
GET /api/3/diskioGet disk I/O statistics
GET /api/3/fsGet filesystem statistics
GET /api/3/processlistGet process list
GET /api/3/sensorsGet sensors data
GET /api/3/dockerGet Docker containers stats
GET /api/3/processlist/pid/<pid>Get specific process info

API Examples

# Get CPU stats
curl http://localhost:61208/api/3/cpu

# Get memory stats
curl http://localhost:61208/api/3/mem

# Get all stats
curl http://localhost:61208/api/3/all

# Get specific process
curl http://localhost:61208/api/3/processlist/pid/1234

# Pretty print JSON output
curl http://localhost:61208/api/3/cpu | python -m json.tool

# Get stats with authentication
curl -u admin:secret http://localhost:61208/api/3/cpu

Common Use Cases

Use Case 1: Remote Server Monitoring

Monitor multiple servers from a central location:

# On remote servers (run as service)
glances -s -B 0.0.0.0 --password

# On monitoring station
glances -c server1.example.com --password yourpassword

# Or use web interface
glances -w -B 0.0.0.0 --username admin --password secret
# Access via browser: http://server:61208

Use Case 2: Export Metrics to InfluxDB and Grafana

Set up continuous monitoring with visualization:

# Start glances with InfluxDB export
glances --export influxdb \
  --influxdb-host localhost \
  --influxdb-port 8086 \
  --influxdb-user admin \
  --influxdb-password secret \
  --influxdb-db glances

# Or configure in glances.conf and run as daemon
glances --quiet --export influxdb

Configure Grafana to use InfluxDB as data source and create dashboards.

Use Case 3: Docker Container Monitoring

Monitor Docker containers alongside system metrics:

# Enable Docker monitoring
glances --docker

# Docker-only view (hide processes)
glances --docker --disable-process

# Export Docker stats to Prometheus
glances --docker --export prometheus --prometheus-port 9091

# Web interface with Docker stats
glances -w --docker

Use Case 4: Troubleshooting High CPU Usage

Identify and analyze resource-intensive processes:

# Start glances with focus on CPU
glances --percpu

# Interactive steps:
# 1. Press 'c' to sort by CPU usage
# 2. Press '1' to see per-CPU breakdown
# 3. Press 'T' to view process tree
# 4. Navigate to problematic process
# 5. Press 'k' to kill if needed

# Export data for analysis
glances --export csv --export-csv-file /tmp/cpu-analysis.csv -t 1

Use Case 5: Automated Monitoring Script

Create a monitoring script with alerts:

#!/bin/bash
# monitor.sh - Check system health via Glances API

# Start glances web server in background
glances -w --quiet &
GLANCES_PID=$!
sleep 5

# Check CPU usage
CPU_USAGE=$(curl -s http://localhost:61208/api/3/cpu | \
  python -c "import sys, json; print(json.load(sys.stdin)['total'])")

if (( $(echo "$CPU_USAGE > 80" | bc -l) )); then
    echo "ALERT: CPU usage is ${CPU_USAGE}%"
    # Send notification or alert
fi

# Check memory usage
MEM_USAGE=$(curl -s http://localhost:61208/api/3/mem | \
  python -c "import sys, json; print(json.load(sys.stdin)['percent'])")

if (( $(echo "$MEM_USAGE > 90" | bc -l) )); then
    echo "ALERT: Memory usage is ${MEM_USAGE}%"
fi

# Cleanup
kill $GLANCES_PID

Best Practices

  • Use configuration files instead of command-line options for permanent settings to maintain consistency across sessions and make configurations version-controllable

  • Set appropriate refresh intervals - Use 2-5 seconds for interactive monitoring, 10-30 seconds for background monitoring to balance responsiveness with system load

  • Filter unnecessary information - Hide irrelevant network interfaces, disk devices, and filesystems to reduce clutter and focus on important metrics

  • Implement authentication for remote monitoring and web interfaces to prevent unauthorized access to system information, especially in production environments

  • Export to time-series databases like InfluxDB or Prometheus for long-term trend analysis, capacity planning, and historical troubleshooting

  • Run as a systemd service on Linux servers for automatic startup and monitoring continuity across reboots

  • Monitor Docker containers when running containerized workloads to track resource usage per container and identify resource-hungry applications

  • Use color thresholds wisely - Configure careful/warning/critical thresholds based on your system’s normal operating ranges to avoid alert fatigue

  • Leverage the API for automation and integration with existing monitoring systems, alerting tools, or custom dashboards

  • Keep glances updated - Regularly update to get new features, performance improvements, and security patches

Troubleshooting

IssueSolution
glances: command not foundEnsure glances is installed and in PATH. Try pip3 install --user glances and add ~/.local/bin to PATH
High CPU usage by glances itselfIncrease refresh interval with -t 5 or higher. Disable unused plugins with --disable-plugin
Cannot connect to remote serverCheck firewall rules allow port 61209. Verify server is running with glances -s. Test connectivity with telnet server 61209
Web interface not accessibleEnsure glances started with -w flag. Check if port 61208 is available with `netstat -tulpn \
Docker containers not showingVerify Docker socket is accessible: ls -l /var/run/docker.sock. Run glances with appropriate permissions or add user to docker group
Permission denied errorsRun with sudo for full system access, or adjust permissions for specific resources. Some features require root privileges
Sensors not displayingInstall lm-sensors package and run sensors-detect. Install Python sensors library: pip3 install py3sensors
InfluxDB export not workingVerify InfluxDB is running and accessible. Check credentials and database name. Install InfluxDB client: pip3 install influxdb
Missing GPU informationInstall NVIDIA monitoring library: pip3 install nvidia-ml-py3. Ensure NVIDIA drivers are installed and working
Config file changes not appliedVerify config file location with glances --version. Check file syntax. Restart glances after configuration changes
Process list incompleteIncrease process limit with --process-max 0 for unlimited. Check if kernel threads are hidden with --no-kernel-threads
Unicode/display issues in terminalSet proper locale: export LANG=en_US.UTF-8. Use --disable-unicode flag if terminal doesn’t support Unicode

Optional Dependencies

Install these packages for enhanced functionality:

# Docker monitoring
pip3 install docker

# GPU monitoring (NVIDIA)
pip3 install nvidia-ml-py3

# Sensors support (Linux)
pip3 install py3sensors

# Web interface
pip3 install bottle

# InfluxDB export
pip3 install influxdb influxdb-client

# Prometheus export
pip3 install prometheus_client

# Elasticsearch export
pip3 install elasticsearch

# StatsD export
pip3 install statsd

# IP geolocation
pip3 install geoip2

# All optional features
pip3 install 'glances[all]'