A question on unwrap

Hello,

I’m trying to understand how unwrap works.

{"timestamp":"2021-10-10T15:08:54.408395+0300", "uptime":1}
{"timestamp":"2021-10-10T15:09:54.408395+0300", "uptime":3}
{"timestamp":"2021-10-10T15:10:54.408395+0300", "uptime":5}
{"timestamp":"2021-10-10T15:11:54.408395+0300", "uptime":10}
{"timestamp":"2021-10-10T15:12:54.408395+0300", "uptime":15}
{"timestamp":"2021-10-10T15:13:54.408395+0300", "uptime":22}

So I have this kind of json log generated by promtail fed into loki. My question is I’m trying to graph this uptime yet no luck. Tried the following:

{job="myjob"} | json |  unwrap uptime | __error__="" [1m]

but it seems I need to apply a function to it. Assume uptime is metric in time.

thanks,
evrim.

So I was able to make logs just the data I want by the following:

{job="myjob"} |json|line_format "{{.uptime |int}}" |__error__=""

Any ideas on plotting the integers?

thanks,
evrim.

I think this should be it plus an aggregation. Could you try e.g. avg_over_time({job="myjob"} | json | unwrap uptime | __error__="" [5m]).

Also, it seems uptime is a gauge. These are surprisingly nasty to handle. Counts are simpler in combination with the rate aggregator.

You can also use last_over_time or first_over_time is you just want one value per step and range.