Everything else depends on targets being scraped correctly, and the configuration file is where that happens.
Prometheus is a single Go binary (or the prom/prometheus Docker image) configured by prometheus.yml. Its main sections:
global: defaults such asscrape_interval(the built-in default is 1m; 15s to 30s is common) andevaluation_intervalfor rules.scrape_configs: a list of jobs. Each has ajob_name, how to find targets (static_configs, or service discovery covered later) and options likemetrics_path(default/metrics),schemeandscrape_timeout.rule_filesandalerting: covered later.
Start it with prometheus --config.file=prometheus.yml and open http://localhost:9090. Status, Target health shows every target with its last scrape and error. For each target Prometheus records synthetic series:
up: 1 if the last scrape succeeded, 0 if it failed. The simplest and most important alert is onup == 0.scrape_duration_secondsandscrape_samples_scraped.
Validate configuration before applying it with promtool check config prometheus.yml. Prometheus reloads its configuration on SIGHUP or, if started with --web.enable-lifecycle, on POST /-/reload.
Storage is in ./data by default; set --storage.tsdb.path and --storage.tsdb.retention.time (default 15 days) for real deployments.
Example
# prometheus.yml
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: prometheus # Prometheus scrapes itself
static_configs:
- targets: ["localhost:9090"]
- job_name: api
metrics_path: /metrics
static_configs:
- targets: ["10.0.0.5:8000", "10.0.0.6:8000"]
labels:
env: prod # extra label on every series
# $ promtool check config prometheus.yml -> SUCCESS
# $ prometheus --config.file=prometheus.yml --storage.tsdb.retention.time=30d
# Query in the UI: up{job="api"} -> 1 per healthy target, 0 if downRemember
- scrape_configs lists jobs and their targets
- up is 1 for a successful scrape and 0 for a failed one
- Check config with promtool; reload with SIGHUP or /-/reload
Watch out for
- Forgetting that the default scrape_interval is 1m, then wondering why graphs look coarse.