Every instance of my application has a different URL. How can I configure prometheus.yml so that it takes path of a target along with the host name?
scrape_configs:
- job_name: 'example-random'
# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 5s
static_configs:
- targets: ['localhost:8090','localhost:8080']
labels:
group: 'dummy'
global: scrape_interval: 15s # By default, scrape targets every 15seconds.
You currently can't configure the metrics_path per target within a job but you can create separate jobs for each of your targets so you can define metrics_path per target.
In this case the global setting is to scrape every 15 seconds. The evaluation_interval option controls how often Prometheus will evaluate rules. Prometheus uses rules to create new time series and to generate alerts. The rule_files block specifies the location of any rules we want the Prometheus server to load.
Prometheus collects metrics from targets by scraping metrics HTTP endpoints. Since Prometheus exposes data in the same manner about itself, it can also scrape and monitor its own health.
You currently can't configure the metrics_path
per target within a job but you can create separate jobs for each of your targets so you can define metrics_path
per target.
Your config file would look something like this:
scrape_configs:
- job_name: 'example-target-1'
scrape_interval: 5s
metrics_path: /target-1-path-to-metrics
static_configs:
- targets: ['localhost:8090']
labels:
group: 'dummy'
- job_name: 'example-target-2'
scrape_interval: 5s
metrics_path: /totally-different-path-for-target-2
static_configs:
- targets: ['localhost:8080']
labels:
group: 'dummy-2'
I achieved this by using file_sd_config option. All targets are described in separate file(s), which can be either in YML or JSON format.
prometheus.yml:
scrape_configs:
- job_name: 'dummy' # This will be overridden in targets.yml
file_sd_configs:
- files:
- targets.yml
targets.yml:
- targets: ['host1:9999']
labels:
job: my_job
__metrics_path__: /path1
- targets: ['host2:9999']
labels:
job: my_job # can belong to the same job
__metrics_path__: /path2
I believe you need to do some relabelling of the __metrics_path__
label set to include the varying paths of your applications.
The Prometheus configuration docs will prove useful to you here and this article should help you understand relabelling a little better.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With