prometheus

prometheus rest api to update scrape config


Is there any REST Post/PUT/other API to add below to prometheus scrape config?

- job_name: 'My Service'
  metrics_path: '/actuator/prometheus'
  static_configs:
    - targets:
      - '10.252.1.2:61'
      labels:
        role: 'mysvc'

Solution

  • No such API provided by Prometheus since it is a core Prometheus server config file. I can suggest following options based on my experience and you can see which one works best for you ->

    1. Use Ansible to remotely manage the prometheus config file
    2. Create an RPM for configs e.g. prometheus.yaml and other config files like rules and alerts
    3. You can create a simple python based service running as a sidecar to create/update the prometheus yaml on that server. Python has yaml processing package which can be used to easily modify the yaml files. Not the easiest option but doable if you really need this.

    Hope this helps!