Monitoring Setup¶
Prerequisites¶
- Docker and Docker Compose installed and running (lab 09/10)
- Inventory API running in Docker Compose at
/home/centos/lab10/docker-compose.yml
Procedure: Configure Inventory API Tracing¶
When to use: The inventory API source has been updated with OpenTelemetry instrumentation. Configure and deploy the new version so traces appear in the central Jaeger instance.
Steps:
-
Pull the latest inventory API source and rebuild the Docker image:
sudo docker build -t inventory-api:lab11 . -
Update the
inventoryservice in/home/centos/lab10/docker-compose.yml— use the new image tag and add three environment variables:Replaceinventory: image: inventory-api:lab11 environment: - OTEL_EXPORTER_OTLP_ENDPOINT=https://jaeger.sysadm.ee - OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf - OTEL_SERVICE_NAME=inventory.<vm_name>.sysadm.ee<vm_name>with your VM's short hostname. -
Restart the inventory service:
cd /home/centos/lab10 sudo docker compose up -d --force-recreate inventory -
Send a test request to generate a trace:
curl -H "Authorization: Bearer 845e6732f32b81dd778972703474ccbb" \ http://inventory.<vm_name>.sysadm.ee/api/v1/inventory
Troubleshooting:
- Service not in Jaeger after 5–10 seconds: check container logs for OTLP exporter errors (
sudo docker compose logs inventory). Ensure all three env vars are set andOTEL_EXPORTER_OTLP_PROTOCOLishttp/protobuf.
Procedure: Deploy Prometheus and node_exporter¶
When to use: Collecting host metrics with Prometheus scraping node_exporter.
Steps:
-
Create
prometheus.ymlin your chosen working directory:global: scrape_interval: 15s scrape_configs: - job_name: 'node-exporter' static_configs: - targets: ['node-exporter:9100'] -
Add node-exporter and prometheus services to a
docker-compose.yml(see Technologies: Prometheus for the full service definitions). -
Add a
prometheus-datavolume entry to the top-levelvolumes:section. -
Start the services:
sudo docker compose up -d node-exporter prometheus -
Open firewall ports:
sudo firewall-cmd --permanent --add-port=9100/tcp sudo firewall-cmd --permanent --add-port=9090/tcp sudo firewall-cmd --reload -
Verify node_exporter is working:
curl http://localhost:9100/metrics | head -5 -
Verify Prometheus is healthy and scraping:
Browse tocurl http://localhost:9090/-/healthy curl http://localhost:9090/api/v1/targetshttp://<vm-ip>:9090→ Status → Targets to confirm the node-exporter job isUP.
Troubleshooting:
- node-exporter target
DOWN: wait 15 seconds for the first scrape, then checkprometheus.ymlspelling. - Port not accessible: verify firewall rules and that ports are bound (
ss -tlnp | grep 909).
Procedure: Deploy Loki and Promtail¶
When to use: Centralizing system logs with Loki and Promtail.
Steps:
-
Create
loki-config.yamlandpromtail-config.yaml(see Technologies: Loki and Technologies: Promtail for the full configs). -
Add loki and promtail services to
docker-compose.yml. Add aloki-datavolume entry. -
Start the services:
sudo docker compose up -d loki promtail -
Open the Loki firewall port:
sudo firewall-cmd --permanent --add-port=3100/tcp sudo firewall-cmd --reload -
Wait 30–60 seconds, then verify Loki is ready:
curl http://localhost:3100/ready -
Verify Promtail has shipped logs:
curl 'http://localhost:3100/loki/api/v1/query?query={job="varlogs"}&limit=5'
Troubleshooting:
- Loki not ready: check logs with
sudo docker compose logs loki. First start takes 30–60 s. - No logs in Loki: check
/var/log/messagesexists (ls /var/log/messages) and Promtail can reach Loki.
Procedure: Deploy Grafana and Connect Data Sources¶
When to use: Adding dashboards to visualize Prometheus metrics and Loki logs.
Steps:
-
Add the grafana service to
docker-compose.ymlwith agrafana-datavolume, binding the port to127.0.0.1:3000:3000. -
Start Grafana:
sudo docker compose up -d grafana -
Add a
grafanaDNS record in your zone file and reload Knot DNS (see Technologies: Grafana for the full DNS, Apache vhost, and reload steps). -
Browse to
https://grafana.<vm_name>.sysadm.eeand log in (admin/admin). -
Add Prometheus data source:
- Connections → Data Sources → Add new data source → Prometheus
- URL:
http://prometheus:9090 - Click Save & Test
-
Import the Node Exporter dashboard:
- Dashboards → New → Import
- Dashboard ID:
1860 - Select the Prometheus data source → Import
-
Add Loki data source:
- Connections → Data Sources → Add new data source → Loki
- URL:
http://loki:3100 - Click Save & Test
-
Import the Loki logs dashboard:
- Dashboard ID:
13639→ Select the Loki data source → Import
- Dashboard ID:
Troubleshooting:
Bad Gatewayon data source test: Grafana cannot reach Prometheus/Loki. Verify they are in the same Docker network (samedocker-compose.ymlor same network name).- Dashboard shows no data: data source test must succeed first.
Quick Reference¶
| Action | Command |
|---|---|
| Start all monitoring services | sudo docker compose up -d |
| Check all containers | sudo docker compose ps |
| View any service logs | sudo docker compose logs <service> |
| Check Prometheus targets | curl http://localhost:9090/api/v1/targets |
| Check Loki ready | curl http://localhost:3100/ready |
| Check Grafana health | curl -sk https://grafana.<vm_name>.sysadm.ee/api/health |
Related Documentation¶
- Concepts: Monitoring
- Technologies: Prometheus, Grafana, Loki, Promtail, Jaeger