Loki swap the ts value and time in explore module

Hi Team,

Is it possible to swap the timestamp(ts) value in log line and time column values in each log line present in grafana explore page. Please help if there is a solution.

Thanks
Lijo

Hi @lijom200,

Are you using Loki as a datasource in the explore view?

yes, I am using loki as a datasource.

Thanks
Lijo

It is doable (based on the log data you are extracting) and normally term is known as Pattern Parser.

So for e.g. here is a very good example as how to define a custom parsing pattern for Nginx logs:

https://sbcode.net/grafana/nginx-promtail/#using-the-loki-pattern-parser

Also, link to the official documentation:

I hope this helps.

Hi usmanahmad

Thanks for the reply.
I have a doubt here, in the above attached screenshot left most time is not from log line. Which is adding by grafana. So when i created the pattern parser i am not able to swap the “ts”(2022-09-12T09:30:28.32577027Z) value with time value (2022-09-12 15:00:28.028).

Thanks
Lijo Thomas

Hi @lijom200,

Hmm, if you have designed the pattern parser and only need to trim out the other details e.g. timestamp but only up to seconds,

Then you can use Functions e.g. Overwrite OR Transformations inside the Panel. Here is a small screencast of how I converted the timestamp using Overwrite:

timestamp-overwrite 2022-09-26 11-46

Also, another alternative is to define the settings in the grafana.ini configuration as shown in this post.

I hope I answer your question