Zum Inhalt
_ _ _

_

Glances Cheatsheet

• Installation

Platform Command
Ubuntu/Debian INLINE_CODE_10
RHEL/CentOS/Fedora INLINE_CODE_11 or INLINE_CODE_12
Arch Linux INLINE_CODE_13
macOS (Homebrew) INLINE_CODE_14
Windows (pip) INLINE_CODE_15
Windows (Chocolatey) INLINE_CODE_16
Docker INLINE_CODE_17
Python pip (all platforms) INLINE_CODE_18
With all features INLINE_CODE_19
From source INLINE_CODE_20

oder Grundlegende Befehle

Command Description
INLINE_CODE_21 Launch glances with default settings
INLINE_CODE_22 Set refresh interval to 5 seconds
INLINE_CODE_23 Display version information
INLINE_CODE_24 Show help and available options
INLINE_CODE_25 Show per-CPU statistics by default
INLINE_CODE_26 Show only active processes with short names
INLINE_CODE_27 Filter processes by name (e.g., "python")
INLINE_CODE_28 Show processes for specific user
INLINE_CODE_29 Use white theme (black background)
INLINE_CODE_30 Disable background colors
INLINE_CODE_31 Display temperature in Fahrenheit instead of Celsius
INLINE_CODE_32 Display network rate in bytes per second
INLINE_CODE_33 Limit displayed processes to 50
INLINE_CODE_34 Hide kernel threads from process list
INLINE_CODE_35 Disable bold text in interface
_
Interaktive Tastenkombinationen
Key Description
INLINE_CODE_36 or INLINE_CODE_37 Quit glances
INLINE_CODE_38 Display help screen
INLINE_CODE_39 Sort processes by CPU usage
INLINE_CODE_40 Sort processes by memory usage
INLINE_CODE_41 Sort processes by process name
INLINE_CODE_42 Sort processes by I/O rate
INLINE_CODE_43 Sort processes by process time
INLINE_CODE_44 Sort processes by user
INLINE_CODE_45 Kill selected process (requires confirmation)
INLINE_CODE_46 Renice (change priority) selected process
INLINE_CODE_47 Toggle between global CPU and per-CPU statistics
INLINE_CODE_48 Show/hide disk I/O stats
INLINE_CODE_49 Show/hide filesystem stats
INLINE_CODE_50 Show/hide network stats
INLINE_CODE_51 Show/hide sensors
INLINE_CODE_52 Show/hide left sidebar
INLINE_CODE_53 Show/hide processes list
INLINE_CODE_54 Toggle network rate between bits/s and bytes/s
INLINE_CODE_55 Delete warning logs
INLINE_CODE_56 Delete warning and critical logs
INLINE_CODE_57 Show/hide Docker containers
INLINE_CODE_58 Toggle process tree view
INLINE_CODE_59 Navigate through process list
INLINE_CODE_60 Tag/untag process for bulk operations
_
/ Fortgeschrittene Nutzung
Command Description
INLINE_CODE_61 Start in server mode (default port 61209)
INLINE_CODE_62 Start server on custom port 8080
INLINE_CODE_63 Start server with password authentication
INLINE_CODE_64 Bind server to specific IP address
INLINE_CODE_65 Connect to remote glances server
INLINE_CODE_66 Connect to server on custom port
INLINE_CODE_67 Start web server mode (default port 61208)
INLINE_CODE_68 Start web server on custom port
INLINE_CODE_69 Web server with authentication
INLINE_CODE_70 Make web server accessible from all interfaces
INLINE_CODE_71 Enable Docker container monitoring
INLINE_CODE_72 Export metrics to CSV file
INLINE_CODE_73 Export metrics to InfluxDB
INLINE_CODE_74 Export metrics for Prometheus scraping
INLINE_CODE_75 Export metrics to JSON file
INLINE_CODE_76 Disable specific plugins
INLINE_CODE_77 Start SNMP server mode
INLINE_CODE_78 Connect via SNMP
INLINE_CODE_79 Log output to file
INLINE_CODE_80 Enable debug logging
_
/ Docker Nutzung

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

Konfiguration

Glances verwendet eine Konfigurationsdatei unter: - Linux: ~/.config/glances/glances.conf oder /etc/glances/glances.conf_ - macOS: ~/Library/Application Support/glances/glances.conf - Windows: %APPDATA%\glances\glances.conf_

Basic Configuration Beispiel

[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 Konfiguration

[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 Nutzung

API Endpoints

Endpoint Description
INLINE_CODE_85 Get server status
INLINE_CODE_86 Get server configuration
INLINE_CODE_87 Get all stats in JSON format
INLINE_CODE_88 Get CPU statistics
INLINE_CODE_89 Get memory statistics
INLINE_CODE_90 Get swap memory statistics
INLINE_CODE_91 Get load average
INLINE_CODE_92 Get network statistics
INLINE_CODE_93 Get disk I/O statistics
INLINE_CODE_94 Get filesystem statistics
INLINE_CODE_95 Get process list
INLINE_CODE_96 Get sensors data
INLINE_CODE_97 Get Docker containers stats
INLINE_CODE_98 Get specific process info
_
### API Beispiele
# 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

Häufige Anwendungsfälle

Use Case 1: Remote Server Monitoring

Überwachen Sie mehrere Server von einem zentralen Standort:

# 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 von Metriken nach InfluxDB und Grafana

Kontinuierliche Überwachung mit Visualisierung:

# 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

Konfigurieren Sie Grafana, um InfluxDB als Datenquelle zu verwenden und Dashboards zu erstellen.

Use Case 3: Docker Container Monitoring

Monitor Docker Container neben Systemmetriken:

# 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: Fehlerbehebung Hohe CPU Verwendung

Identifizieren und analysieren ressourcenintensive Prozesse:

# 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: Automatische Überwachung Script

Erstellen Sie ein Überwachungsskript mit Warnungen:

#!/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

oder Best Practices

  • ** Verwenden Sie Konfigurationsdateien** anstelle von Befehlszeilenoptionen für permanente Einstellungen, um Konsistenz über Sitzungen zu erhalten und Konfigurationen versionskontrollierbar zu machen

  • ** Setzen Sie geeignete Refresh-Intervalle** - Verwenden Sie 2-5 Sekunden zur interaktiven Überwachung, 10-30 Sekunden zur Hintergrundüberwachung, um die Reaktionsfähigkeit mit Systemlast auszugleichen

  • Filter unnötige Informationen - Verstecken irrelevanter Netzwerkschnittstellen, Festplattengeräte und Dateisysteme, um Cutter zu reduzieren und sich auf wichtige Metriken zu konzentrieren

  • Implementieren Sie die Authentifizierung für Fernüberwachung und Webschnittstellen, um unberechtigten Zugriff auf Systeminformationen zu verhindern, insbesondere in Produktionsumgebungen

  • **Export zu Zeitreihen-Datenbanken* wie InfluxDB oder Prometheus für langfristige Trendanalyse, Kapazitätsplanung und historische Fehlerbehebung

  • Run als systemd service auf Linux-Servern für automatische Inbetriebnahme und Überwachung Kontinuität über Neustarts

  • Monitor Docker-Container beim Betrieb von Container-Workloads, um die Ressourcennutzung pro Container zu verfolgen und ressourcenhungrige Anwendungen zu identifizieren

  • ** Verwenden Sie Farbschwellen weise* - Konfigurieren Sie vorsichtige/warning/kritische Schwellen basierend auf den normalen Betriebsbereichen Ihres Systems, um Alarmermüdung zu vermeiden

  • Verwalten Sie die API für Automatisierung und Integration mit vorhandenen Überwachungssystemen, Warnwerkzeugen oder benutzerdefinierten Dashboards

  • **Keep Blicke aktualisiert* - Regelmäßig aktualisieren, um neue Features, Leistungsverbesserungen und Sicherheits-Patches zu erhalten

Fehlerbehebung

Issue Solution
INLINE_CODE_99 Ensure glances is installed and in PATH. Try INLINE_CODE_100 and add INLINE_CODE_101 to PATH
High CPU usage by glances itself Increase refresh interval with INLINE_CODE_102 or higher. Disable unused plugins with INLINE_CODE_103
Cannot connect to remote server Check firewall rules allow port 61209. Verify server is running with INLINE_CODE_104. Test connectivity with INLINE_CODE_105
Web interface not accessible Ensure glances started with INLINE_CODE_106 flag. Check if port 61208 is available with INLINE_CODE_107. Bind to all interfaces with INLINE_CODE_108
Docker containers not showing Verify Docker socket is accessible: INLINE_CODE_109. Run glances with appropriate permissions or add user to docker group
Permission denied errors Run with INLINE_CODE_110 for full system access, or adjust permissions for specific resources. Some features require root privileges
Sensors not displaying Install INLINE_CODE_111 package and run INLINE_CODE_112. Install Python sensors library: INLINE_CODE_113
InfluxDB export not working Verify InfluxDB is running and accessible. Check credentials and database name. Install InfluxDB client: INLINE_CODE_114
Missing GPU information Install NVIDIA monitoring library: INLINE_CODE_115. Ensure NVIDIA drivers are installed and working
Config file changes not applied Verify config file location with INLINE_CODE_116. Check file syntax. Restart glances after configuration changes
Process list incomplete Increase process limit with INLINE_CODE_117 for unlimited. Check if kernel threads are hidden with INLINE_CODE_118
Unicode/display issues in terminal Set proper locale: INLINE_CODE_119. Use INLINE_CODE_120 flag if terminal doesn't support Unicode
_
Optionale Abhängigkeiten

Installieren Sie diese Pakete für verbesserte Funktionalität:

# 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]'