Since prometheus version 2.28, Prometheus provides a generic HTTP Service discovery. We recommend to use prometheus native http_sd feature.
https://prometheus.io/docs/prometheus/latest/configuration/configuration/#http_sd_config
Prometheus service discovery using with HTTP API and file_sd_config
.
Download from https://github.com/rrreeeyyy/prometheus-http-sd
docker pull rrreeeyyy/prometheus-http-sd
-
Run a single API endpoint
./prometheus-http-sd --api.url="http://api.example.com/service_discovery.json" --output.file=/path/to/http_sd.json --refresh.interval=60
-
Run multiple API endpoints
./prometheus-http-sd --api.url="http://api.example.com/foo_service_discovery.json" --output.file=/path/to/http_foo_sd.json --api.url="http://api.example.com/bar_service_discovery.json" --output.file=/path/to/http_bar_sd.json --refresh.interval=60
HTTP API response should be follow prometheus file_sd_config
format like below:
[
{
"targets": [
"192.0.2.1:8080",
"192.0.2.2:8080",
],
"labels": {
"service": "web",
"role": "role-1"
}
},
{
"targets": [
"192.0.3.1:3306"
],
"labels": {
"service": "db",
"role": "role-2"
}
}
]
The part of your prometheus.yml
is probably as follows.
scrape_configs:
- job_name: 'http_sd'
file_sd_configs:
- files:
- /path/to/http_sd.json
prometheus_sd_http_http_requests_total
- labels
api_url
: target API URLcode
: http response code
- labels