Skip to content

Commit

Permalink
Add system/resource usage info to status reports.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sventimir committed Jan 26, 2024
1 parent 28ad233 commit 5abdb68
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib/node_status_service/dune
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
(libraries
;; opam libraries
core
core.linux_ext
cohttp-async
async
core_kernel
Expand Down
39 changes: 39 additions & 0 deletions src/lib/node_status_service/node_status_service.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 () ;
Expand Down

0 comments on commit 5abdb68

Please sign in to comment.