diff --git a/src/prometheus.ml b/src/prometheus.ml index 7077824..d34a757 100644 --- a/src/prometheus.ml +++ b/src/prometheus.ml @@ -133,6 +133,11 @@ module CollectorRegistry = struct (fun acc (k, v) -> v >|= fun v -> MetricFamilyMap.add k v acc) MetricFamilyMap.empty + let collect_non_lwt t = + List.iter (fun f -> f ()) t.pre_collect; + let metrics = MetricFamilyMap.map (fun f -> f ()) t.metrics in + metrics + let collect t = List.iter (fun f -> f ()) t.pre_collect; Lwt_list.iter_p (fun f -> f ()) t.pre_collect_lwt >>= fun () -> diff --git a/src/prometheus.mli b/src/prometheus.mli index c7c3d66..c1619f3 100644 --- a/src/prometheus.mli +++ b/src/prometheus.mli @@ -85,6 +85,11 @@ module CollectorRegistry : sig val collect : t -> snapshot Lwt.t (** Read the current value of each metric. *) + val collect_non_lwt: t -> snapshot + (** Read the current value of each metric. To be used in non-Lwt contexts, as + it doesn't evaluate collectors registered with [register_lwt] or functions + registered with [register_pre_collect_lwt] *) + val register : t -> MetricInfo.t -> (unit -> Sample_set.t LabelSetMap.t) -> unit (** [register t metric collector] adds [metric] to the set of metrics being collected. It will call [collector ()] to collect the values each time [collect] is called. *)