Building a Scalable Monitoring Stack with Prometheus and Grafana

Overview

Prometheus is an open-source systems monitoring and alerting toolkit originally developed at SoundCloud and now a staple within the Cloud Native Computing Foundation (CNCF). It excels at collecting time-series data using a pull-based model, offering a powerful query language (PromQL) and a multi-dimensional data model.

Grafana complements Prometheus by serving as an advanced visualization layer. While Prometheus provides the data storage and query engine, Grafana transforms this data into sophisticated, interactive dashboards that are significantly easier to interpret for operational teams.

Deployment via Docker

Using Docker simplifies the lifecycle management of these components. Below is a structured approach to running both services.

Prometheus Container Setup

Create a directory structure to persist you're monitoring data and configurations:

mkdir -p /opt/monitoring/prometheus/{data,config,rules}

Create a prometheus.yml configuration file to define your scrape targets:

global:
 scrape_interval: 60s

scrape_configs:
 - job_name: 'self-monitor'
   static_configs:
     - targets: ['localhost:9090']
 - job_name: 'node-exporter'
   static_configs:
     - targets: ['192.168.1.10:9100']

Start the container with volume mounts:

docker run -d --name prometheus \
 -p 9090:9090 \
 -v /opt/monitoring/prometheus/config:/etc/prometheus \
 -v /opt/monitoring/prometheus/data:/prometheus/data \
 prom/prometheus --config.file=/etc/prometheus/prometheus.yml

Grafana Container Setup

Deploy Grafana to visualize the metrics:

docker run -d --name grafana \
 -p 3000:3000 \
 -e "GF_SECURITY_ADMIN_PASSWORD=securepassword" \
 grafana/grafana

Once running, access the dashboard at http://localhost:3000. Navigate to Connections > Data Sources and add your Prometheus instance URL.

Integrating Exporters

Exporters are agents that run on target hosts to expose metrics. Common implementations include:

1. Node Exporter (System Metrics)

Deploying node_exporter on Linux provides hardware and OS-level telemetry. Register it as a systemd service for reliability:

[Unit]
Description=Node Exporter
After=network.target

[Service]
ExecStart=/usr/local/bin/node_exporter
Restart=always

[Install]
WantedBy=multi-user.target

2. MySQL Exporter (Database Metrics)

To monitor database performance, create a restricted user in MySQL:

CREATE USER 'exporter_user'@'localhost' IDENTIFIED BY 'password';
GRANT SELECT, PROCESS, REPLICATION CLIENT ON *.* TO 'exporter_user'@'localhost';

Run the exporter with the DATA_SOURCE_NAME environment variable pointing to your database credentials.

Visualizing Data

Instead of building dashboards from scratch, leverage the Grafana community library. Visit the official Grafana Dashboards portal to search for specific identifiers (e.g., ID 15172 for Node Exporter). Simply input the ID in the "Import" section of your Grafana dashboard to instantly visualize your collected metrics.

Tags: prometheus Grafana docker monitoring Metrics

Posted on Mon, 31 Aug 2026 16:08:25 +0000 by largo