Fields
The type for metric graphs.
type 'a field_f = ?doc:string -> ?unit:string -> ?graph:graph -> ?graphs:graph list -> key -> 'a -> field
The type for field functions.
val string : string field_f
string ?doc k v
is the field whose key is k
and value is v
.
val int : int field_f
int ?doc k i
is the field whose key is k
and value is i
.
val uint : int field_f
uint ?doc k i
is the field whose key is k
and value is i
.
val int32 : int32 field_f
int32 k i
is the field whose key is k
and value is i
.
val uint32 : int32 field_f
uint32 ?doc k i
is the field whose key is k
and value is i
.
val int64 : int64 field_f
int64 ?doc k i
is the field whose key is k
and value is i
.
val uint64 : int64 field_f
uint64 ?doc k i
is the field whose key is k
and value is i
.
val float : float field_f
uint ?doc k f
is the field whose key is k
and value is i
.
val bool : bool field_f
uint ?doc k b
is the field whose key is k
and value is i
.
val duration : int64 -> field
duration 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 -> field
field ?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 -> string
key f
is f
's key.
val doc : field -> string option
doc f
is f
's documentation.
val unit : field -> string option
unit t
are t
's units.
val index : fields:string list -> field -> int
index ~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 ... end
Data
defines what is stored in the time series.
type data = Data.t
The type for data points.
Tags
module Tags : sig ... end
Tags
indexes metric sources, and allow to enable/disable data collection at runtime.
type tags = field list
The type for metric tags. Used to distinguish the various entities that are being measured.
val enable_tag : key -> unit
enable_tag t
enables all the registered metric sources having the tag t
.
val disable_tag : key -> unit
disable_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 ... end
Metric sources.
Metric Graphs
module Graph : sig ... end
module Key : sig ... end
Monitoring
val is_active : ('a, 'b) src -> bool
is_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) -> 'b
run 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.result
The type for extended results.
val rrun : ('a, ('b, 'c) rresult -> Data.t) src -> ('a -> tags) -> (unit -> ('b, 'c) Stdlib.result) -> ('b, 'c) Stdlib.result
Same 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 : reporter
nop_reporter
is the initial reporter returned by reporter
, it does nothing if a metric gets reported.
val reporter : unit -> reporter
reporter ()
is the current reporter.
val set_reporter : reporter -> unit
set_reporter r
sets the current reporter to r
.
module SM : Stdlib.Map.S with type key = Src.t
cache_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.