counter metrics

This commit is contained in:
Hannes Mehnert 2019-11-08 12:49:04 +01:00
parent f10e6257be
commit aaec284b17
2 changed files with 29 additions and 1 deletions

View file

@ -1,8 +1,32 @@
open Lwt.Infix
let src = Logs.Src.create "influx" ~doc:"influx metrics reporter"
let src = Logs.Src.create "monitoring-experiments" ~doc:"Monitoring experiments"
module Log = (val Logs.src_log src : Logs.LOG)
let create ~f =
let data : (string, int) Hashtbl.t = Hashtbl.create 7 in
(fun x ->
let key = f x in
let cur = match Hashtbl.find_opt data key with
| None -> 0
| Some x -> x
in
Hashtbl.replace data key (succ cur)),
(fun () ->
let data, total =
Hashtbl.fold (fun key value (acc, total) ->
(Metrics.uint key value :: acc), value + total)
data ([], 0)
in
Metrics.uint "total" total :: data)
let counter_metrics ~f name =
let open Metrics in
let doc = "Counter metrics" in
let incr, get = create ~f in
let data thing = incr thing; Data.v (get ()) in
Src.v ~doc ~tags:Metrics.Tags.[] ~data name
let vmname = Metrics.field ~doc:"name of the virtual machine" "vm" Metrics.String
module Make (T : Mirage_time.S) (S : Mirage_stack.V4) = struct

View file

@ -1,3 +1,7 @@
val counter_metrics : f:('a -> string) -> string ->
(Metrics.field list, 'a -> Metrics.data) Metrics.src
val vmname : string -> Metrics.field
(** [vmname name] creates a [tag] with the virtual machine name. *)