Build a Complete Prometheus Monitoring Stack with Grafana: Step‑by‑Step Docker Setup
This guide walks you through setting up a full Prometheus monitoring solution with Exporters, Alertmanager, and Grafana using Docker containers, covering component roles, configuration files, and visualizing host and container metrics on two sample hosts.
Prometheus is a powerful monitoring solution that provides data collection, storage, processing, visualization, and alerting.
Key Components
Prometheus consists of four main modules: Prometheus Server, Exporter, Alertmanager, and a visualization component.
Prometheus Server pulls data from Exporters, stores it, and offers the PromQL query language.
Exporter collects performance metrics from hosts or containers and exposes them via an HTTP endpoint.
Alertmanager receives alerts based on monitoring data and sends notifications according to predefined rules.
The visualization component originally built into Prometheus has been largely superseded by Grafana, which integrates seamlessly for rich dashboards.
Hands‑On Lab
1. Environment Setup
The lab monitors two hosts, collecting host‑level metrics and optionally container metrics using appropriate dashboards.
The following Docker containers are deployed:
Prometheus Server (running on 192.168.0.102)
Node Exporter – gathers host hardware and OS data.
cAdvisor – gathers container metrics.
Grafana – visualizes the collected data.
2. Run Node Exporter
docker run -d --name node-exporter -p 9100:9100 \
-v "/proc:/host/proc:ro" -v "/sys:/host/sys:ro" -v "/:/rootfs:ro" \
--restart=always --net="host" \
prom/node-exporter \
--path.procfs /host/proc --path.sysfs /host/sys \
--collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"Using --net="host" allows direct communication between Node Exporter and Prometheus Server.
3. Run cAdvisor
docker run -v /:/rootfs:ro -v /var/run:/var/run:rw \
-v /sys:/sys:ro -v /var/lib/docker:/var/lib/docker:ro \
-p8080:8080 -t --name cadvisor --net="host" \
google/cadvisor:latestAgain, --net="host" enables direct communication with Prometheus.
4. Run Prometheus Server
docker run -d -p 9090:9090 \
-v /root/prometheus.yml:/etc/prometheus/prometheus.yml \
--name prometheus --net host \
prom/prometheusThe prometheus.yml configuration defines a global scrape interval of 15 seconds and specifies static targets for the Exporters.
# my global config
global:
scrape_interval: 15s
evaluation_interval: 15s
alerting:
alertmanagers:
- static_configs:
- targets:
- alertmanager:9093
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090','localhost:8080','localhost:9100','192.168.0.101:9100','192.168.0.101:8080']Access http://192.168.0.102:9090 , go to the Status → Targets page; all targets should show UP , confirming successful data collection.
5. Install Grafana
docker run -d -p 3000:3000 \
-e "GF_SERVER_ROOT_URL=http://grafana.server.com" \
-e "GF_SECURITY_ADMIN_PASSWORD=admin@123" \
--net="host" grafana/grafanaThe -e "GF_SECURITY_ADMIN_PASSWORD=admin@123" flag sets the Grafana admin password.
Open http://192.168.0.102:3000 , add Prometheus as a data source, and import a ready‑made dashboard JSON (e.g., a host‑only dashboard) to visualize the metrics.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
