I have an application that has two instances running and each request runs on a different machine.

I am monitoring an event with a counter in my application and each instance runs it's own counter using prometheus-net. It would be great if prometheus-net was using a caching mechanism other that in-memory, maybe a redis, so whenever prometheus scrap /metrics, it gets the same data each time.

Unfortunately, each scrap request from prometheus runs on a different machine and it's like I have two counters.

I need a way to tell to prometheus to scrap two urls and I will find a way to combine them.

Unfortunately, the way to access directly the web app instance is by using parameters.

The urls looks like that:


That way I cannot use the following code since I cannot add full url here.

      - targets: ['example.com']

I tried the following but it didn't created two 'instances' at the label instance

- job_name: 'example'
    scrape_interval: 30s
      -instance: ['372c43937e6acd56073246ffdf0e95597480cdba24688cc331d77a8c3c07e1a9','be007691832f4002a86cf0148768a3b039304e9b1fa7ae91a032b0beddc152b2']
      - targets: ['example.com']
    metrics_path: /metrics
    scheme: https

1 Answer 1


You can do this similarly to how it's done in blackbox_exporter: list identifying information of your targets in the target block, and then use relabeling to replace scraping address with address of your actual exporter and to place targets into parameters of scraping request.

  - job_name: 'myjob'
      - targets:  # Targets to probe using parameters
        - 372c43937e6acd56073246ffdf0e95597480cdba24688cc331d77a8c3c07e1a9   
        - be007691832f4002a86cf0148768a3b039304e9b1fa7ae91a032b0beddc152b2
      - source_labels: [__address__]
        target_label: __param_instance
      - source_labels: [__param_instance]
        target_label: instance
      - target_label: __address__
        replacement: example.com  # The exporter's real address

please notice here: __param_instance is a label that will be used during scraping as URL parameter with name instance.

Here replacement config does:

  1. puts ids from target list into parameter instance,
  2. puts content of that parameter into final label instance (otherwise content of __address__ will be used),
  3. puts address of actual target into label __address__ to be used bu scraping.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.