A monitoring lab with Prometheus and Grafana
Run a small monitoring stack on your own computer: collect metrics from a machine, draw dashboards, set an alert and test a backup, so you can practise the monitoring and observability courses with real tools.
What you need
Monitoring has three parts: collect numbers from systems (metrics), look at them (dashboards) and tell someone when they go wrong (alerts). A free, widely used stack does all three:
- node_exporter publishes a machine’s CPU, memory, disk and network numbers.
- Prometheus (prometheus.io) scrapes those numbers on a timer and stores them.
- Grafana (grafana.com) draws dashboards from Prometheus.
- Alertmanager routes alerts, for example to email or a chat tool.
Set it up
The quickest route is Docker Compose. Create a folder with a prometheus.yml:
global:
scrape_interval: 15s
scrape_configs:
- job_name: "node"
static_configs:
- targets: ["node-exporter:9100"]
and a docker-compose.yml that runs prom/prometheus, grafana/grafana and prom/node-exporter (mount the file into Prometheus, publish ports 9090 and 3000, and put the three on one network). Then:
docker compose up -d
Open http://localhost:9090 for Prometheus and http://localhost:3000 for Grafana (the first sign-in is admin; change the password immediately). In Grafana add a Prometheus data source pointing to http://prometheus:9090, then import a community “Node Exporter” dashboard.
To monitor another VM, install prometheus-node-exporter there (sudo apt install prometheus-node-exporter) and add vm-address:9100 to the targets.
Check that it works
- In Prometheus, Status, Targets shows each target UP.
- The query
node_memory_MemAvailable_bytesreturns a number, andrate(node_cpu_seconds_total{mode="idle"}[1m])returns a graph. - Your Grafana dashboard shows live CPU and memory. Run
yes > /dev/nullon a VM and watch the CPU line rise.
Practise safely
- Keep Grafana and Prometheus on localhost or an internal lab network; they expose detailed information about your systems and have no protection by default.
- Change default passwords, and never expose these ports to the internet.
- Metrics can be large; set a retention limit (
--storage.tsdb.retention.time=7d) so a lab does not fill the disk. - Practise backups on test data: back up a folder with
tarorrsync, delete the original, restore it and check it matches. A backup you have never restored is only a hope.
Go further
- Write an alert rule such as “memory available is under 10 percent for 5 minutes”, trigger it by using memory, and confirm it fires and then clears.
- Add a service check (for example blackbox_exporter probing a web page) and alert when the page is down.
- Define a simple service level objective (for instance 99 percent of requests under 300 ms) and chart it.
- Test a complete recovery: restore a database or folder from backup onto a fresh VM and time it.
- Compare what the dashboards show with what the logs show when something breaks.
Courses that use this lab
Other lab guides
- A virtual machine lab on your own computer
- A Linux practice machine
- A network lab with free simulators and virtual routers
- A packet-capture lab with Wireshark and tcpdump
- A network-services lab: DHCP, DNS, proxy, load balancer, time and failover
- A Windows Server and Active Directory lab
- A developer workstation: editor, Git, Python and Node
- A container and Kubernetes lab
- A security operations (SOC) practice lab
- An isolated security lab for authorised practice
- A cloud lab that cannot surprise you with a bill
- An embedded and microcontroller lab: simulators first, hardware second
- An electronics lab: simulate first, then build on a breadboard
- A Raspberry Pi lab, with or without a Pi
- A home automation lab with Home Assistant and MQTT
- An audio, video, streaming and show-control lab
- A data lab: Python, pandas and Jupyter on your own computer
- A machine learning lab: scikit-learn, notebooks and honest experiments
- An LLM lab: a free local model, embeddings and a test harness
- A TypeScript lab: Node.js, the compiler and a test runner
- A web deployment lab: Git, a free host and environment settings
Software changes quickly. Menu names and version numbers may differ a little from what you see; the ideas and the check at the end of each section stay the same. Always download from the project's own website, and read the licence terms for your situation.