Page
Library
Module
Module type
Parameter
Class
Class type
Source
Metrics
SourceMetrics 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 are 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 from metric monitoring. This is handled by custom reporters.
v0.5.0 - homepage
The type for metric fields.
The type for field keys.
type 'a field_f =
?doc:string ->
?unit:string ->
?graph:graph ->
?graphs:graph list ->
key ->
'a ->
field
The type for field functions.
The type for process status.
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
.
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.
pp_value
is the pretty-printer for field values, using sensible default.
Tags
indexes metric sources, and allow to enable/disable data collection at runtime.
The type for metric tags. Used to distinguish the various entities that are being measured.
all_enabled ()
is true if all metric sources are enabled.
enable_tag t
enables all the registered metric sources having the tag t
.
disable_tag t
disables all the registered metric sources having the tag t
.
enable_all ()
enables all registered metric sources.
disable_all ()
disables all registered metric 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
.
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).
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.
nop_reporter
is the initial reporter returned by reporter
, it does nothing if a metric gets reported.
cache_reporter ?cb ()
is a reporter that stores the last measurement from each source in a map (which can be retrieved by get_cache
below). This overcomes 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). The optional cb
function is called for each measurement that gets reported.
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).
get_cache ()
is the current data of the cache reporter. The cache is only filled if cache_reporter ?cb ()
is set as a reporter.
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.
val report :
('a, 'b) src ->
over:(unit -> unit) ->
k:(unit -> 'c) ->
('a -> tags) ->
('b -> (data -> 'c) -> 'd) ->
'd
/