Running Prometheus

All Topics

The Configuration File

Prometheus scrape_configs

Prometheus is configured using a YAML file, typically named prometheus.yml. This file defines what Prometheus monitors, how often it collects metrics, and how alerts are handled.

Key Sections

global — Defines default settings applied across all jobs, such as:

  • scrape_interval (how often Prometheus pulls metrics)
  • evaluation_interval (how often alerting rules are evaluated)

scrape_configs — Defines the list of targets Prometheus will monitor. Each job specifies:

  • A job name
  • The target endpoints
  • Optional labels or custom intervals

rule_files — Points to files containing alerting and recording rules.

alerting — Configures how Prometheus communicates with Alertmanager.

Reloading Configuration

After modifying prometheus.yml, Prometheus must reload the configuration. You can do this by:

  • Sending a SIGHUP signal to the Prometheus process
  • Sending an HTTP POST request to http://localhost:9090/-/reload (only works if --web.enable-lifecycle is enabled)

Example Configuration File

# Global configuration
global:
  scrape_interval: 15s        # How often to scrape targets
  evaluation_interval: 15s    # How often to evaluate rules

# Rule files (alerting/recording rules)
rule_files:
  - "rules.yml"               # File containing alert rules

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
            - "localhost:9093"  # Alertmanager address

# Scrape configuration
scrape_configs:

  # Monitor Prometheus itself
  - job_name: "prometheus"
    static_configs:
      - targets: ["localhost:9090"]

  # Example application job
  - job_name: "my-app"
    scrape_interval: 10s        # Override default interval
    static_configs:
      - targets: ["localhost:8080"]  # App exposing /metrics

This is a minimal but realistic configuration that scrapes Prometheus itself, scrapes a sample application, connects to Alertmanager, and loads alerting rules.