Prometheus setting scrape_interval specific to target in http_sd_config

Viewed 422

I'm using Prometheus http service discovery to add targets dynamically, But it looks like I can only add labels and targets URLs <static_config>. I would like to know is there any way to specify scrape_interval for each target?

I can do that if I add targets manually to the Prometheus config file as below.

global:
  scrape_interval:     15s # By default, scrape targets every 15 seconds.

  scrape_configs:
  - job_name: 'target-1'
    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'target-2'
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:1010']
1 Answers

I got the answer from the Prometheus GitHub discussion.

With http_sd_config you can set scrape interval for each target:

[
    {
        "targets": ["10.0.40.3:9100"],
        "labels": {
            "__meta_datacenter": "london",
            "__scrape_interval__": "1m",
            "__scrape_timeout__": "5m"
        }
    },
    {
        "targets": ["10.0.40.1:9100"],
        "labels": {
            "__meta_datacenter": "london",
            "__scrape_interval__": "1m",
            "__scrape_timeout__": "5m"
        }
    }
]

But also be careful that these labels are experimental and subject to change in a future release.

From Prometheus documentation.

The scrape_interval and scrape_timeout labels are set to the target's interval and timeout. This is experimental and could change in the future.

Related