Add prometheus metric requests_total with headers

Co-authored-by: Julien Salleyron <julien.salleyron@gmail.com>
This commit is contained in:
Romain 2023-03-20 18:06:07 +01:00 committed by GitHub
parent 4bc2305ed3
commit c823879097
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 295 additions and 90 deletions

View file

@ -165,3 +165,66 @@ metrics:
```bash tab="CLI"
--metrics.prometheus.manualrouting=true
```
#### `headerLabels`
_Optional_
Defines the extra labels for the `requests_total` metrics, and for each of them, the request header containing the value for this label.
Please note that if the header is not present in the request it will be added nonetheless with an empty value.
In addition, the label should be a valid label name for Prometheus metrics,
otherwise, the Prometheus metrics provider will fail to serve any Traefik-related metric.
```yaml tab="File (YAML)"
metrics:
prometheus:
headerLabels:
label: headerKey
```
```toml tab="File (TOML)"
[metrics]
[metrics.prometheus]
[metrics.prometheus.headerLabels]
label = "headerKey"
```
```bash tab="CLI"
--metrics.prometheus.headerlabels.label=headerKey
```
##### Example
Here is an example of the entryPoint `requests_total` metric with an additional "useragent" label.
When configuring the label in Static Configuration:
```yaml tab="File (YAML)"
metrics:
prometheus:
headerLabels:
useragent: User-Agent
```
```toml tab="File (TOML)"
[metrics]
[metrics.prometheus]
[metrics.prometheus.headerLabels]
useragent = "User-Agent"
```
```bash tab="CLI"
--metrics.prometheus.headerlabels.useragent=User-Agent
```
And performing a request with a custom User-Agent:
```bash
curl -H "User-Agent: foobar" http://localhost
```
The following metric is produced :
```bash
traefik_entrypoint_requests_total{code="200",entrypoint="web",method="GET",protocol="http",useragent="foobar"} 1
```

View file

@ -354,6 +354,9 @@ Buckets for latency metrics. (Default: ```0.100000, 0.300000, 1.200000, 5.000000
`--metrics.prometheus.entrypoint`:
EntryPoint (Default: ```traefik```)
`--metrics.prometheus.headerlabels.<name>`:
Defines the extra labels for the requests_total metrics, and for each of them, the request header containing the value for this label.
`--metrics.prometheus.manualrouting`:
Manual routing (Default: ```false```)

View file

@ -354,6 +354,9 @@ Buckets for latency metrics. (Default: ```0.100000, 0.300000, 1.200000, 5.000000
`TRAEFIK_METRICS_PROMETHEUS_ENTRYPOINT`:
EntryPoint (Default: ```traefik```)
`TRAEFIK_METRICS_PROMETHEUS_HEADERLABELS_<NAME>`:
Defines the extra labels for the requests_total metrics, and for each of them, the request header containing the value for this label.
`TRAEFIK_METRICS_PROMETHEUS_MANUALROUTING`:
Manual routing (Default: ```false```)

View file

@ -272,6 +272,9 @@
addServicesLabels = true
entryPoint = "foobar"
manualRouting = true
[metrics.prometheus.headerLabels]
label1 = "foobar"
label2 = "foobar"
[metrics.datadog]
address = "foobar"
pushInterval = "42s"

View file

@ -298,6 +298,9 @@ metrics:
addServicesLabels: true
entryPoint: foobar
manualRouting: true
headerLabels:
label1: foobar
label2: foobar
datadog:
address: foobar
pushInterval: 42s