diff --git a/mirage-monitoring.opam b/mirage-monitoring.opam index 6fb00fd..3a789a3 100644 --- a/mirage-monitoring.opam +++ b/mirage-monitoring.opam @@ -16,8 +16,7 @@ depends: [ "metrics-influx" {>= "0.2.0"} "mirage-time" {>= "2.0.0"} "tcpip" {>= "7.0.0"} - "mirage-solo5" {>= "0.6.4" & < "0.7.0"} - "ocaml-freestanding" {>= "0.4.5"} + "mirage-solo5" {>= "0.7.0"} "mirage-runtime" "memtrace-mirage" {>= "0.2.1.2.2"} "mirage-clock" {>= "4.0.0"} diff --git a/src/mirage_monitoring.ml b/src/mirage_monitoring.ml index 6b60639..3f4e450 100644 --- a/src/mirage_monitoring.ml +++ b/src/mirage_monitoring.ml @@ -31,11 +31,12 @@ let counter_metrics ~f name = let vmname = Metrics.field ~doc:"name of the virtual machine" "vm" Metrics.String -let memory_metrics ~tags = +let memory_metrics ~quick ~tags = let open Metrics in let doc = "Memory counters" in + let stat = Solo5_os.Memory.(if quick then quick_stat else stat) in let data () = - let stat = OS.Memory.quick_stat () in + let stat = stat () in Data.v [ uint "memory heap words" stat.heap_words ; uint "memory live words" stat.live_words @@ -264,8 +265,8 @@ module Make (T : Mirage_time.S) (P : Mirage_clock.PCLOCK) (S : Tcpip.Stack.V4V6) Lwt.return_unit) >>= fun () -> S.TCP.close f) - let create ?(interval = 10) ?hostname dst ?(port = 8094) ?(listen_port = 2323) - ?(memtrace_port = 4242) ?(sampling_rate = 1e-4) stack = + let create ?(interval = 10) ?(quick = true) ?hostname dst ?(port = 8094) + ?(listen_port = 2323) ?(memtrace_port = 4242) ?(sampling_rate = 1e-4) stack = S.TCP.listen (S.tcp stack) ~port:memtrace_port (fun f -> (* only allow a single tracing client *) @@ -285,8 +286,7 @@ module Make (T : Mirage_time.S) (P : Mirage_clock.PCLOCK) (S : Tcpip.Stack.V4V6) Metrics.set_reporter reporter; Metrics.enable_all (); Metrics_lwt.init_periodic (fun () -> T.sleep_ns (Duration.of_sec interval)); - Metrics_lwt.periodically (OS.MM.malloc_metrics ~tags:Metrics.Tags.[])[@warning "-3"]; - Metrics_lwt.periodically (memory_metrics ~tags:Metrics.Tags.[]); + Metrics_lwt.periodically (memory_metrics ~quick ~tags:Metrics.Tags.[]); let host = match hostname with None -> [] | Some host -> [vmname host] in Lwt.async (timer_loop get_cache host interval stack (dst, port)); create_listener stack listen_port diff --git a/src/mirage_monitoring.mli b/src/mirage_monitoring.mli index 6435666..bf66fd3 100644 --- a/src/mirage_monitoring.mli +++ b/src/mirage_monitoring.mli @@ -7,14 +7,17 @@ val vmname : string -> Metrics.field module Make (T : Mirage_time.S) (P : Mirage_clock.PCLOCK) (S : Tcpip.Stack.V4V6) : sig - val create : ?interval:int -> ?hostname:string -> Ipaddr.t -> ?port:int -> - ?listen_port:int -> ?memtrace_port:int -> ?sampling_rate:float -> S.t -> unit - (** [create ~interval ~hostname ip ~port ~listen_port ~memtrace_port ~sampling_rate stack] + val create : ?interval:int -> ?quick:bool -> ?hostname:string -> Ipaddr.t -> + ?port:int -> ?listen_port:int -> ?memtrace_port:int -> + ?sampling_rate:float -> S.t -> unit + (** [create ~interval ~quick ~hostname ip ~port ~listen_port ~memtrace_port ~sampling_rate stack] initiates monitoring on [stack] for the unikernel. The metrics are reported every [interval] (defaults to 10) seconds to [ip] on [port] (defaults to 8094) via TCP using the influxd wire protocol. On [listen_port] (defaults to 2323) a TCP connection can be initiated to adjust the log level and enable and disable metrics sources. On [memtrace_port] (defaults to 4242) a single TCP client can connect simultaneously to receive a [Gc.Memprof] - trace. The [sampling_rate] defaults to [1e-4]. *) + trace. The [sampling_rate] defaults to [1e-4]. If [quick] is provided + and [false] (defaults to [true]), [Solo5_os.Memory.stat] is used, + otherwise [Solo5_os.Memory.quick_stat] is used. *) end