I need to create a graph, which tells the average response time for each request

I need to create a graph, which tells the average response time for each request.

I need to use this information for each line

ex:
POST /v1/contract [+761.258 ms]

request 1 → [+761.258 ms]

request 2 → [+311.258 s]

2 request, average time [+761.258 ms] + [+311.258 s] / 2

I need to extract this value, and create a graph using this response time for each request

How can I do this ?

thank you

1 Like

You might want to have a look at pattern expressions in LogQL which you can read about here:

This will allow you to define a pattern expression in logql which will extract each bit of a structured log line into a data element that you can then use subsequently. Check the examples in the post.

Note that the query you’re showing is using the visual query builder, you’ll need to hit the “code” toggle switch next to the “builder” item you’ve got selected at the right to enter these queries.

2 Likes

please post some sample text (obfuscated for sensitive data) rather than image? So we can test it out in our loki

2024-9-98 stdout F info: <= 200 POST /v1/contract [+1.041 s]

etc

1 Like

Thank you!


2024-02-27T12:59:08.71523167Z stdout F info: <= 200 POST /v1/contract [+638.502 ms] {“mod”:“webhook”,“nodeID”:“budget-6499b94c75-mb9fw-17”,“ns”:“oi-svc-budget”,“svc”:“webhook”}
2024-02-27T12:58:32.262676191Z stdout F info: <= 200 POST /v1/contract [+872.488 ms] {“mod”:“webhook”,“nodeID”:“budget-6499b94c75-vv9wx-17”,“ns”:“oi-svc-budget”,“svc”:“webhook”}
2024-02-27T12:51:33.668970191Z stdout F info: <= 200 POST /v1/contract [+829.923 ms] {“mod”:“webhook”,“nodeID”:“budget-6499b94c75-vv9wx-17”,“ns”:“oi-svc-budget”,“svc”:“webhook”}
2024-02-27T12:46:20.032044694Z stdout F info: <= 200 POST /v1/contract [+900.940 ms] {“mod”:“webhook”,“nodeID”:“budget-6499b94c75-mb9fw-17”,“ns”:“oi-svc-budget”,“svc”:“webhook”}
2024-02-27T12:45:20.198352704Z stdout F info: <= 200 POST /v1/contract [+1.610 s] {“mod”:“webhook”,“nodeID”:“budget-6499b94c75-vv9wx-17”,“ns”:“oi-svc-budget”,“svc”:“webhook”}

Column “LINE”

2024-02-27T13:00:39.966427389Z stdout F e[32minfoe[39m: <= 200 POST /v1/contract [+655.075 ms] {“mod”:“webhook”,“nodeID”:“budget-6499b94c75-vv9wx-17”,“ns”:“oi-svc-budget”,“svc”:“webhook”}

2024-02-27T12:58:32.262676191Z stdout F e[32minfoe[39m: <= 200 POST /v1/contract [+872.488 ms] {“mod”:“webhook”,“nodeID”:“budget-6499b94c75-vv9wx-17”,“ns”:“oi-svc-budget”,“svc”:“webhook”}

1 Like