Traefik 4xx/5xx errors in Zabbix without Prometheus

Traefik 4xx/5xx errors in Zabbix without Prometheus

Table of Contents

Traefik sits in front of a lot of applications: as a Docker reverse proxy, as a Kubernetes ingress controller, or as an edge router on a single VM. That makes it the best place to see whether your applications are healthy from the user’s point of view — every failed request passes through it.

Traefik exposes detailed metrics in Prometheus format. The usual advice is “add Prometheus and Grafana”. But if your monitoring is Zabbix, running a second monitoring stack just to read one endpoint is overkill. Zabbix can parse Prometheus metrics itself.

Template: custom-zabbix-templates/traefik-metrics — Zabbix 6.4 and newer, no external scripts.

What you get

For every Traefik service (whoami@docker, api@internal, myapp-web@kubernetescrd, …) the template automatically creates:

Item Meaning
Service Requests Number of requests since the previous check
Service Requests – 4xx Errors Client errors (all 4xx codes summed)
Service Requests – 5xx Errors Server errors (all 5xx codes summed)
Service Response bytes Traffic sent to clients

Plus two trigger prototypes per service: more than N 4xx and more than N 5xx errors within 5 minutes.

New services are discovered automatically — deploy a container with Traefik labels and it appears in Zabbix without any configuration. Services that disappear are cleaned up automatically.

How it works

  1. A Zabbix agent item web.page.get[{$TRAEFIK.API}] fetches the metrics page.
  2. Preprocessing converts the Prometheus text (traefik_service_requests_total{service=…, code=…}) into JSON and a small JavaScript step groups status codes into 2xx/4xx/5xx per service.
  3. Low-level discovery creates items for each service; simple change preprocessing turns ever-growing counters into “requests since the last check”.

Everything happens inside Zabbix — no exporter, no cron job, no Python.

Setup

1. Enable Prometheus metrics in Traefik, ideally on a separate entry point that isn’t published to the internet:

# traefik.yml (static configuration)
entryPoints:
  metrics:
    address: "127.0.0.1:8082"

metrics:
  prometheus:
    entryPoint: metrics
    addServicesLabels: true

The same with CLI flags: --entryPoints.metrics.address=127.0.0.1:8082 --metrics.prometheus=true --metrics.prometheus.entryPoint=metrics --metrics.prometheus.addServicesLabels=true.

Check it: curl -s http://127.0.0.1:8082/metrics | grep traefik_service_requests_total.

2. Import the template in Zabbix (Data collection → Templates → Import) and link it to the host running Traefik. The host needs a Zabbix agent, because the metrics are fetched by the agent — which means the metrics port can stay bound to localhost.

3. Set the macros:

Macro Example Meaning
{$TRAEFIK.API} http://127.0.0.1:8082/metrics Metrics URL as seen from the Zabbix agent
{$TRAEFIK.4XX_ERRORS} 50 Alert when a service returns more 4xx in 5 minutes
{$TRAEFIK.5XX_ERRORS} 5 Alert when a service returns more 5xx in 5 minutes

Note

Both thresholds default to 0, which disables the triggers — the template only collects data until you decide what “too many errors” means for you. The thresholds apply to every service on the host.

Choosing thresholds

  • 5xx errors are your problem — the backend is down, timing out or crashing. Even a handful in 5 minutes is worth a look on most services.
  • 4xx errors are mostly the client’s problem (404s from scanners, 401s from expired sessions), so set the threshold higher and use it to spot unusual spikes: a burst of 401/403 can mean a broken login flow or a credential-stuffing attempt.
  • Look at a week of data before setting thresholds. The “Service Requests” items give you the normal traffic level for each service.

Summary

  • Traefik already exposes everything you need; Zabbix can read it directly.
  • Every service is discovered automatically, with requests, 4xx, 5xx and traffic.
  • Keep the metrics entry point on localhost and let the Zabbix agent fetch it.
  • Set the 4xx/5xx thresholds — until then, the triggers are off.

Running Traefik in Docker or Kubernetes and want proper monitoring around it? Get in touch.

comments powered by Disqus

Related Posts

gWebTail: tail -f in the browser for teams without SSH access

gWebTail: tail -f in the browser for teams without SSH access

A familiar scene: a new build is deployed to a test server and a developer asks “can you send me the log?”. Someone with SSH access logs in, runs tail -f, copies a chunk into a chat — and ten minutes later does it again.

Read More
ESXi disk health in Zabbix: SMART for SATA, health log for NVMe

ESXi disk health in Zabbix: SMART for SATA, health log for NVMe

The standard Zabbix templates for VMware (VMware and VMware Hypervisor, using the vSphere API) are great for CPU, memory, datastores and VM status. What they don’t tell you is how the physical disks in a standalone ESXi host are doing. You learn that a disk failed when a datastore goes offline — not a week earlier, when the drive started reallocating sectors.

Read More
Monitoring Wazuh agents in Zabbix via the REST API

Monitoring Wazuh agents in Zabbix via the REST API

Wazuh is a popular open-source SIEM/XDR: agents on servers and workstations collect logs, file-integrity events and vulnerability data, and send them to the Wazuh manager. It works well — as long as the agents are actually connected.

Read More