mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-07 03:35:34 -05:00
function to update GC metrics when prometheus knocks
This commit is contained in:
parent
e8eeec5915
commit
c8852b15ab
2 changed files with 20 additions and 1 deletions
|
|
@ -22,6 +22,7 @@ type registry = {
|
||||||
mutable counters: counter list;
|
mutable counters: counter list;
|
||||||
mutable gauges: gauge list;
|
mutable gauges: gauge list;
|
||||||
mutable hists: histogram list;
|
mutable hists: histogram list;
|
||||||
|
mutable on_will_emit: (unit -> unit) list;
|
||||||
}
|
}
|
||||||
|
|
||||||
let validate_descr_ what s =
|
let validate_descr_ what s =
|
||||||
|
|
@ -154,9 +155,13 @@ end
|
||||||
module Registry = struct
|
module Registry = struct
|
||||||
type t = registry
|
type t = registry
|
||||||
|
|
||||||
let create () : t = { counters = []; gauges = []; hists = [] }
|
let create () : t =
|
||||||
|
{ counters = []; gauges = []; hists = []; on_will_emit = [] }
|
||||||
|
|
||||||
|
let on_will_emit self f = self.on_will_emit <- f :: self.on_will_emit
|
||||||
|
|
||||||
let emit (buf : Buffer.t) (self : t) : unit =
|
let emit (buf : Buffer.t) (self : t) : unit =
|
||||||
|
List.iter (fun f -> f ()) self.on_will_emit;
|
||||||
List.iter (Gauge.emit buf) self.gauges;
|
List.iter (Gauge.emit buf) self.gauges;
|
||||||
List.iter (Counter.emit buf) self.counters;
|
List.iter (Counter.emit buf) self.counters;
|
||||||
List.iter (Histogram.emit buf) self.hists;
|
List.iter (Histogram.emit buf) self.hists;
|
||||||
|
|
@ -228,4 +233,8 @@ module GC_metrics = struct
|
||||||
Counter.incr_to self.major_coll stats.major_collections;
|
Counter.incr_to self.major_coll stats.major_collections;
|
||||||
Counter.incr_to self.compactions stats.compactions;
|
Counter.incr_to self.compactions stats.compactions;
|
||||||
Gauge.set self.major_heap (stats.heap_words * 8)
|
Gauge.set self.major_heap (stats.heap_words * 8)
|
||||||
|
|
||||||
|
let create_and_update_before_emit reg : unit =
|
||||||
|
let gc = create reg in
|
||||||
|
Registry.on_will_emit reg (fun () -> update gc)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,11 @@ module Registry : sig
|
||||||
|
|
||||||
val create : unit -> t
|
val create : unit -> t
|
||||||
|
|
||||||
|
val on_will_emit : t -> (unit -> unit) -> unit
|
||||||
|
(** [on_will_emit registry f] calls [f()] every time
|
||||||
|
[emit buf registry] is called (before the metrics start being emitted). This
|
||||||
|
is useful to update some metrics on demand. *)
|
||||||
|
|
||||||
val emit : Buffer.t -> t -> unit
|
val emit : Buffer.t -> t -> unit
|
||||||
(** Write metrics into the given buffer. The buffer will be
|
(** Write metrics into the given buffer. The buffer will be
|
||||||
cleared first thing. *)
|
cleared first thing. *)
|
||||||
|
|
@ -79,4 +84,9 @@ module GC_metrics : sig
|
||||||
|
|
||||||
val create : Registry.t -> t
|
val create : Registry.t -> t
|
||||||
val update : t -> unit
|
val update : t -> unit
|
||||||
|
|
||||||
|
val create_and_update_before_emit : Registry.t -> unit
|
||||||
|
(** [create_and_update_before_emit reg] creates new GC metrics,
|
||||||
|
adds them to the registry, and uses {!Registry.on_will_emit}
|
||||||
|
to {!update} the metrics every time the registry is polled. *)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue