Following on from my previous post about Homer Service Discovery, I wrote a tool to automate generating targets for Prometheus from Traefik. The need idea was the same: adding, changing or removing a self-hosted service also required updating my blackbox exporter config to monitor the new service.
The application is written in Golang and is free and open-source including the CI and release process on GitHub Actions.
I made it available for all operating systems and architectures that Prometheus does to support all users. It is available as static binary files on the GitHub release page or Docker images on GitHub's Container registry using goreleaser.
More information, including how to use it, can be found on the project's README file.
Prometheus offers a variety of service discovery options for discovering scrape targets. When something doesn't exist, they recommend using file-based service discovery, by generating the files yourself.
The application connects to Traefik's API and gets all HTTP routes rules configured. It places these rules into JSON files within a folder that Prometheus watches for changes. When a file is added, Prometheus reads the file for new scrape targets. When a file is deleted, Prometheus will stop scraping the target.
I also added a 'grace period' before a target file is deleted. This is in case a service isn't working as expected and needs to be alerted on.