Skip to content

Commit 3d7be03

Browse files
author
Andrii Sultanov
committed
prometheus: Add CollectorRegistry.unregister functions
Sources of metrics can sometimes disappear at runtime (a VM being destroyed, disk being unplugged), and rather than continuing to present the last value, it is useful to remove them altogether. Other Prometheus client libraries do implement similar functions as well, see https://docs.rs/prometheus/latest/prometheus/struct.Registry.html#method.unregister for example. Signed-off-by: Andrii Sultanov <andrii.sultanov@cloud.com>
1 parent fb4f8b1 commit 3d7be03

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/prometheus.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,16 @@ module CollectorRegistry = struct
121121
ensure_not_registered t info;
122122
t.metrics <- MetricFamilyMap.add info collector t.metrics
123123

124+
let unregister t info =
125+
t.metrics <- MetricFamilyMap.remove info t.metrics
126+
124127
let register_lwt t info collector =
125128
ensure_not_registered t info;
126129
t.metrics_lwt <- MetricFamilyMap.add info collector t.metrics_lwt
127130

131+
let unregister_lwt t info =
132+
t.metrics_lwt <- MetricFamilyMap.remove info t.metrics_lwt
133+
128134
open Lwt.Infix
129135

130136
let map_p m =

0 commit comments

Comments
 (0)