New to Loki, but having trouble finding an answer to what I’m trying to do in the docs:
I’m logging CPU pressure from my application and would like to show the average pressure over a period of time, say 15m, as a gauge. CPU pressure is being logged as 1 of 4 possible values: "nominal"
, "fair"
, "serious"
, or "critical"
in a JSON object in my logs. A sample log that reports CPU pressure looks like this:
{
"extra": {
"data": {
"state": "fair",
"time": 1697147863116.569
}
},
"message": "CPU pressure changed"
}
How can I then take a group of these logs over a specified range like 15m and calculate an average value to display in a gauge? For example, if nominal = 1, fair = 2, serious = 3, and critical = 4, and I have 2 fair logs, 4 nominal logs, and 1 critical log, then the average value would be ~1.7 out of 4 which I would like to display in a gauge.
Can this be achieved in a query, or is it something that must be done in Grafana, or in the logs themselves? Thanks for your help!