Skip to main content

Configuring Scrape Jobs

1. Defining Static Targets

Property Description Example
job_name Unique identifier for the scrape job node_exporter
static_configs List of static targets to scrape
[
  {
    "targets": ["localhost:9100", "server2:9100"]
  }
]
scrape_interval How often to scrape targets (default: 15s) 30s
scrape_timeout Timeout for individual scrape requests (default: 10s) 5s

Example: Basic Static Target Configuration

scrape_configs:
  - job_name: "node_exporter"
    static_configs:
      - targets: ["localhost:9100", "server2:9100"]
        labels:
          env: "production"

2. Setting Job-Specific Scrape Interval

Property Values Description
scrape_interval 15s How frequently to scrape targets. Default is 15 seconds.
scrape_timeout 10s Timeout for scraping a single target. Default is 10 seconds.

Example: Configuring scrape interval for a job

scrape_configs:
  - job_name: "prometheus"
    scrape_interval: 30s
    static_configs:
      - targets: [localhost:9090]
Note: The scrape_interval setting in a job overrides the global default scrape interval.

3. Configuring Metrics Path

Field Description Default Example
metrics_path Path to scrape metrics from /metrics /app/metrics
scheme Protocol to use for scraping (http or https) http https
port Port to scrape metrics from 9090 8080

Example: Configuring Metrics Path

scrape_configs:
  - job_name: "myapp"
    metrics_path: /app/metrics
    scheme: https
    static_configs:
      - targets: ["localhost:8080"]

4. Setting Scrape Scheme

Property Values Description
scheme http, https Specifies the URL scheme to use when scraping targets. Defaults to http.

Example: Configuring HTTP Scrape Scheme

scrape_configs:
  - job_name: "prometheus"
    scheme: http
    static_configs:
      - targets: ['localhost:9090']

Example: Configuring HTTPS Scrape Scheme

scrape_configs:
  - job_name: "secure-metrics"
    scheme: https
    static_configs:
      - targets: ['secure.example.com:8443']

5. Adding Job Labels

Label Name Value Description
job_name prometheus Unique identifier for the scrape job
scrape_interval 15s How frequently to scrape targets
scrape_timeout 10s Timeout for individual scrape requests
metrics_path /metrics Path to scrape metrics from
honor_labels false Whether to honor labels from scraped targets
relabel_configs [] Relabeling rules to apply before scraping

Example: Adding Job Labels

scrape_configs:
  - job_name: "prometheus"
    static_configs:
      - targets: ["localhost:9090"]
    metrics_path: /metrics
    scrape_interval: 15s
    scrape_timeout: 10s
    honor_labels: false
    relabel_configs:
      - source_labels: [__address__]
        target_label: job

6. Setting Scrape Timeout

Property Values Description
scrape_timeout 10s Timeout for scraping targets. Default is 10 seconds.
scrape_timeout 30s NEW in Prometheus v2.30+

Example: Configuring Scrape Timeout

scrape_configs:
  - job_name: "prometheus"
    scrape_timeout: 15s
    static_configs:
      - targets: ['localhost:9090']

7. Enabling Sample Limit

Option Values Notes
scrape.sample_limit 0 Maximum number of samples to scrape per job. 0 = no limit
scrape.max_samples_per_scrape 100000 Maximum number of samples to scrape per job. Default is 100k

Example: Configuring Sample Limit in Prometheus Configuration

scrape_configs:
  - job_name: "prometheus"
    static_configs:
      - targets: [localhost:9090]
    scrape_interval: 15s
    sample_limit: 10000
Note: Setting sample_limit helps prevent resource exhaustion from scraping too many samples. It's particularly useful when scraping metrics from services that may generate a large number of time series.

8. Configuring Label Limits

Option Values Notes
scrape_config.sample_limit 1000 Maximum number of samples per scrape
scrape_config.label_limit 100 Maximum number of labels per sample
scrape_config.label_name_length_limit 1024 Maximum length of label names in bytes
scrape_config.label_value_length_limit 2048 Maximum length of label values in bytes

Example: Setting Label Limits in Configuration

scrape_configs:
  - job_name: "prometheus"
    static_configs:
      - targets: ["localhost:9090"]
    label_limit: 150
    label_name_length_limit: 1200
    label_value_length_limit: 2500
Note: These limits help prevent resource exhaustion from overly large metrics. Adjust based on your system's capacity and typical metric sizes.

9. Using Params for Scraping

Parameter Description Example
params Query parameters to append to the scrape URL
params:
  format: prometheus
  extra: value

Example: Configuring params in scrape job

scrape_configs:
  - job_name: "prometheus"
    static_configs:
      - targets: ["localhost:9090"]
    params:
      format: prometheus
      extra: value

10. Configuring Honor Labels

Option Values Description
honor_labels true | false If true, Prometheus will use the label values from the scraped target instead of the ones provided by the scrape job. Default is false.

Example: Configuring honor_labels

scrape_configs:
  - job_name: "prometheus"
    honor_labels: true
    static_configs:
      - targets: ["localhost:9090"]
Note: When honor_labels is set to true, any labels present in the scraped metrics will override the ones defined in the scrape configuration.

11. Configuring Honor Timestamps

Option Values Description
honor_timestamps true | false When set to false, Prometheus will ignore the timestamps provided by the target and use the scrape time instead. When set to true, Prometheus will honor the timestamps provided by the target.

Example: Setting honor_timestamps to false

scrape_configs:
  - job_name: "example"
    honor_timestamps: false
    static_configs:
      - targets: ["localhost:9090"]
Note: Setting honor_timestamps to false can be useful when scraping metrics from a source that provides inaccurate timestamps or when you want to align all metrics with the scrape time.

12. Setting Body Size Limit

Configuration Option Description Default Value Notes
scrape.body-size-limit Maximum size of the response body that Prometheus will accept from a scrape target. 0 Set to 0 to disable the limit. A value of 10MB is recommended for large payloads.

Example: Configuring Body Size Limit

scrape_configs:
  - job_name: "example"
    scrape_interval: 15s
    static_configs:
      - targets: [ "localhost:9090" ]
    body_size_limit: 10MiB

Was this article helpful?