Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/prometheus.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 () ->
Expand Down
5 changes: 5 additions & 0 deletions src/prometheus.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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. *)
Expand Down