justwatchcom / sql_exporter

Flexible SQL Exporter for Prometheus.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possible to calculate query time taken?

jmreicha opened this issue · comments

I'm testing out the exporter and it is working for me so far. Wondering if there is any method to get the amount of time a query as a Prometheus metric so that I can measure certain database latencies.

Apologies if this is already outlined in docs, I might have missed it!

Hey, are you talking about getting the historic duration a query takes? If you can query it from the database you can do it, it won't be super accurate as you'd only get the value at the time Prometheus scrapes but might be good enough. In Postgres the pg_stat_activity table is probably your best bet.

Thanks for the reply, that makes more sense.

Maybe I'm thinking about the problem the wrong way. I was thinking that Prometheus would capture the amount of time it takes for a query to complete, but it looks like I am mistaken. I will look into the pg_stat_activity table.