Konstantinos Antoniou.

← Projects

Infrastructure Monitoring with Prometheus and Grafana

Introduction

As part of maintaining a robust and reliable home lab and multi-site network infrastructure, I implemented a monitoring solution using Prometheus for data collection and Grafana for visualization. This project aims to provide real-time insights into the health, performance, and resource usage of my infrastructure, which includes Proxmox VMs, Docker containers, network devices, and multi-site connectivity. Monitoring these components ensures high availability, proactive troubleshooting, and efficient resource utilization.

Project Goals

  • Collect performance metrics from all key components of the infrastructure.
  • Visualize metrics in dashboards for easy analysis.
  • Set up alerts for critical events such as high CPU usage, network failures, or disk space exhaustion.
  • Monitor both home and remote sites using a unified platform.
  • Gain hands-on experience with Prometheus, Grafana, exporters, and alerting systems.

Infrastructure Overview

Home Lab (Site A):
  • Proxmox : Hosting VMs for Debian, Windows, and containerized services (Docker/Portainer).
  • Docker Containers: WordPress, Nextcloud, Heimdall, Watchtower, OpenMediaVault.
  • Other Services: Zerotier for site-to-site connectivity.
Remote Site (Site B):
  • MikroTik hAP ax² router.
  • Subnet-segmented LANs (Guest, Devices, Admin).
Monitoring Scope:
  • CPU, memory, disk usage of VMs and containers.
  • Network latency, throughput, and device availability.
  • Service status (HTTP endpoints, Docker containers).
  • VPN connectivity metrics.

Tools Used

  • Docker: Container runtime for easy deployment of Prometheus and Grafana.
  • Prometheus: Open-source monitoring system for collecting metrics.
  • Grafana: Visualization platform for dashboards and alerts.
  • Node Exporter: Prometheus exporter for Linux system metrics.
  • Docker Compose: Tool for defining and managing multi-container Docker applications.

1. Node Exporter

Installing Node Exporter for Prometheus is a straightforward process. Node Exporter is a lightweight agent that exposes hardware and OS metrics (CPU, memory, disk, network, etc.) in a format Prometheus can scrape.

Go to: Prometheus

# Replace  with the latest release, e.g., 1.7.1
wget https://github.com/prometheus/node_exporter/releases/download/v1.10.2/node_exporter-1.10.2.linux-amd64.tar.gz

# Extract it
tar xvfz node_exporter-.linux-amd64.tar.gz
cd node_exporter-.linux-amd64
./node_exporter
Run Node Exporter as a Service
  • Create a node_exporter user:
sudo useradd -rs /bin/false node_exporter
  • Move the binary to /usr/local/bin:
sudo cp node_exporter /usr/local/bin/
  • Create a systemd service file:
sudo nano /etc/systemd/system/node_exporter.service
  • Add the following content:
Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target

[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter

[Install]
WantedBy=multi-user.target

2. Prometheus Configuration

Create a configuration file for Prometheus: /opt/appdata/prometheus/prometheus.yml
# my global config
global:
  scrape_interval: 15s 

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

# A scrape configuration containing exactly one endpoint to scrape:
scrape_configs:
  # The job name is added as a label `job=` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets:
        - "192.0.2.20:9100"
        - "192.0.2.21:9100"
        - "192.0.2.22:9100"
        - "192.0.2.27:9100"
        - "192.0.2.24:9100"
        - "192.0.2.18:9100"
        - "192.0.2.16:9100"
        - "192.0.2.15:9100"
        - "198.51.100.17:9100"

Screenshot 1: A scrape configuration containing exactly one endpoint to scrape


3. Docker Compose File

services:
  prometheus:
    image: prom/pro
      - "9090:9090"
    volumes:
      - /opt/appdata/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
      - /opt/appdata/prometheus/data:/prometheus
    restart: unless-stopped
  grafana:
    image: grafana/grafana:latest
    container_name: Grafana
    ports:
      - "3000:3000"
    volumes:
      - /opt/appdata/grafana:/var/lib/grafana
    environment:
      - GF_SECURITY_ADMIN_USER=${GF_ADMIN_USER}
      - GF_SECURITY_ADMIN_PASSWORD=${GF_ADMIN_PASSWORD}
      - GF_INSTALL_PLUGINS=grafana-piechart-panel,grafana-clock-panel
    depends_on:
      - prometheus
    restart: unless-stopped

networks:
  default:
    external: true
    name: Apps-Network  # External network configuration named Apps-Network

Verify in Grafana

Configuration of Grafana Dashboards
  1. Log in to Grafana.
  2. Add Prometheus as a data source:
    • URL: http://prometheus:9090
  3. Import or create dashboards:
    • Node Exporter Full for system metrics.
    • Custom dashboards for Docker containers or network metrics.
  4. Set up alerts to notify when thresholds are exceeded (e.g., CPU > 80%)

Screenshot 2: Configuration of Grafana Dashboards


Use Cases

  • Server Monitoring: CPU, RAM, disk usage, and network statistics.
  • Docker Monitoring: Container uptime, CPU, memory, and network.
  • Alerting: Email or webhook notifications for critical metrics.
  • Trend Analysis: Historical graphs to optimize resource usage.

Conclusion

Using Docker, Prometheus, and Grafana provides a robust, flexible, and scalable monitoring solution for my infrastructure. This setup allows real-time monitoring, alerting, and visualization, significantly improving infrastructure management. The modular architecture allows adding more exporters for network devices, databases, or custom applications in the future.