Active Queries Log

When expensive or otherwise troublesome PromQL queries cause your Prometheus server to crash or become unresponsive (so you have to forcibly restart it), you will often want to know which queries were running at the time of the crash or restart. Luckily, Prometheus' TSDB automatically tracks any currently running queries in a file in its TSDB data directory. If you restart Prometheus and it detects a non-empty file, it will log any contained queries at startup.

For example, if your Prometheus server crashed while running a PromQL query with the expression up, Prometheus might log something like this during startup:

level=info ts=2023-04-08T15:46:34.320Z caller=query_logger.go:80 component=activeQueryTracker msg="These queries didn't finish in prometheus' last run:" queries="[{\"query\":\"up",\"timestamp_sec\":1661010165}]"

This helps you track down queries that are causing trouble for your Prometheus server, so you can avoid or fix them in the future.