Use a different Prometheus scrape URL for each target
Configure target labels, paths, schemes, and query parameters with separate jobs or target relabeling.
Prometheus target groups can have different labels, but metrics_path, scheme, and params are configured at the scrape-job level. For different URLs, either create separate jobs or use target relabeling to set the internal URL labels.
Give target groups different labels
scrape_configs:
- job_name: my-app
metrics_path: /metrics
static_configs:
- targets: ['server1:9090']
labels: {env: prod, team: order}
- targets: ['server2:9090']
labels: {env: staging, team: order}
Both targets use HTTP and /metrics, but their exported series receive different env labels. Putting metrics_path directly inside one of these static_configs groups is not valid.
Change the path, scheme, or parameter per target
For a few endpoints, separate jobs are often easiest to read. For many targets, keep one job and rewrite the internal labels:
scrape_configs:
- job_name: varied-endpoints
metrics_path: /metrics
params:
format: [prometheus]
static_configs:
- targets: ['server1:9090', 'server2:9443']
relabel_configs:
- source_labels: [__address__]
regex: 'server1:.*'
target_label: __metrics_path__
replacement: /custom/metrics
- source_labels: [__address__]
regex: 'server2:9443'
target_label: __scheme__
replacement: https
- source_labels: [__address__]
regex: 'server2:9443'
target_label: __param_format
replacement: openmetrics
Here, server1 uses /custom/metrics?format=prometheus; server2 uses HTTPS with /metrics?format=openmetrics. The target must actually support the selected format, path, and protocol. Configure appropriate certificate trust for the HTTPS target.
__metrics_path__, __scheme__, and __param_<name> control the scrape request. Target relabeling can change the first value of a named URL parameter; use separate jobs when you need different multi-valued parameter lists or different HTTP authentication/TLS settings.
Maintain a larger inventory with file discovery
file_sd_configs reads JSON or YAML target-group files. Those groups can contain addresses and labels that relabeling uses to construct the URL. Prometheus detects target-file changes without a process restart. Editing the scrape-job configuration itself still requires a configuration reload.
Inspect the resulting endpoint in the Targets page and validate the configuration with the promtool version matching your server before reloading it.
Common questions
Will internal labels appear on stored samples? Labels beginning with __ are removed after target relabeling. Copy information you need for queries into ordinary labels, keeping cardinality under control.
Must different query parameters use different jobs? No. __param_<name> can override a target's parameter value. Separate jobs remain useful when settings cannot be represented safely by target relabeling.
References
Contact us
Join the community
to join the community
Try Guance
Start online and pay only for what you use.
Get startedChoose a Guance plan