Need assistance in configuring alerts with Loki data source

Hi guys, newbie here. I could use some help. I’ve tried to read up the documentation, including this one and I still could not figure out how to configure alerts with Loki.

I have a log file in NDJSON format, and am using Loki + Promtail to ingest and display the data from the log file on Grafana. Example entries in the log file would be something like this:

{“timestamp”: “2024-04-01T00:16:11+08:00”, “number_of_files”: 30, “something_else”: “cat”}

{“timestamp”: “2024-04-01T00:20:36+08:00”, “number_of_files”: 92, “something_else”: “dog”}

I am able to parse and display this on Grafana without any issues:

dashboard

Now I want to create an alert to notify me if, for example, the number_of_files drops to 10 or lower. But I’m completely lost as to how to configure the Alert rules, and I couldn’t really figure it out from the documentation. This is the error message I’m getting:

I’ve tried to add a json parser (as per the hint) and other haphazard guesses, but I’m getting the same error message.

With the Grafana panel, I am able to apply various transformations to extract the data and allow it to be visualized, but there’s no such option on the Alert page, so I’m not sure how to go about from here.

Any insight on this matter will be greatly appreciated. Thank you.