I have the following JSON data provided by Loki:
{
"app":"myapp",
"data":{
"stats":{
"cpu":0,
"ctime":0,
"elapsed":5710,
"memory":528384,
"pid":237,
"ppid":1,
"timestamp":1689261005778
},
"taskId":"64b013c84d8867b08cf5729b"
},
"host":"myhost",
"level":"info",
"service":"myservice",
"timestamp":"2023-07-13T15:10:05.879Z"
}
{
"app":"myapp",
"data":{
"task":{
"createdAt":"2023-07-13T15:10:00.013Z",
"hash":"T32Y9sst89H2gPpuwtiqZToxF2iDCDGKK/qW0c4SkqI=",
"id":"64b013c84d8867b08cf5729b",
"job":"64a799753aa5d2bfdc0eea5c",
"parameters":[
],
"priority":"0",
"reference":"T32Y9sst89H2gPpuwtiqZToxF2iDCDGKK/qW0c4SkqI=",
"script":"myscript.py",
"type":"job",
"updatedAt":"2023-07-13T15:10:00.031Z"
}
},
"host":"myhost",
"level":"info",
"service":"myservice",
"timestamp":"2023-07-13T15:10:00.034Z"
}
There are multiple task logs per script (different “id”, but same “script”). I want to group by “script” and display all the different task runs over time on x-axis and the corresponding duration (see “data.stats.elapsed”) on y-axis. I want to display the name of script and not the taskId, so I guess I need some sort of subquery to make that look-up happen?
Here is what I got so far, but it obviously doesn’t group all the task runs by scripts:
sum by (task_id) (
avg_over_time({app="myapp", service="myservice"} | json task_id="data.taskId", elapsed="data.stats.elapsed" | unwrap elapsed [$__range])
)
Can anyone help me please getting this right? I am a beginner with Grafana and spent quite some time reading the docs already without getting really far.