Library
Module
Module type
Parameter
Class
Class type
Metrics Monitoring.
Metrics
provides a basic infrastructure to monitor metrics using time series. Monitoring is performed on sources, indexed by tags. Tags allow users to select at runtime which metric sources is producing data points. Disabled data-sources have a low runtime cost (only a closure allocation) which make Metrics
suitable to instrument production systems.
Both sources tags and data-points are built using dictionaries of typed entries called fields.
Metrics
is heavily inspired by Logs as it decouples metric reporting is from metric monitoring. This is handled by custom reporters.
0.1.0 - homepage
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")
.
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
.
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.
module Data : sig ... end
Data
defines what is stored in the time series.
type data = Data.t
The type for data points.
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
.
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.
module Graph : sig ... end
module Key : sig ... end
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
.
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 ]) result
The type for extended results.
val rrun :
('a, ('b, 'c) rresult -> Data.t) src ->
('a -> tags) ->
(unit -> ('b, 'c) result) ->
('b, 'c) result
Same as run
but also record if the result is Ok
or Error
.
TODO: explain and give an example
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
.
The Gc module of the OCaml system provides counters of the memory management via Gc.quick_stat and Gc.stat function. Both are provided here.
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.