Configure Glances System Monitor #42

Open
opened 2025-09-14 08:10:48 +00:00 by tonym · 0 comments
Owner

Glances System Monitor Configuration Guide

Overview

Glances is a cross-platform system monitoring tool that provides a comprehensive view of system resources including CPU, memory, disk I/O, network, and running processes.


Container Installation

Docker Run Command

docker run -d \
  --name=glances \
  --restart=unless-stopped \
  -p 61208:61208 \
  -v /var/run/docker.sock:/var/run/docker.sock:ro \
  -v /host/proc:/host/proc:ro \
  -v /host/sys:/host/sys:ro \
  -v /host/etc:/host/etc:ro \
  -e GLANCES_OPT="-w" \
  nicolargo/glances:latest

Docker Compose

version: "3.8"
services:
  glances:
    image: nicolargo/glances:latest
    container_name: glances
    restart: unless-stopped
    ports:
      - "61208:61208"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /host/proc:/host/proc:ro
      - /host/sys:/host/sys:ro
      - /host/etc:/host/etc:ro
    environment:
      - GLANCES_OPT=-w
    pid: host
    network_mode: host

Container Configuration

Port Configuration

  • 61208: Web interface (HTTP)

Volume Mounts

  • /var/run/docker.sock:/var/run/docker.sock:ro: Docker container monitoring
  • /host/proc:/host/proc:ro: Process information
  • /host/sys:/host/sys:ro: System information
  • /host/etc:/host/etc:ro: Configuration files

Environment Variables

  • GLANCES_OPT: Command line options (-w for web mode)
  • TZ: Timezone setting

Initial Configuration

Web Interface Access

  1. Open browser to http://your-server-ip:61208
  2. No authentication required by default
  3. Real-time system monitoring dashboard

Configuration File

Create /mnt/user/appdata/glances/glances.conf:

[global]
refresh=2

[outputs]
curses_color=True
webui_username=admin
webui_password=your_secure_password

[cpu]
user_careful=50
user_warning=70
user_critical=90
iowait_careful=40
iowait_warning=60
iowait_critical=80

[mem]
careful=50
warning=70
critical=90

[swap]
careful=50
warning=70
critical=90

[load]
careful=70
warning=100
critical=500

[network]
hide=docker.*,veth.*

[docker]
max_name_size=20

Service Configuration

Alert Thresholds

  1. CPU Usage:

    • Careful: 50%
    • Warning: 70%
    • Critical: 90%
  2. Memory Usage:

    • Careful: 50%
    • Warning: 70%
    • Critical: 90%
  3. Disk I/O:

    • Monitor read/write rates
    • Alert on high wait times

Monitoring Modules

  • System information
  • CPU usage
  • Memory usage
  • Load average
  • Network interfaces
  • Disk I/O
  • File system usage
  • Running processes
  • Docker containers
  • GPU usage (if available)

Integration Points

With Prometheus

# Enable Prometheus export
docker run -d \
  --name=glances \
  -p 61208:61208 \
  -p 9091:9091 \
  -e GLANCES_OPT="-w --export prometheus" \
  nicolargo/glances:latest

With Grafana

  • Import Glances dashboard
  • Dashboard ID: 914 (Glances Dashboard)
  • Configure Prometheus data source

With Home Assistant

# configuration.yaml
sensor:
  - platform: glances
    host: 192.168.0.5
    port: 61208
    resources:
      - cpu_use
      - memory_use
      - disk_use
      - temperature_core

Monitoring & Notifications

SNMP Configuration

[snmp]
host=localhost
port=161
community=public
version=2c

Email Notifications

[smtp]
host=smtp.gmail.com
port=587
tls=True
user=your-email@gmail.com
password=your-app-password
to=admin@yourdomain.com
subject=Glances Alert

Custom Actions

[actions]
# Restart service on high CPU
cpu_critical=sudo systemctl restart high-cpu-service

# Clear cache on high memory
memory_critical=sudo sync && echo 3 | sudo tee /proc/sys/vm/drop_caches

Backup Configuration

Configuration Backup

#!/bin/bash
# Backup glances configuration
cp /mnt/user/appdata/glances/glances.conf /mnt/user/backups/glances/glances.conf.$(date +%Y%m%d)

Automated Backup

# Add to crontab
0 2 * * 0 /path/to/backup-glances.sh

Testing Procedures

Functionality Tests

  1. Web Interface Test:

    curl -I http://localhost:61208
    
  2. API Test:

    curl http://localhost:61208/api/3/status
    
  3. Metrics Test:

    curl http://localhost:61208/api/3/cpu
    

Performance Tests

  • Verify real-time updates
  • Check resource usage of Glances itself
  • Test alert triggering

Troubleshooting

Common Issues

  1. Permission Denied:

    # Add user to docker group
    sudo usermod -aG docker $USER
    
  2. Missing System Info:

    # Check volume mounts
    docker exec glances ls -la /host/proc
    
  3. High Resource Usage:

    # Reduce refresh rate
    export GLANCES_OPT="-w -t 5"
    

Log Analysis

# View container logs
docker logs glances

# Monitor real-time logs
docker logs -f glances

Performance Optimization

  • Increase refresh interval for lower resource usage
  • Disable unused modules
  • Use filters to hide unnecessary processes

Maintenance

Regular Updates

# Update container
docker pull nicolargo/glances:latest
docker stop glances
docker rm glances
# Recreate with new image

Health Checks

# Check service status
curl -s http://localhost:61208/api/3/status | jq

# Monitor resource usage
docker stats glances

Log Rotation

# Configure Docker log rotation
docker run --log-driver=json-file --log-opt max-size=10m --log-opt max-file=3

Security Considerations

Authentication

[passwords]
# Username/password in glances.conf
user1=password1
user2=password2

Network Security

  • Bind to specific interface: -p 127.0.0.1:61208:61208
  • Use reverse proxy with SSL
  • Implement firewall rules

Access Control

  • Limit API access
  • Use read-only volume mounts
  • Regular security updates

Advanced Configuration

Custom Plugins

# Custom plugin example
from glances_plugin import GlancesPlugin

class Plugin(GlancesPlugin):
    def __init__(self, args=None):
        super(Plugin, self).__init__(args=args)
        self.plugin_name = "custom"

Export Options

  • CSV export: --export csv --export-csv-file /tmp/glances.csv
  • JSON export: --export json
  • InfluxDB export: --export influxdb

This guide provides comprehensive coverage of Glances system monitoring setup and configuration.

# Glances System Monitor Configuration Guide ## Overview Glances is a cross-platform system monitoring tool that provides a comprehensive view of system resources including CPU, memory, disk I/O, network, and running processes. --- ## Container Installation ### Docker Run Command ```bash docker run -d \ --name=glances \ --restart=unless-stopped \ -p 61208:61208 \ -v /var/run/docker.sock:/var/run/docker.sock:ro \ -v /host/proc:/host/proc:ro \ -v /host/sys:/host/sys:ro \ -v /host/etc:/host/etc:ro \ -e GLANCES_OPT="-w" \ nicolargo/glances:latest ``` ### Docker Compose ```yaml version: "3.8" services: glances: image: nicolargo/glances:latest container_name: glances restart: unless-stopped ports: - "61208:61208" volumes: - /var/run/docker.sock:/var/run/docker.sock:ro - /host/proc:/host/proc:ro - /host/sys:/host/sys:ro - /host/etc:/host/etc:ro environment: - GLANCES_OPT=-w pid: host network_mode: host ``` --- ## Container Configuration ### Port Configuration - **61208**: Web interface (HTTP) ### Volume Mounts - `/var/run/docker.sock:/var/run/docker.sock:ro`: Docker container monitoring - `/host/proc:/host/proc:ro`: Process information - `/host/sys:/host/sys:ro`: System information - `/host/etc:/host/etc:ro`: Configuration files ### Environment Variables - `GLANCES_OPT`: Command line options (-w for web mode) - `TZ`: Timezone setting --- ## Initial Configuration ### Web Interface Access 1. Open browser to `http://your-server-ip:61208` 2. No authentication required by default 3. Real-time system monitoring dashboard ### Configuration File Create `/mnt/user/appdata/glances/glances.conf`: ```ini [global] refresh=2 [outputs] curses_color=True webui_username=admin webui_password=your_secure_password [cpu] user_careful=50 user_warning=70 user_critical=90 iowait_careful=40 iowait_warning=60 iowait_critical=80 [mem] careful=50 warning=70 critical=90 [swap] careful=50 warning=70 critical=90 [load] careful=70 warning=100 critical=500 [network] hide=docker.*,veth.* [docker] max_name_size=20 ``` --- ## Service Configuration ### Alert Thresholds 1. **CPU Usage**: - Careful: 50% - Warning: 70% - Critical: 90% 2. **Memory Usage**: - Careful: 50% - Warning: 70% - Critical: 90% 3. **Disk I/O**: - Monitor read/write rates - Alert on high wait times ### Monitoring Modules - System information - CPU usage - Memory usage - Load average - Network interfaces - Disk I/O - File system usage - Running processes - Docker containers - GPU usage (if available) --- ## Integration Points ### With Prometheus ```bash # Enable Prometheus export docker run -d \ --name=glances \ -p 61208:61208 \ -p 9091:9091 \ -e GLANCES_OPT="-w --export prometheus" \ nicolargo/glances:latest ``` ### With Grafana - Import Glances dashboard - Dashboard ID: 914 (Glances Dashboard) - Configure Prometheus data source ### With Home Assistant ```yaml # configuration.yaml sensor: - platform: glances host: 192.168.0.5 port: 61208 resources: - cpu_use - memory_use - disk_use - temperature_core ``` --- ## Monitoring & Notifications ### SNMP Configuration ```ini [snmp] host=localhost port=161 community=public version=2c ``` ### Email Notifications ```ini [smtp] host=smtp.gmail.com port=587 tls=True user=your-email@gmail.com password=your-app-password to=admin@yourdomain.com subject=Glances Alert ``` ### Custom Actions ```ini [actions] # Restart service on high CPU cpu_critical=sudo systemctl restart high-cpu-service # Clear cache on high memory memory_critical=sudo sync && echo 3 | sudo tee /proc/sys/vm/drop_caches ``` --- ## Backup Configuration ### Configuration Backup ```bash #!/bin/bash # Backup glances configuration cp /mnt/user/appdata/glances/glances.conf /mnt/user/backups/glances/glances.conf.$(date +%Y%m%d) ``` ### Automated Backup ```bash # Add to crontab 0 2 * * 0 /path/to/backup-glances.sh ``` --- ## Testing Procedures ### Functionality Tests 1. **Web Interface Test**: ```bash curl -I http://localhost:61208 ``` 2. **API Test**: ```bash curl http://localhost:61208/api/3/status ``` 3. **Metrics Test**: ```bash curl http://localhost:61208/api/3/cpu ``` ### Performance Tests - Verify real-time updates - Check resource usage of Glances itself - Test alert triggering --- ## Troubleshooting ### Common Issues 1. **Permission Denied**: ```bash # Add user to docker group sudo usermod -aG docker $USER ``` 2. **Missing System Info**: ```bash # Check volume mounts docker exec glances ls -la /host/proc ``` 3. **High Resource Usage**: ```bash # Reduce refresh rate export GLANCES_OPT="-w -t 5" ``` ### Log Analysis ```bash # View container logs docker logs glances # Monitor real-time logs docker logs -f glances ``` ### Performance Optimization - Increase refresh interval for lower resource usage - Disable unused modules - Use filters to hide unnecessary processes --- ## Maintenance ### Regular Updates ```bash # Update container docker pull nicolargo/glances:latest docker stop glances docker rm glances # Recreate with new image ``` ### Health Checks ```bash # Check service status curl -s http://localhost:61208/api/3/status | jq # Monitor resource usage docker stats glances ``` ### Log Rotation ```bash # Configure Docker log rotation docker run --log-driver=json-file --log-opt max-size=10m --log-opt max-file=3 ``` --- ## Security Considerations ### Authentication ```ini [passwords] # Username/password in glances.conf user1=password1 user2=password2 ``` ### Network Security - Bind to specific interface: `-p 127.0.0.1:61208:61208` - Use reverse proxy with SSL - Implement firewall rules ### Access Control - Limit API access - Use read-only volume mounts - Regular security updates --- ## Advanced Configuration ### Custom Plugins ```python # Custom plugin example from glances_plugin import GlancesPlugin class Plugin(GlancesPlugin): def __init__(self, args=None): super(Plugin, self).__init__(args=args) self.plugin_name = "custom" ``` ### Export Options - CSV export: `--export csv --export-csv-file /tmp/glances.csv` - JSON export: `--export json` - InfluxDB export: `--export influxdb` This guide provides comprehensive coverage of Glances system monitoring setup and configuration.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: tonym/NastyNAS#42
No description provided.