2

I have a prometheus.yml config file that monitors a cluster of servers. The config file looks something like this:

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

    scrape_configs:

      - job_name: 'prometheus'
        scrape_interval: 5s
        scrape_timeout: 5s
        static_configs:
          - targets: ['localhost:9090']

      - job_name: minio
        metrics_path: /minio/prometheus/metrics
        scheme: http
        static_configs:
          - targets: [ "server-01.example.com:9000", "server-02.example.com:9000", "server-03.example.com:9000", "server-04.example.com:9000" ]
# Upto 32 such servers in the cluster server-{01..32}.example.com:9000

I hate to specify each target in the config file. Is there a way we can write a regex for the targets, something like server-{01..32}.example.com:9000 instead of specifying each server in the list. I tried different ways to do it, but none worked for me.

Aditya Pednekar
  • 442
  • 2
  • 6
  • 19
  • What you are trying to do is templating. Do you have a service discovery service or do you use a deployment framework ? – Michael Doubez May 30 '19 at 11:00
  • Nope I don't use any kind of service discovery or deployment framework. In my setup each minio server runs as a binary/service and knows about the other servers in the cluster through a flagged argument passed on to the binary. Can't we use regex's for specifying scrape targets (or do templating ) without relying on any discovery services or deployment frameworks? – Aditya Pednekar May 30 '19 at 12:01
  • No but you can use a contemplating tool to generate prometheus' configuration (by ex Jinja) – Michael Doubez May 30 '19 at 20:14
  • I wish I can config with that regex pattern: `["server{001-199}.example.com:9100"]` But not find any valid config until now. – kholis Aug 09 '22 at 07:17

0 Answers0