From 98ef5cc436d8f808c7657a3d5ae270e8b5605807 Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Fri, 3 Mar 2023 12:03:48 +0100 Subject: [PATCH] avoid dependency on mirage-solo5, conflict with mirage-solo5/mirage-xen that do not include the Memory.metrics --- mirage-monitoring.opam | 5 ++++- src/dune | 2 +- src/mirage_monitoring.ml | 19 ++----------------- src/mirage_monitoring.mli | 12 +++++------- 4 files changed, 12 insertions(+), 26 deletions(-) diff --git a/mirage-monitoring.opam b/mirage-monitoring.opam index fd4811b..4dc9a28 100644 --- a/mirage-monitoring.opam +++ b/mirage-monitoring.opam @@ -16,11 +16,14 @@ depends: [ "metrics-influx" {>= "0.2.0"} "mirage-time" {>= "2.0.0"} "tcpip" {>= "7.0.0"} - "mirage-solo5" {>= "0.9.0"} "mirage-runtime" {>= "4.3.0"} "memtrace-mirage" {>= "0.2.1.2.2"} "mirage-clock" {>= "4.0.0"} ] +conflicts: [ + "mirage-solo5" {< "0.9.2"} + "mirage-solo5" {< "8.0.2"} +] build: [ ["dune" "subst"] {dev} ["dune" "build" "-p" name "-j" jobs] diff --git a/src/dune b/src/dune index 1e4e40d..868768a 100644 --- a/src/dune +++ b/src/dune @@ -3,4 +3,4 @@ (public_name mirage-monitoring) (wrapped false) (libraries logs metrics metrics-lwt metrics-influx mirage-time mirage-clock - memtrace-mirage tcpip mirage-solo5 mirage-runtime)) + memtrace-mirage tcpip mirage-runtime)) diff --git a/src/mirage_monitoring.ml b/src/mirage_monitoring.ml index b030e03..03cee92 100644 --- a/src/mirage_monitoring.ml +++ b/src/mirage_monitoring.ml @@ -31,20 +31,6 @@ let counter_metrics ~f name = let vmname = Metrics.field ~doc:"name of the virtual machine" "vm" Metrics.String -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 = stat () in - Data.v - [ uint "memory heap words" stat.heap_words - ; uint "memory live words" stat.live_words - ; uint "memory stack words" stat.stack_words - ; uint "memory free words" stat.free_words ] - in - Src.v ~doc ~tags ~data "memory" - let get_log_levels s = let qs = String.split_on_char ',' s in let srcs = Logs.Src.list () in @@ -261,8 +247,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) ?(quick = true) ?hostname dst ?(port = 8094) - ?(listen_port = 2323) ?(memtrace_port = 4242) ?(sampling_rate = 1e-4) stack = + let create ?(interval = 10) ?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 *) @@ -282,7 +268,6 @@ 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 (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 bf66fd3..755ab6b 100644 --- a/src/mirage_monitoring.mli +++ b/src/mirage_monitoring.mli @@ -7,17 +7,15 @@ val vmname : string -> Metrics.field module Make (T : Mirage_time.S) (P : Mirage_clock.PCLOCK) (S : Tcpip.Stack.V4V6) : sig - 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] + 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] 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]. If [quick] is provided - and [false] (defaults to [true]), [Solo5_os.Memory.stat] is used, - otherwise [Solo5_os.Memory.quick_stat] is used. *) + trace. The [sampling_rate] defaults to [1e-4]. *) end