Cloud Native 7 min read

Master Prometheus: Step‑by‑Step Container & Host Monitoring with Grafana

This guide introduces Prometheus, explains its advantages over traditional monitoring tools, walks through installation, configuration, and Docker deployment, and demonstrates practical monitoring of Docker containers, Linux hosts, and visualization with Grafana, providing complete code snippets and screenshots.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Prometheus: Step‑by‑Step Container & Host Monitoring with Grafana

Prometheus Overview is an open‑source monitoring and alerting toolkit designed for cloud‑native environments. Compared with traditional systems like Nagios or Zabbix, it offers easy management, high efficiency, scalability, rich dashboards, and built‑in support for Docker and Kubernetes.

Prometheus Architecture

The main components are:

Prometheus Server: collects metrics and stores time‑series data, provides query API
Client Library: client libraries for instrumenting code
Pushgateway: short‑term storage for metrics from batch jobs
Exporters: expose metrics from third‑party services
Alertmanager: handles alerts
Web UI: simple web console

Installation steps:

Download the official installation guide from https://prometheus.io/docs/prometheus/latest/installation/

Prepare two servers: 192.168.106.101 (Prometheus server) and 192.168.106.100 (target host)

Copy prometheus.yml to the server and configure global scrape interval, alerting, and scrape jobs for Prometheus itself, Docker, and the Linux node.

Run Prometheus in Docker:

docker run -d --name=prometheus -p 9090:9090 -v /tmp/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus

Access http://192.168.106.101:9090/ to verify the UI.

Monitoring a Container Service

Use docker stats --no-stream lnmp_nginx for quick metrics, or deploy cAdvisor to collect detailed container metrics.

docker run -d \
  --volume=/:/rootfs:ro \
  --volume=/var/run:/var/run:ro \
  --volume=/sys:/sys:ro \
  --volume=/var/lib/docker/:/var/lib/docker:ro \
  --volume=/dev/disk/:/dev/disk:ro \
  --publish=8080:8080 \
  --name=cadvisor \
  google/cadvisor:latest

cAdvisor UI is available at http://192.168.106.100:8080/containers/ and its metrics endpoint ( http://192.168.106.100:8080/metrics ) can be scraped by Prometheus. Add a new job in prometheus.yml pointing to the cAdvisor address and restart Prometheus.

Monitoring a Linux Host

Deploy the Node Exporter as a systemd service to expose host metrics.

#!/bin/bash
wget https://github.com/prometheus/node_exporter/releases/download/v0.17.0/node_exporter-0.17.0.linux-amd64.tar.gz
tar zxf node_exporter-0.17.0.linux-amd64.tar.gz
mv node_exporter-0.17.0.linux-amd64 /usr/local/node_exporter
cat <<EOF >/usr/lib/systemd/system/node_exporter.service
[Unit]
Description=Node Exporter
[Service]
Restart=on-failure
ExecStart=/usr/local/node_exporter/node_exporter
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable node_exporter
systemctl restart node_exporter

Metrics are available at http://192.168.106.100:9100/metrics . Add a job for node_exporter in Prometheus and restart.

Visualizing Metrics with Grafana

Run Grafana in Docker, configure Prometheus as a data source, and import ready‑made dashboards (e.g., template 9276) to view container and host metrics.

docker run -d --name=grafana -p 3000:3000 grafana/grafana

After adding the Prometheus data source at http://192.168.106.101:9090 , the dashboards display real‑time monitoring of all containers and the Linux host.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

monitoringPrometheusGrafananode_exportercAdvisor
MaGe Linux Operations
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.