This is a simple HTTP server that you can use to push targets to Prometheus. We can use this to dynamically update prometheus targets without knowing the targets in advance.
Send a POST request to /update with a JSON body containing a single target to add.
{
"name": "test",
"mac": "0a:0a:0a:0a:0a:0a",
"address": "123.45.67.240",
"labels": {
"__meta_prometheus_job": "barcode_readers",
}
}The MAC field can be an arbitrary ID to identify the target.
This is the endpoint for Prometheus http_sd_config. It will return a list of targets in the format that Prometheus expects.
Create Docker Container:
docker run -d -p 8000:8000 -e MAX_AGE=300 -e BASIC_AUTH_USER=user -e BASIC_AUTH_PASS=password --name prometheus-http-push-sd spencershepard/prometheus-http-push-sdUpdate prometheus.yml
scrape_configs:
- job_name: 'pushed_scrapes'
http_sd_configs:
- url: http://ipaddress:8000/targets
basic_auth:
username: username
password: password- 'MAX_AGE' - The maximum age of a target in seconds.
- 'BASIC_AUTH_USER' - The basic auth username to use.
- 'BASIC_AUTH_PASSWORD' - The basic auth password to use.