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
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 whatsoeverYou can try using
Prometheus
withTraefik
. Here is a sampledocker-compose
which will do the jobYou 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
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