Skip to content

Monitoring Stack Documentation

Overview

The monitoring stack provides comprehensive observability for the entire Docker infrastructure, enabling proactive monitoring, alerting, and troubleshooting. It combines industry-standard tools to collect metrics, aggregate logs, visualize data, and manage alerts.

Architecture

graph TB
    subgraph "Data Collection"
        NE[Node Exporter<br/>System Metrics]
        CA[cAdvisor<br/>Container Metrics]
        PE[PostgreSQL Exporter<br/>Database Metrics]
        BE[Blackbox Exporter<br/>Endpoint Monitoring]
        PT[Promtail<br/>Log Collection]
    end

    subgraph "Storage & Processing"
        P[Prometheus<br/>Metrics Storage]
        L[Loki<br/>Log Storage]
    end

    subgraph "Visualization & Alerting"
        G[Grafana<br/>Dashboards]
        AM[AlertManager<br/>Alert Routing]
    end

    NE --> P
    CA --> P
    PE --> P
    BE --> P
    PT --> L

    P --> G
    L --> G
    P --> AM

    AM --> E[Email/Discord/Webhook]

Components

Core Services

Prometheus (https://prometheus.rbnk.uk)

  • Purpose: Time-series database for metrics storage and querying
  • Features:
  • Collects metrics from various exporters
  • Evaluates alert rules
  • Provides PromQL query language
  • 30-day retention by default
  • Access: Protected by Traefik authentication

Grafana (https://grafana.rbnk.uk)

  • Purpose: Visualization platform for metrics and logs
  • Features:
  • Pre-configured dashboards
  • Custom dashboard creation
  • Multiple data sources (Prometheus, Loki)
  • Alert visualization
  • Default Credentials: admin / (configured in .env)

Loki

  • Purpose: Log aggregation system
  • Features:
  • Collects logs from all containers
  • Indexes metadata, not log content (cost-effective)
  • Integrates with Grafana for visualization
  • 30-day retention

AlertManager

  • Purpose: Alert routing and management
  • Features:
  • Groups and deduplicates alerts
  • Routes alerts based on severity
  • Supports multiple notification channels
  • Silence and inhibition rules

Data Collectors

Node Exporter

  • Collects host-level metrics:
  • CPU usage and load
  • Memory statistics
  • Disk I/O and space
  • Network statistics
  • System information

cAdvisor

  • Collects container-level metrics:
  • Container CPU usage
  • Memory consumption
  • Network I/O per container
  • Disk usage per container

PostgreSQL Exporter

  • Monitors Supabase database:
  • Connection statistics
  • Database sizes
  • Query performance
  • Replication status
  • Lock information

Blackbox Exporter

  • Monitors service endpoints:
  • HTTP/HTTPS availability
  • Response times
  • SSL certificate expiry
  • DNS resolution

Promtail

  • Log collection agent:
  • Tails container logs
  • Adds metadata labels
  • Ships to Loki
  • Handles log rotation

Access and Usage

Accessing Services

  1. Grafana Dashboard: https://grafana.rbnk.uk
  2. Main entry point for monitoring
  3. View dashboards, explore metrics, search logs

  4. Prometheus UI: https://prometheus.rbnk.uk

  5. Direct metric queries
  6. Target health status
  7. Alert state viewing

Common Tasks

Viewing System Health

  1. Open Grafana: https://grafana.rbnk.uk
  2. Navigate to DashboardsInfrastructure Overview
  3. Key panels to check:
  4. System resource usage
  5. Container status
  6. Service availability
  7. Recent alerts

Monitoring PostgreSQL Database

  1. Open Grafana: https://grafana.rbnk.uk
  2. Navigate to DashboardsPostgreSQL Database
  3. Monitor key database metrics:
  4. Active/idle connections
  5. Query performance (SELECT, INSERT, UPDATE, DELETE)
  6. Cache hit rates (should be > 90%)
  7. Database sizes and growth
  8. Lock contention
  9. Checkpoint and WAL statistics

Searching Logs

  1. In Grafana, go to Explore
  2. Select Loki as data source
  3. Use LogQL queries:
    # All logs from a specific container
    {container_name="supa-db"}
    
    # Error logs across all services
    {job="containerlogs"} |= "ERROR"
    
    # Logs from last hour with specific text
    {container_name="traefik"} |= "404" | __timestamp__ > (now() - 1h)
    

Creating Custom Dashboards

  1. Click +CreateDashboard
  2. Add panels with PromQL queries:
    # Container memory usage
    container_memory_usage_bytes{name!~"POD|k8s_.*"}
    
    # HTTP request rate
    rate(traefik_service_requests_total[5m])
    
    # Database connections
    pg_stat_database_numbackends
    

Managing Alerts

  1. View active alerts: AlertingAlert rules
  2. Silence alerts: AlertingSilences
  3. Configure contact points: AlertingContact points

Pre-configured Dashboards

Infrastructure Overview

  • System resource utilization
  • Container health status
  • Network traffic overview
  • Disk usage trends

Service Health

  • Service availability status
  • Response time percentiles
  • Error rates by service
  • SSL certificate status

Resource Optimization

  • Container resource usage ranking
  • Memory and CPU trends
  • Disk I/O patterns
  • Network bandwidth usage

Security Monitoring

  • Failed authentication attempts
  • Unusual network activity
  • Container restart patterns
  • Access logs analysis

PostgreSQL Database (ID: 9628)

  • Database connections and activity
  • Query performance and slow queries
  • Cache hit ratios
  • Database size and growth
  • Transaction rates (commits/rollbacks)
  • Lock statistics and deadlocks
  • Checkpoint performance
  • Background writer statistics
  • Temporary file usage

Alert Management

Alert Severity Levels

  • Critical: Immediate action required
  • Service down
  • Database unreachable
  • Disk space < 10%
  • Backup failure

  • Warning: Investigation needed

  • High resource usage
  • Slow queries
  • Certificate expiring soon
  • Container restarts

  • Info: Informational only

  • Scheduled maintenance
  • Non-critical updates
  • Usage statistics

Notification Channels

AlertManager integrates with the notification stack for flexible alert routing:

Primary Integration - Apprise: - AlertManager sends webhooks to http://apprise:8000/notify/apprise - Apprise distributes to configured channels (WhatsApp, Telegram, Email, Discord, etc.) - Tag-based routing allows selective notifications

Configuration Example:

# alertmanager.yml
receivers:
  - name: 'default'
    webhook_configs:
      - url: 'http://apprise:8000/notify/apprise'
        send_resolved: true

  - name: 'critical'
    webhook_configs:
      - url: 'http://apprise:8000/notify/apprise?tag=critical,oncall'
        send_resolved: true

Available Channels via Apprise: - WhatsApp: Via WhatsApp Business API - Telegram: Direct messages and group notifications - Email: SMTP-based email notifications - Discord: Webhooks to channels - ntfy: Push notifications to mobile/desktop - Slack: Workspace notifications - Custom: Any service supported by Apprise

Common Alert Scenarios

High Memory Usage

Alert: HighMemoryUsage
Severity: warning
Action: 
1. Check Grafana memory dashboard
2. Identify memory-consuming containers
3. Consider scaling or optimization

Service Down

Alert: ServiceDown
Severity: critical
Action:
1. Check container status: docker ps
2. Review logs: docker logs [container]
3. Restart if needed: docker compose restart [service]

Disk Space Low

Alert: DiskSpaceLow
Severity: critical
Action:
1. Check disk usage: df -h
2. Clean Docker: docker system prune -a
3. Review backup retention
4. Consider disk expansion

Monitoring Best Practices

Dashboard Usage

  1. Start with Overview: Always check the Infrastructure Overview first
  2. Drill Down: Use detailed dashboards for specific issues
  3. Time Ranges: Adjust time ranges to identify patterns
  4. Annotations: Mark deployments and changes

Query Optimization

  1. Use Recording Rules: For frequently-used complex queries
  2. Limit Time Ranges: Avoid queries over large time spans
  3. Use Aggregations: Reduce data points with avg(), max(), etc.
  4. Label Filtering: Be specific with label selectors

Alert Tuning

  1. Avoid Alert Fatigue: Set appropriate thresholds
  2. Use Time Windows: Require conditions to persist (e.g., "for: 5m")
  3. Group Related Alerts: Use inhibition rules
  4. Document Runbooks: Link alerts to troubleshooting guides

Maintenance Tasks

Daily

  • Check Grafana dashboard for anomalies
  • Review any triggered alerts
  • Verify backup job completion
  • Ensure all monitoring services are running

Weekly

  • Review resource usage trends
  • Check for security-related alerts
  • Update dashboards based on needs
  • Review and acknowledge resolved alerts
  • Verify permission fix script is accessible

Monthly

  • Analyze long-term trends
  • Capacity planning review
  • Alert rule optimization
  • Dashboard cleanup
  • Review Watchtower exclusions for monitoring stack

After System Updates

  • Run permission fix script if monitoring services fail to start
  • Verify AlertManager configuration is valid
  • Check that Watchtower exclusions are maintained
  • Test alert delivery to n8n webhooks

Troubleshooting

Permission Issues

Problem: Services fail to start with permission denied errors

Solution: Use the permission fix script:

/srv/dockerdata/monitoring/fix-permissions.sh

Details: The monitoring stack runs with specific user IDs: - Prometheus: User 65534 (nobody) - Grafana: User 472 - Loki: User 10001 - AlertManager: User 65534 (nobody)

These user IDs must own their respective Docker volume data directories. The fix script automatically corrects ownership and permissions.

Prevention: Watchtower is excluded from auto-updating monitoring containers to prevent permission issues:

# Each monitoring service includes:
labels:
  - "com.centurylinklabs.watchtower.enable=false"

AlertManager Configuration Issues

Problem: AlertManager fails to start with "time interval crossing midnight" errors

Root Cause: Complex time interval configurations can cause parsing issues when intervals cross midnight boundaries.

Solution: Use simplified, minimal configuration: - Avoid complex time-based routing - Use simple repeat intervals (1h, 30m, etc.) - Test configuration with: docker exec alertmanager amtool config check /etc/alertmanager/config.yml

Current Configuration: Simplified to basic webhook routing with n8n integration - Default receiver: Basic webhook placeholder - N8N webhook: Routes all severity levels to n8n automation workflows - Simple inhibition rules prevent alert spam

Metrics Not Appearing

  1. Check exporter health:

    docker ps | grep exporter
    

  2. Verify Prometheus targets:

  3. Visit https://prometheus.rbnk.uk/targets
  4. All targets should show "UP"

  5. Test exporter directly:

    # Node exporter
    curl http://localhost:9100/metrics
    
    # cAdvisor
    curl http://localhost:8080/metrics
    

Grafana Issues

  1. Dashboard not loading:
  2. Check datasource configuration
  3. Verify Prometheus is accessible
  4. Review browser console for errors
  5. Verify Grafana permissions (user 472)

  6. No data points:

  7. Verify time range selection
  8. Check query syntax
  9. Ensure metrics exist in Prometheus

  10. Permission denied on startup:

  11. Run permission fix script: /srv/dockerdata/monitoring/fix-permissions.sh
  12. Check volume ownership: ls -la /srv/dockerdata/docker-root/volumes/monitoring_grafana_data/_data

Alert Not Firing

  1. Check alert configuration:

    docker exec prometheus promtool check rules /etc/prometheus/alerts.yml
    

  2. Verify alert state in Prometheus:

  3. Visit https://prometheus.rbnk.uk/alerts

  4. Check AlertManager:

    docker logs alertmanager
    

  5. AlertManager configuration errors:

  6. Check for time interval issues
  7. Validate config: docker exec alertmanager amtool config check
  8. Review webhook connectivity to n8n

High Resource Usage

  1. Prometheus:
  2. Reduce retention period
  3. Increase scrape intervals
  4. Remove unused metrics

  5. Grafana:

  6. Limit dashboard refresh rates
  7. Optimize queries
  8. Cache dashboard results

  9. Loki:

  10. Reduce log retention
  11. Filter unnecessary logs
  12. Compress old data

Security Considerations

  1. Authentication:
  2. Grafana uses its own authentication
  3. Prometheus protected by Traefik auth
  4. Change default passwords

  5. Network Isolation:

  6. Monitoring network separate from application networks
  7. Only Grafana and Prometheus exposed externally

  8. Data Sensitivity:

  9. Metrics may contain sensitive information
  10. Logs should be filtered for secrets
  11. Use appropriate retention policies

  12. Container Security:

  13. Monitoring containers run with specific non-root user IDs
  14. Watchtower auto-updates disabled to prevent permission issues
  15. Volume permissions strictly controlled via fix script

  16. Alert Security:

  17. AlertManager webhooks use HTTPS for n8n integration
  18. Webhook tokens should be configured for production
  19. Alert content filtered to avoid sensitive data exposure

Integration Guide

Adding New Service Metrics

  1. For services with Prometheus support:

    # In service's docker-compose.yml
    services:
      myservice:
        labels:
          - "prometheus.io/scrape=true"
          - "prometheus.io/port=8080"
          - "prometheus.io/path=/metrics"
    

  2. For custom metrics:

    # In prometheus/prometheus.yml
    scrape_configs:
      - job_name: 'myservice'
        static_configs:
          - targets: ['myservice:8080']
    

Creating Service-Specific Dashboards

  1. Design dashboard in Grafana UI
  2. Export as JSON
  3. Save to: monitoring/grafana/dashboards/
  4. Restart Grafana to auto-import

Adding Custom Alerts

  1. Edit monitoring/prometheus/alerts.yml
  2. Add alert rule:
    - alert: MyServiceDown
      expr: up{job="myservice"} == 0
      for: 1m
      labels:
        severity: critical
      annotations:
        summary: "MyService is down"
    
  3. Restart Prometheus

Resource Requirements

  • Total Stack: ~2-3GB RAM
  • Disk Space: ~5-10GB for 30-day retention
  • CPU: Minimal during normal operation

Per-Component Requirements

Component RAM CPU Disk
Prometheus 1GB Low 2-5GB
Grafana 200MB Low 100MB
Loki 500MB Low 2-5GB
AlertManager 50MB Minimal 50MB
Exporters 50-100MB each Minimal Minimal

Backup and Recovery

What to Backup

  1. Grafana:
  2. Dashboards (auto-provisioned)
  3. Data sources (auto-provisioned)
  4. User preferences (in volume)

  5. Prometheus:

  6. Metric data (optional, can be regenerated)
  7. Alert rules (in config files)

  8. Configuration:

  9. All YAML files in monitoring/
  10. Environment variables (.env)

Backup Script

The monitoring stack is included in the infrastructure backup:

/srv/dockerdata/_scripts/monitoring-backup.sh

Recovery Process

  1. Restore configuration files
  2. Restore Docker volumes (if needed)
  3. Restart monitoring stack
  4. Verify all exporters are connected

Useful Resources