minor cleanup: stats type
This commit is contained in:
parent
f3c67f626a
commit
46548418cd
|
@ -199,7 +199,7 @@ let rec read_sock_write_tcp c ?fd addr addrtype =
|
|||
end else
|
||||
let name = string_of_id hdr.Vmm_asn.id in
|
||||
let ru = P.encode_ru name ru in
|
||||
let vmm = match vmm with [] -> [] | _ -> [ P.encode_vmm name vmm ] in
|
||||
let vmm = match vmm with None -> [] | Some xs -> [ P.encode_vmm name xs ] in
|
||||
let taps = List.map (P.encode_if name) ifs in
|
||||
let out = (String.concat ~sep:"\n" (ru :: vmm @ taps)) ^ "\n" in
|
||||
Logs.debug (fun m -> m "writing %d via tcp" (String.length out)) ;
|
||||
|
|
|
@ -211,37 +211,26 @@ type stats_cmd = [
|
|||
| `Stats_add of int * string list
|
||||
| `Stats_remove
|
||||
| `Stats_subscribe
|
||||
| `Stats_data of rusage * (string * int64) list * ifdata list
|
||||
| `Stats_data of stats
|
||||
]
|
||||
|
||||
let pp_stats_cmd ppf = function
|
||||
| `Stats_add (pid, taps) -> Fmt.pf ppf "stats add: pid %d taps %a" pid Fmt.(list ~sep:(unit ", ") string) taps
|
||||
| `Stats_remove -> Fmt.string ppf "stat remove"
|
||||
| `Stats_subscribe -> Fmt.string ppf "stat subscribe"
|
||||
| `Stats_data (ru, vmm, ifs) -> Fmt.pf ppf "stats data: %a %a %a"
|
||||
pp_rusage ru
|
||||
pp_vmm vmm
|
||||
Fmt.(list ~sep:(unit "@.@.") pp_ifdata) ifs
|
||||
| `Stats_data stats -> Fmt.pf ppf "stats data: %a" pp_stats stats
|
||||
|
||||
let stats_cmd =
|
||||
let f = function
|
||||
| `C1 (pid, taps) -> `Stats_add (pid, taps)
|
||||
| `C2 () -> `Stats_remove
|
||||
| `C3 () -> `Stats_subscribe
|
||||
| `C4 (ru, vmm, ifdata) ->
|
||||
let vmm = match vmm with None -> [] | Some vmm -> vmm
|
||||
and ifdata = match ifdata with None -> [] | Some ifs -> ifs
|
||||
in
|
||||
`Stats_data (ru, vmm, ifdata)
|
||||
| `C4 (ru, ifs, vmm) -> `Stats_data (ru, vmm, ifs)
|
||||
and g = function
|
||||
| `Stats_add (pid, taps) -> `C1 (pid, taps)
|
||||
| `Stats_remove -> `C2 ()
|
||||
| `Stats_subscribe -> `C3 ()
|
||||
| `Stats_data (ru, vmm, ifdata) ->
|
||||
let vmm = match vmm with [] -> None | xs -> Some xs
|
||||
and ifs = match ifdata with [] -> None | xs -> Some xs
|
||||
in
|
||||
`C4 (ru, vmm, ifs)
|
||||
| `Stats_data (ru, ifs, vmm) -> `C4 (ru, vmm, ifs)
|
||||
in
|
||||
Asn.S.map f g @@
|
||||
Asn.S.(choice4
|
||||
|
@ -252,12 +241,11 @@ let stats_cmd =
|
|||
(explicit 2 null)
|
||||
(explicit 3 (sequence3
|
||||
(required ~label:"resource_usage" ru)
|
||||
(optional ~label:"vmm_stats" @@ explicit 0
|
||||
(required ~label:"ifdata" (sequence_of ifdata))
|
||||
(optional ~label:"vmm_stats"
|
||||
(sequence_of (sequence2
|
||||
(required ~label:"key" utf8_string)
|
||||
(required ~label:"value" int64))))
|
||||
(optional ~label:"ifdata" @@ explicit 1
|
||||
(sequence_of ifdata)))))
|
||||
(required ~label:"value" int64)))))))
|
||||
|
||||
let addr =
|
||||
Asn.S.(sequence2
|
||||
|
|
|
@ -30,7 +30,7 @@ type stats_cmd = [
|
|||
| `Stats_add of int * string list
|
||||
| `Stats_remove
|
||||
| `Stats_subscribe
|
||||
| `Stats_data of rusage * (string * int64) list * ifdata list
|
||||
| `Stats_data of stats
|
||||
]
|
||||
|
||||
type log_cmd = [
|
||||
|
|
|
@ -209,7 +209,9 @@ let pp_rusage ppf r =
|
|||
Fmt.pf ppf "utime %Lu.%d stime %Lu.%d maxrss %Lu ixrss %Lu idrss %Lu isrss %Lu minflt %Lu majflt %Lu nswap %Lu inblock %Lu outblock %Lu msgsnd %Lu msgrcv %Lu signals %Lu nvcsw %Lu nivcsw %Lu"
|
||||
(fst r.utime) (snd r.utime) (fst r.stime) (snd r.stime) r.maxrss r.ixrss r.idrss r.isrss r.minflt r.majflt r.nswap r.inblock r.outblock r.msgsnd r.msgrcv r.nsignals r.nvcsw r.nivcsw
|
||||
|
||||
let pp_vmm ppf vmm =
|
||||
|
||||
type vmm_stats = (string * int64) list
|
||||
let pp_vmm_stats ppf vmm =
|
||||
Fmt.(list ~sep:(unit "@,") (pair ~sep:(unit ": ") string int64)) ppf vmm
|
||||
|
||||
type ifdata = {
|
||||
|
@ -237,6 +239,13 @@ let pp_ifdata ppf i =
|
|||
Fmt.pf ppf "name %s flags %lX send_length %lu max_send_length %lu send_drops %lu mtu %lu baudrate %Lu input_packets %Lu input_errors %Lu output_packets %Lu output_errors %Lu collisions %Lu input_bytes %Lu output_bytes %Lu input_mcast %Lu output_mcast %Lu input_dropped %Lu output_dropped %Lu"
|
||||
i.name i.flags i.send_length i.max_send_length i.send_drops i.mtu i.baudrate i.input_packets i.input_errors i.output_packets i.output_errors i.collisions i.input_bytes i.output_bytes i.input_mcast i.output_mcast i.input_dropped i.output_dropped
|
||||
|
||||
type stats = rusage * vmm_stats option * ifdata list
|
||||
let pp_stats ppf (ru, vmm, ifs) =
|
||||
Fmt.pf ppf "%a@.%a@.%a"
|
||||
pp_rusage ru
|
||||
Fmt.(option ~none:(unit "no vmm stats") pp_vmm_stats) vmm
|
||||
Fmt.(list ~sep:(unit "@.@.") pp_ifdata) ifs
|
||||
|
||||
module Log = struct
|
||||
type event =
|
||||
[ `Startup
|
||||
|
|
|
@ -98,7 +98,9 @@ type rusage = {
|
|||
nivcsw : int64;
|
||||
}
|
||||
val pp_rusage : rusage Fmt.t
|
||||
val pp_vmm : (string * int64) list Fmt.t
|
||||
|
||||
type vmm_stats = (string * int64) list
|
||||
val pp_vmm_stats : vmm_stats Fmt.t
|
||||
|
||||
type ifdata = {
|
||||
name : string;
|
||||
|
@ -122,6 +124,9 @@ type ifdata = {
|
|||
}
|
||||
val pp_ifdata : ifdata Fmt.t
|
||||
|
||||
type stats = rusage * vmm_stats option * ifdata list
|
||||
val pp_stats : stats Fmt.t
|
||||
|
||||
module Log :
|
||||
sig
|
||||
type event =
|
||||
|
|
|
@ -112,7 +112,7 @@ let tick t =
|
|||
| None -> Logs.err (fun m -> m "failed to get rusage for %d" pid) ; out
|
||||
| Some ru' ->
|
||||
let stats =
|
||||
let vmm' = match vmm with None -> [] | Some xs -> List.combine !descr xs in
|
||||
let vmm' = match vmm with None -> None | Some xs -> Some (List.combine !descr xs) in
|
||||
ru', vmm', ifd
|
||||
in
|
||||
List.fold_left (fun out (id, socket) ->
|
||||
|
|
Loading…
Reference in a new issue