Self-Hosting Prometheus: Metrics Collection for Everything
Prometheus scrapes and stores metrics from your apps and infrastructure. The foundation of modern monitoring stacks.
What Is Prometheus?
Prometheus is a time-series database designed for monitoring. It scrapes metrics from targets at regular intervals, stores them, and lets you query and alert on them.
How It Works
Pull Model
Prometheus pulls metrics from your applications. Each app exposes a /metrics endpoint. Prometheus scrapes it every 15 seconds.
This is different from push-based systems where apps send metrics to a collector.
Metrics Format
Plain text, human-readable:
http_requests_total{method="GET", status="200"} 12345
http_request_duration_seconds{quantile="0.95"} 0.25
process_cpu_seconds_total 456.78
PromQL
Prometheus's query language:
What to Monitor
Node Exporter (Server Metrics)
cAdvisor (Container Metrics)
Application Metrics
Most frameworks have Prometheus client libraries:
Database Metrics
Alerting
Prometheus includes Alertmanager for alerting on metrics:
expr: node_cpu_seconds_total > 0.8
for: 5m
labels:
severity: warning
annotations:
summary: CPU usage above 80% for 5 minutes
Alertmanager routes alerts to Slack, email, PagerDuty, etc.
Deployment
1. Deploy Prometheus on TinyPod
2. Configure scrape targets (node_exporter, cAdvisor, app metrics)
3. Connect Grafana to Prometheus
4. Import dashboards
5. Set up alerting rules
Resources: 1 CPU, 1 GB RAM for small setups. Scales with number of metrics.
Retention
Default: 15 days. For long-term storage, use Thanos or VictoriaMetrics as a Prometheus backend.