prometheus-community / postgres_exporter

A PostgreSQL metric exporter for Prometheus
Apache License 2.0
2.82k stars 743 forks source link

Add the type of statement (`SELECT|INSERT|UPDATE|DELETE`) as a label in the `stat_statements` collector #946

Open przemek-pokrywka opened 1 year ago

przemek-pokrywka commented 1 year ago

Proposal

Use case. Why is this important?

My database enjoys/suffers heavy read+write traffic with the writes dominating the load, sometimes by orders of magnitude. That makes it very difficult to track the performance of the read queries, even when one uses a logarithmic scale on Grafana. The read (SELECT) queries are simply very close to the bottom and only if you manually hide many write (INSERT) queries, the dashboard becomes usable.

If postgres_exporter would add yet another label to the metrics exported from the pg_stat_statements view, it would be much easier to filter out the write queries. The label would need to contain the type of statement: INSERT/UPDATE/DELETE/CREATE/ALTER/SELECT/OTHER.

Even if postgres_exporter did something really simple (like taking the first word from the query column, without really parsing the SQL) it would help a lot already.

SuperQ commented 1 year ago

Huh, PostgreSQL doesn't have this information in any other metrics source?

We're looking to add query as a label with a length limit.

There are two open PRs for this that need reviewing: