Prometheus Dynamic Configuration target
(Jin Qing's column 2018.4)
The simplest configuration is a static target:
Scrape_configs:
-job_name: ' Prometheus '
static_configs:
-Targets: [' localhost:9090 ', ' localhost:9100 ' ]
Labels:
group: ' Prometheus '
After you change this file, you can send a SIGHUP trigger configuration reload.
Prometheus provides a service discovery feature that can discover new targets from a variety of sources, from Consul, DNS, kubernetes, file, and so on.
The simplest of these is the file Discovery service.
For example, the/ROOT/PROMETHEUS/PROMETHEUS.YML configuration is as follows:
Global:
scrape_interval:15s
evaluation_interval:15s
scrape_configs:
-job_name: ' Prometheus '
static_configs:
-Targets: [' 127.0.0.1:9090 ', ' 127.0.0.1:9100 ']
Labels:
group: ' Prometheus '
-job_name: ' Test '
file_sd_configs:
-Files: ['/etc/prometheus/test_sd_config/*.yml ']
Refresh _interval:5s
Start Prometheus with Docker:
Docker run-d--net=host \
-v/root/prometheus:/etc/prometheus \
--name prometheus-server \
prom/ Prometheus
Create/root/prometheus/test_sd_config/test.yml as follows
-Targets: ["192.168.93.192:8080"]
Labels:
group: "My_test_group"
The test.yml is automatically read within 5s and the new target is added.
Open the Prometheus 9090 port using the browser,
Check the Status of Configuration, Targets, Service Discovery,
You can see the newly added target.