sql_exporter icon indicating copy to clipboard operation
sql_exporter copied to clipboard

Can I create histogram metrics with this exporter

Open duergner opened this issue 6 years ago • 3 comments

I found examples for counter and gauge metrics types but was not able to find something regarding histogram. Is this possible?

duergner avatar Oct 07 '19 12:10 duergner

@duergner did you ever find out if you could use this for histogram types? I looked into the source and only saw references to counter and gauge

teoboley avatar Mar 03 '20 20:03 teoboley

I looked more into the code and saw that it explicitly only supports counter and gauge metric types: https://github.com/free/sql_exporter/blob/6f96b0d6b40340929e4d84c902378e7ead113ff1/config/config.go#L423

teoboley avatar Mar 03 '20 21:03 teoboley

SQL Exporter is stateless. Every time it is scraped by Prometheus it queries the DB for metric values. (A counter also implies state, but we're relying on the DB for that.)

Implementing a histogram would imply maintaining some sort of state across scrapes (and independent of them). Of course you could manually "build" your own histogram from scratch: the (cumulative) buckets are simply a bunch of counters with an le label; plus a sum and a count metric. All in all 3 queries/metrics. There is no need to explicitly "bundle" them together on the /metrics page, Prometheus will ignore all of that when scraping (including whether a metric is a counter or a gauge).

You may get some inconsistencies due to race conditions between the 3 queries (e.g. the count metric may be calculated before the sum metric, on different underlying data) but I wouldn't worry to much about that. The buckets would be consistent with one another, as they would be the output of a single SQL query.

free avatar Mar 04 '20 06:03 free