Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sum certain values from Grafana-Loki logs?

Tags:

grafana-loki

I have this log line:

Successfully encrypted 189322 bytes for upload req_id=MediaUpload
Successfully encrypted 189322 bytes for upload req_id=MediaUpload
Successfully encrypted 492346 bytes for upload req_id=MediaUpload

There's a way to sum the bytes of the matching query log lines? Per example, by the those logs I would like to have a summed value of 870990 bytes or 0.87099 MB.

Is that possible?

like image 303
Kaleby Cadorin Avatar asked Oct 12 '25 09:10

Kaleby Cadorin


1 Answers

Sure you can. Check this out.

I've used the pattern parser to extract the bytes as a number out of your log lines.

Then you can run a range query on top of that:

Eg.

sum by (app) 
(sum_over_time(
{app="your-app"}
| pattern `Successfully encrypted <byte_size> bytes for upload req_id=<_>`
| unwrap byte_size 
| __error__="" [$__interval]
))

you can change $__interval based on your needs.

like image 169
Dan Dinu Avatar answered Oct 14 '25 22:10

Dan Dinu