Fields
The type for metric graphs.
type 'a field_f = ?doc:string -> ?unit:string -> ?graph:graph -> ?graphs:graph list -> key -> 'a -> fieldThe type for field functions.
val string : string field_fstring ?doc k v is the field whose key is k and value is v.
val int : int field_fint ?doc k i is the field whose key is k and value is i.
val uint : int field_fuint ?doc k i is the field whose key is k and value is i.
val int32 : int32 field_fint32 k i is the field whose key is k and value is i.
val uint32 : int32 field_fuint32 ?doc k i is the field whose key is k and value is i.
val int64 : int64 field_fint64 ?doc k i is the field whose key is k and value is i.
val uint64 : int64 field_fuint64 ?doc k i is the field whose key is k and value is i.
val float : float field_fuint ?doc k f is the field whose key is k and value is i.
val bool : bool field_fuint ?doc k b is the field whose key is k and value is i.
val duration : int64 -> fieldduration t is the field ("duration", t, "ns").
Custom fields
type 'a ty = | String : string ty |
| Bool : bool ty |
| Float : float ty |
| Int : int ty |
| Int32 : int32 ty |
| Int64 : int64 ty |
| Uint : int ty |
| Uint32 : int32 ty |
| Uint64 : int64 ty |
| Other : 'a Fmt.t -> 'a ty |
The type of supported values in metric fields.
val field : ?doc:string -> ?unit:string -> ?graph:graph -> ?graphs:graph list -> string -> 'a ty -> 'a -> fieldfield ?doc ?unit k ty v is the field whose key is k, value type is ty and value is v.
Reading Fields
val key : field -> stringkey f is f's key.
val doc : field -> string optiondoc f is f's documentation.
val unit : field -> string optionunit t are t's units.
val index : fields:string list -> field -> intindex ~fields f is f's index in the list of field keys fields. Raise Not_found if f is not a field of t.
Same as index but using field keys instead.
Pretty-printing Fields
Data points
module Data : sig ... endData defines what is stored in the time series.
type data = Data.tThe type for data points.
Tags
module Tags : sig ... endTags indexes metric sources, and allow to enable/disable data collection at runtime.
type tags = field listThe type for metric tags. Used to distinguish the various entities that are being measured.
val enable_tag : key -> unitenable_tag t enables all the registered metric sources having the tag t.
val disable_tag : key -> unitdisable_tag t disables all the registered metric sources having the tag t.
Sources
The type for metric sources. A source defines a named unit for a time series. 'a is the type of the function used to create new data points. 'b is the type for tags.
module Src : sig ... endMetric sources.
Metric Graphs
module Graph : sig ... endmodule Key : sig ... endMonitoring
val is_active : ('a, 'b) src -> boolis_active src is true iff src monitoring is enabled.
add src t f adds a new data point to src for the tags t.
val run : ('a, ('b, exn) Stdlib.result -> Data.t) src -> ('a -> tags) -> (unit -> 'b) -> 'brun src t f runs f () and add a new data points.
Depending on src configuration, new data points might have duration information (e.g. how long g () took, in nano-seconds) and status information (e.g. to check if an exception has been raised).
type ('a, 'b) rresult = ('a, [ `Exn of exn | `Error of 'b ]) Stdlib.resultThe type for extended results.
val rrun : ('a, ('b, 'c) rresult -> Data.t) src -> ('a -> tags) -> (unit -> ('b, 'c) Stdlib.result) -> ('b, 'c) Stdlib.resultSame as run but also record if the result is Ok or Error.
Reporters
type reporter = {now : unit -> int64; |
at_exit : unit -> unit; |
report : a. tags:tags -> data:data -> over:(unit -> unit) -> Src.t -> (unit -> 'a) -> 'a; |
}The type for reporters.
val nop_reporter : reporternop_reporter is the initial reporter returned by reporter, it does nothing if a metric gets reported.
val reporter : unit -> reporterreporter () is the current reporter.
val set_reporter : reporter -> unitset_reporter r sets the current reporter to r.
module SM : Stdlib.Map.S with type key = Src.tcache_reporter now () is a reporter that stores the last measurement from each source in a map (which can be retrieved by the returned function). This is an initial attempt to overcome the push vs pull interface. Each measurement _event_ is sent at an arbitrary point in time, while reporting over a communication channel may be rate-limited (i.e. report every 10 seconds statistics, rather than whenever they appear).
This is only a good idea for counters, histograms etc. may be useful for other numbers (such as time consumed between receive and send - the measurement should provide the information whether it's a counter or sth else).
OCaml Gc sources
gc_stat ~tags is the source of OCaml's Gc.stat () memory management counters.
gc_quick_stat ~tags is the source of OCaml's Gc.quick_stat () memory management counters.