Count and group by day based on label value

  • What Grafana version and what operating system are you using?
    Grafana v9.1.4

  • What are you trying to achieve?
    I’m collecting metrics about log files with filestat_exporter, and i would like to have graphic with the count of rotated logs per day based on values of the label path.

file_stat_size_bytes{fqdn=~“$fqdn”,path=~“/var/log/mylog-[0-9].*.log”}

so the path label has values like this:

/var/log/mylog-2023-03-18.0.log
/var/log/mylog-2023-03-18.1.log
/var/log/mylog-2023-03-18.2.log
/var/log/mylog-2023-03-18.3.log
/var/log/mylog-2023-03-19.0.log
/var/log/mylog-2023-03-19.1.log
/var/log/mylog-2023-03-19.2.log

How can i write a PromQL that would give me a bar graphic with the count of rotated logs per day based on the values of the label path?

Using the values above, the end result would be:
2023-03-18 → 4
2023-03-19 → 3

Welcome @mvrk

Have you explored all of the examples here?

Also, this question (and answer) seems similar to yours and may help get you started.

1 Like

thank you, that post on stackoverflow really helped.

count by (path_group) (label_replace(file_stat_modif_time_seconds{fqdn=~“$fqdn”,path=~“/var/log/mylog-[0-9]..log"}, “path_group”, “$1”, “path”, ".-(\d{4}-\d{2}-\d{2}).*”))