Skip to content
Advertisement

Add Targets to Blackbox Exporter programmatically via API (Prometheus) [closed]

How can I add targets to blackbox exporter via an api or something similar?

Background
I created a small front end for status monitoring of websites, I am utilizing the blackbox exporter and created a simple interface for adding and removing targets (Bootstrap front, PHP backend). I couldn’t find a programmatic way to manage targets so I’m add just editing the text and manually reloading the config via curl.

This works but is inconsistent, and restarts my probe times so it takes some time before I see the change. Wondering if anyone has experience doing it a better way?

Advertisement

Answer

Welcome to StackOverflow.

The usual way to do this is to use the FileSD. This allows you to point to a directory or file which Prometheus will watch for changes.

The Workflow would be:

  1. User changes Target
  2. Your backend writes the target file in JSON format in the directory.
  3. Prometheus picks up the changes and configures itself on the fly.
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement