mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-09 12:23:32 -04:00
util: add module to emit some GC metrics
This commit is contained in:
parent
a9f17ef54b
commit
fdd4582a2f
2 changed files with 43 additions and 0 deletions
|
|
@ -7,6 +7,8 @@ module Event = Event
|
|||
module Span = Span
|
||||
module Globals = Globals
|
||||
module Timestamp_ns = Timestamp_ns
|
||||
module GC_metrics = GC_metrics
|
||||
module Trace_context = Trace_context
|
||||
|
||||
module Trace = struct
|
||||
open Proto.Trace
|
||||
|
|
|
|||
|
|
@ -592,6 +592,7 @@ module Metrics = struct
|
|||
Collector.send_metrics [rm] ~ret:ignore
|
||||
end
|
||||
|
||||
(** {2 Utils} *)
|
||||
|
||||
(** Implementation of the W3C Trace Context spec
|
||||
|
||||
|
|
@ -663,3 +664,43 @@ module Trace_context = struct
|
|||
|
||||
end
|
||||
end
|
||||
|
||||
(** Export GC metrics.
|
||||
|
||||
These metrics are emitted after each GC collection. *)
|
||||
module GC_metrics = struct
|
||||
(** Basic setup: a few stats *)
|
||||
let basic_setup () : unit =
|
||||
let last = ref (Timestamp_ns.now_unix_ns()) in
|
||||
let emit() =
|
||||
let gc = Gc.quick_stat () in
|
||||
let start_time_unix_nano = !last in
|
||||
last := Timestamp_ns.now_unix_ns();
|
||||
Metrics.(
|
||||
emit
|
||||
[
|
||||
gauge ~name:"ocaml.gc.major_heap_words" ~unit_:"words"
|
||||
[ int gc.Gc.heap_words ];
|
||||
sum ~name:"ocaml.gc_minor_allocated"
|
||||
~aggregation_temporality:Metrics.Aggregation_temporality_cumulative
|
||||
~is_monotonic:true
|
||||
~unit_:"words"
|
||||
[ float ~start_time_unix_nano gc.Gc.minor_words ];
|
||||
sum ~name:"ocaml.gc.minor-collections"
|
||||
~aggregation_temporality:Metrics.Aggregation_temporality_cumulative
|
||||
~is_monotonic:true
|
||||
[ int ~start_time_unix_nano gc.Gc.minor_collections ];
|
||||
sum ~name:"ocaml.gc.major-collections"
|
||||
~aggregation_temporality:Metrics.Aggregation_temporality_cumulative
|
||||
~is_monotonic:true
|
||||
[ int ~start_time_unix_nano gc.Gc.major_collections ];
|
||||
sum ~name:"ocaml.gc.compactions"
|
||||
~aggregation_temporality:Metrics.Aggregation_temporality_cumulative
|
||||
~is_monotonic:true
|
||||
[ int ~start_time_unix_nano gc.Gc.compactions ];
|
||||
])
|
||||
in
|
||||
ignore (Gc.create_alarm emit : Gc.alarm);
|
||||
()
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue