package tally

  1. Overview
  2. Docs

Tally - collecting metrics of OCaml applications

Tally is a library to collect and output counters of OCaml applications. The output can be send to InfluxDB (via Telegraf), and then visualized with Grafana.

The API of a tally is simple: each tally has a name (which is the measurement name), a set of tags (key and value are string), and a set of fields (with key being a string, and value an int).

Base tallies are already implemented by this library: gc uses Gc.quick_stat, logs exposes the Logs.warn_count () and Logs.err_count ().

An example application would use:

let pid = Unix.getpid () in
let _ru = Tally_rusage.v pid in
let more_tags = [ "process", "my-application" ; "pid", string_of_int pid ] in
let measurements = Tally.measure () in
let influx_data =
  List.map (fun name tags fields ->
    Tally.encode_influx name ~tags:(more_tags @ tags) fields)
    measurements |> String.concat ""
in
let socket = Unix.(socket PF_INET SOCK_STREAM 0) in
Unix.connect socket Unix.(ADDR_INET (inet_addr_loopback, 8096));
let _written =
  Unix.write socket (Bytes.of_string influx_data) 0 (String.length influx_data)
in
()

Tally-rusage

The sublibrary tally.rusage provides Tally_rusage.v pid to collect resource usage from the host system about a process. This uses /proc/<pid>/stat and /proc/<pid>/status on Linux, and ctl_kern.kern_proc.kern_proc_pid on FreeBSD.

Tally-mkernel

The separate opam package tally-mkernel collects metrics from mkernel devices and the ocaml-solo5 malloc implementation.

Comparison to other metric libraries

The library metrics has a similar goal, but uses a more involved API for fields, and tags (with GADTs - where the keys and values may have more types). It also introduces more buereaucracy with graphs and also provides interaction with GNUplot.

The library prometheus is tied to the monitoring system Prometheus.

Tally is not tied to any monitoring system, contributions for more operating systems as well as further monitoring systems are appreciated - though the latter may be best provided by separate packages.

Installation

It is released to opam-repository, so an opam install tally or opam install tally-mkernel will make this package available.

LICENSE

AGPL 3 or later