You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by wi...@apache.org on 2023/03/31 15:31:26 UTC
[couchdb] 04/04: fix (prometheus): gauge types for metrics that can be decremented
This is an automated email from the ASF dual-hosted git repository.
willholley pushed a commit to branch prometheus_metrics
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit b8d60faa18526948956fb9e3b2da27c1e86aaa24
Author: Will Holley <wi...@uk.ibm.com>
AuthorDate: Fri Mar 31 12:25:05 2023 +0000
fix (prometheus): gauge types for metrics that can be decremented
Prometheus assumes that metrics with `counter` types are cumulative.
This isn't the case in CouchDB / Folsom, which allows counters to
be decremented.
This changes the type of metrics where we decrement the counter values
to `gauge`:
- couchdb_open_databases
- couchdb_couchdb_open_os_files
- couchdb_httpd_clients_requesting_changes
---
src/couch_prometheus/src/couch_prometheus_util.erl | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/src/couch_prometheus/src/couch_prometheus_util.erl b/src/couch_prometheus/src/couch_prometheus_util.erl
index 16886f4a7..e1d0345a7 100644
--- a/src/couch_prometheus/src/couch_prometheus_util.erl
+++ b/src/couch_prometheus/src/couch_prometheus_util.erl
@@ -71,6 +71,20 @@ couch_to_prom([couchdb, httpd_status_codes, 200], Info, _All) ->
});
couch_to_prom([couchdb, httpd_status_codes, Code], Info, _All) ->
to_prom(httpd_status_codes, {[{code, Code}], val(Info)});
+
+% Convert to gauge in prometheus type. This is required because
+% prometheus assumes that counters are cumulative and should be
+% rated by default, whereas folsom (the library CouchDB uses for
+% metrics) allows counters to be decremented as well. Folsom supports
+% gauges but does not track their state to allow increment/decrement.
+% Basically, anywhere we use couch_stats:decrement_count we should
+% be converting to a prometheus gauge.
+couch_to_prom([couchdb, open_databases], Info, _All) ->
+ to_prom(open_databases, gauge, desc(Info), val(Info));
+couch_to_prom([couchdb, open_os_files], Info, _All) ->
+ to_prom(open_os_files, gauge, desc(Info), val(Info));
+couch_to_prom([couchdb, httpd, clients_requesting_changes], Info, _All) ->
+ to_prom(httpd_clients_requesting_changes, gauge, desc(Info), val(Info));
couch_to_prom([ddoc_cache, hit], Info, All) ->
Total = val(Info) + val([ddoc_cache, miss], All),
to_prom(ddoc_cache_requests_total, counter, "number of design doc cache requests", Total);