From 5abdb6810fb8ffb581c40d5ecb0aa59d02813cfb Mon Sep 17 00:00:00 2001 From: Sventimir Date: Thu, 25 Jan 2024 13:54:04 +0100 Subject: [PATCH] Add system/resource usage info to status reports. --- src/lib/node_status_service/dune | 1 + .../node_status_service.ml | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/lib/node_status_service/dune b/src/lib/node_status_service/dune index d18ccef9ea08..15e0d1b721db 100644 --- a/src/lib/node_status_service/dune +++ b/src/lib/node_status_service/dune @@ -5,6 +5,7 @@ (libraries ;; opam libraries core + core.linux_ext cohttp-async async core_kernel diff --git a/src/lib/node_status_service/node_status_service.ml b/src/lib/node_status_service/node_status_service.ml index 6a9de7d9292c..55ecfad20236 100644 --- a/src/lib/node_status_service/node_status_service.ml +++ b/src/lib/node_status_service/node_status_service.ml @@ -49,6 +49,17 @@ type block = } [@@deriving to_yojson] +type sysinfo = + { uptime : string + ; load : int + ; total_ram : int64 + ; free_ram : int64 + ; total_swap : int64 + ; free_swap : int64 + ; procs : int + } +[@@deriving to_yojson] + type node_status_data = { version : int ; block_height_at_best_tip : int @@ -72,6 +83,7 @@ type node_status_data = ; pubsub_msg_received : gossip_count ; pubsub_msg_broadcasted : gossip_count ; received_blocks : block list + ; sysinfo : sysinfo } [@@deriving to_yojson] @@ -179,6 +191,32 @@ let start ~logger ~node_status_url ~transition_frontier ~sync_status ~chain_id let sync_status = sync_status |> Mina_incremental.Status.Observer.value_exn in + let sysinfo = + match Linux_ext.Sysinfo.sysinfo with + | Ok sysinfo -> + let open Int64 in + let info = sysinfo () in + let mem_unit = of_int info.mem_unit in + { uptime = Time.Span.to_string info.uptime + ; load = info.load15 + ; total_ram = of_int info.total_ram * mem_unit + ; free_ram = of_int info.free_ram * mem_unit + ; total_swap = of_int info.total_swap * mem_unit + ; free_swap = of_int info.free_swap * mem_unit + ; procs = info.procs + } + | Error e -> + [%log error] "Failed to get sysinfo: $error" + ~metadata:[ ("error", `String (Error.to_string_hum e)) ] ; + { uptime = "" + ; load = 0 + ; total_ram = 0L + ; free_ram = 0L + ; total_swap = 0L + ; free_swap = 0L + ; procs = 0 + } + in [%log info] "About to send bandwidth request to libp2p" ; match%bind Mina_networking.bandwidth_info network with | Ok @@ -352,6 +390,7 @@ let start ~logger ~node_status_url ~transition_frontier ~sync_status ~chain_id ; is_valid = true ; reason_for_rejection = None } ) + ; sysinfo } in reset_gauges () ;