Monitor Traefik v2 Ingress controller with Prometheus by host

Hi! I have a k3s cluster with Traefik v2 as Ingress Controller, I successfully configured Prometheus to scrape Traefik's metrics but the exported metrics are labeled by Ingress resource.

This is a problem because a single Ingress resource can be configured to serve multiple domains, and the name of an Ingress resource isn't ideal to categorize the requests.

As an example, in v1 I got metrics like:

traefik_backend_requests_total{backend="url.of.ingress.com", code="200", container="traefik", endpoint="...", instance="...", job="traefik-prometheus", method="DELETE", namespace="...", pod="...", protocol="http", service="traefik-prometheus"}

And from here I could filter/aggregate metrics in Grafana by host thanks to the backend field.

But in v2, there are no more backends and I get metrics like:

traefik_service_requests_total{code="200", container="traefik", endpoint="...", exported_service="name-of-ingress-resource-80@kubernetes", instance="...", job="traefik-metrics", method="GET", namespace="...", pod="...", protocol="http", service="traefik-metrics"}

That are not useful at all, since I cannot see the destination host, the only field useful for identification is exported_service but again, is no host.

Is there a way to export what I'm looking for?

1 Like

I would also like to be able to aggregate in grafana the metrics by the targeted url.
Is there any possibility?

When enabling routers label, you may have more information, depending of your dynamic configuration.

It's also possible with data in access.logs to aggregate per target url or path.