Prometheus Configuration Basics
What you'll learn: How to configure Prometheus to collect metrics from your services using the prometheus.yml configuration file.
Prometheus uses a single YAML configuration file—typically named prometheus.yml—to define what to monitor, how often to collect metrics, and where to find targets. This file is the control panel for your entire monitoring operation.
Core Configuration Structure
The configuration file has several key sections:
Global settings define defaults that apply to all scrape jobs:
global:
scrape_interval: 15s # How often to collect metrics
evaluation_interval: 15s # How often to evaluate rules
external_labels:
cluster: 'production' # Labels attached to all time series
Scrape configs define individual monitoring jobs and their targets:
scrape_configs:
- job_name: 'my-app'
scrape_interval: 10s # Override global setting
static_configs:
- targets: ['localhost:8080', 'localhost:8081']
labels:
env: 'prod'
Think of It This Way
Imagine Prometheus as a newspaper reporter with a beat. The global section sets their daily routine (visit sources every 15 minutes). Each scrape_config is a specific source—a city hall, police station, or school board. The targets are the exact addresses, and labels are tags to categorize the stories.
Key Elements
scrape_interval: Frequency of metric collection (per-job overrides global)targets: List ofhost:portendpoints exposing metricsjob_name: Logical grouping automatically added as a labellabels: Custom dimensions attached to all metrics from these targets
Key Takeaway: The prometheus.yml file controls all monitoring behavior through global defaults and per-job scrape configurations, defining targets, intervals, and labels that structure your entire metrics collection strategy.