skip to Main Content

I’m trying to find a way to get response times from Traefik per route.

For instance:

/api/asdf/.*     123.5ms
/blub/narf/.*     70.5ms
/blub/.*        1337.8ms

and so on.

This doesn’t seem to be a very unusual requirement but after googeling a lot, I didn’t find anything that could do the job.

I even had a look at the middlewares but there is no way to get response time of a request because it only hooks itself into the request but there is no hook that would be called after the request completed.

The traefik log files actually contain the information (in debug log level) and if I could tail somehow with a e.g. python script, I could run a list of regexs on them and collect this way the response times. But tailing on docker logs is quite messy imho and I think there should be some more obvious way I havn’t found yet 🤔

Can’t imaging that I’m the first person trying to track response times per route – but why can’t I find anything 🤷‍♂️

Does someone perhaps an idea in which direction I should search?

Thank you in advance!

2

Answers


  1. If you dont find any, you can take help from this project and https://github.com/traefik/plugin-rewritebody. It enables the user to replace the body but you get the idea, there is an example to get the response and you can add your own logic to write the response time in the file or whatsoever

    Login or Signup to reply.
  2. You can try using Prometheus with Traefik. Here is a sample docker-compose which will do the job

    You might wanna checkout this open-source repo

    We calculated the average response time of API’s by enabling prometheus in traefik.

    The expression which we are using for the same is like

    expr: sum(traefik_service_request_duration_seconds_sum{instance="company.com:12345",service=~"backend-module-test.*"}) / sum(traefik_service_request_duration_seconds_count{instance="company.com:12345",service=~"backend-module-test.*"}) * 1000
    

    This expression is evaluated for a period of 1m, 5m, 10m etc and the resulting graph is displayed on the dashboard.

    Other solutions include traefik-docs

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search