📊
Monitoring & Observability

Prometheus

Open-source monitoring and alerting toolkit with time-series database

🐧 Linux🍎 Mac🪟 Windows📋 Quick reference →
Reviewed: Tested on: Kubernetes 1.29 · Terraform 1.8 · Ubuntu 22.04

What is this?

Prometheus collects numbers about your servers — CPU, memory, disk — and stores them over time.

📁

Config files for Prometheus

Where to create or edit the main configuration — paths below match the setup steps.

  • prometheus.yml

    Location: Server or container mount /etc/prometheus/

    Scrape targets, rules, and alerting

📥

Step 01

Install Prometheus

(01)Run with Docker

Linux
1docker run -d --name prometheus -p 9090:9090 \
2 -v ./prometheus.yml:/etc/prometheus/prometheus.yml \
3 prom/prometheus
4# UI: http://localhost:9090

(02)Install binary (Linux)

Linux
1wget https://github.com/prometheus/prometheus/releases/download/v2.54.0/prometheus-2.54.0.linux-amd64.tar.gz
2tar xvfz prometheus-*.tar.gz
3cd prometheus-*
4./prometheus --config.file=prometheus.yml
⚙️

Step 02

Configure Prometheus

(01)prometheus.yml scrape config

Linux
1cat > prometheus.yml << 'EOF'
2global:
3 scrape_interval: 15s
4scrape_configs:
5 - job_name: prometheus
6 static_configs:
7 - targets: ["localhost:9090"]
8 - job_name: node
9 static_configs:
10 - targets: ["localhost:9100"]
11 - job_name: kubernetes-pods
12 kubernetes_sd_configs:
13 - role: pod
14EOF
15
16docker restart prometheus

Step 03

Verify

(01)Check targets

Linux
1curl http://localhost:9090/-/healthy

Step 04

Query & Monitor

(01)PromQL examples

Linux
1# Via UI at http://localhost:9090/graph
2# up — target health
3# rate(http_requests_total[5m]) — request rate
4# node_memory_MemAvailable_bytes — memory

📋Config templates

1 YAML template for Prometheus. Copy and deploy after setup.

1 ready-to-copy template. Expand one, copy the YAML, then run the deploy commands.

docker-compose.yml

yaml
1services:
2 prometheus:
3 image: prom/prometheus:latest
4 ports:
5 - "9090:9090"
6 volumes:
7 - ./prometheus.yml:/etc/prometheus/prometheus.yml
8 - prom_data:/prometheus
9
10 grafana:
11 image: grafana/grafana:latest
12 ports:
13 - "3000:3000"
14 environment:
15 GF_SECURITY_ADMIN_PASSWORD: admin
16 volumes:
17 - grafana_data:/var/lib/grafana
18 depends_on:
19 - prometheus
20
21volumes:
22 prom_data:
23 grafana_data:

prometheus.yml

yaml
1global:
2 scrape_interval: 15s
3
4scrape_configs:
5 - job_name: prometheus
6 static_configs:
7 - targets: ["localhost:9090"]
📄

Step 01

Run Prometheus + Grafana

(01)Start stack

Linux
1docker compose up -d --build
2docker compose ps
3docker compose logs -f

(02)Stop

Linux
1docker compose down