vmm_stats: allow vmmapi to fail (and report nothing), more convenient for linux code path
This commit is contained in:
parent
51d1dc63dc
commit
66df394d36
|
@ -69,15 +69,15 @@ let fill_descr ctx =
|
||||||
match !descr with
|
match !descr with
|
||||||
| [] ->
|
| [] ->
|
||||||
begin match wrap vmmapi_statnames ctx with
|
begin match wrap vmmapi_statnames ctx with
|
||||||
| None -> Error (`Msg "vmmapi_statnames failed, shouldn't happen")
|
| None ->
|
||||||
|
Logs.err (fun m -> m "vmmapi_statnames failed, shouldn't happen") ;
|
||||||
|
()
|
||||||
| Some d ->
|
| Some d ->
|
||||||
Logs.info (fun m -> m "descr are %a" Fmt.(list ~sep:(unit ",@ ") string) d) ;
|
Logs.info (fun m -> m "descr are %a" Fmt.(list ~sep:(unit ",@ ") string) d) ;
|
||||||
descr := d ;
|
descr := d
|
||||||
Ok ()
|
|
||||||
end
|
end
|
||||||
| ds ->
|
| ds ->
|
||||||
Logs.info (fun m -> m "descr are already %a" Fmt.(list ~sep:(unit ",@ ") string) ds) ;
|
Logs.info (fun m -> m "descr are already %a" Fmt.(list ~sep:(unit ",@ ") string) ds)
|
||||||
Ok ()
|
|
||||||
|
|
||||||
let add_pid t pid nics =
|
let add_pid t pid nics =
|
||||||
let name = "ukvm" ^ string_of_int pid in
|
let name = "ukvm" ^ string_of_int pid in
|
||||||
|
@ -85,27 +85,29 @@ let add_pid t pid nics =
|
||||||
| None, _ -> Error (`Msg "sysctl ifcount failed")
|
| None, _ -> Error (`Msg "sysctl ifcount failed")
|
||||||
| _, None -> Error (`Msg "vmmapi_open failed")
|
| _, None -> Error (`Msg "vmmapi_open failed")
|
||||||
| Some max_nic, Some vmctx ->
|
| Some max_nic, Some vmctx ->
|
||||||
match fill_descr vmctx with
|
fill_descr vmctx ;
|
||||||
| Error e -> Error e
|
let rec go cnt acc id =
|
||||||
| Ok () ->
|
if id > 0 && cnt > 0 then
|
||||||
let rec go cnt acc id =
|
match wrap sysctl_ifdata id with
|
||||||
if id > 0 && cnt > 0 then
|
| Some ifd when List.mem ifd.name nics ->
|
||||||
match wrap sysctl_ifdata id with
|
go (pred cnt) ((id, ifd.name) :: acc) (pred id)
|
||||||
| Some ifd when List.mem ifd.name nics ->
|
| _ -> go cnt acc (pred id)
|
||||||
go (pred cnt) ((id, ifd.name) :: acc) (pred id)
|
else
|
||||||
| _ -> go cnt acc (pred id)
|
List.rev acc
|
||||||
else
|
in
|
||||||
List.rev acc
|
let nic_ids = go (List.length nics) [] max_nic in
|
||||||
in
|
let pid_nic = IM.add pid (vmctx, nic_ids) t.pid_nic in
|
||||||
let nic_ids = go (List.length nics) [] max_nic in
|
Ok { t with pid_nic }
|
||||||
let pid_nic = IM.add pid (vmctx, nic_ids) t.pid_nic in
|
|
||||||
Ok { t with pid_nic }
|
|
||||||
|
|
||||||
let stats t pid =
|
let stats t pid =
|
||||||
try
|
try
|
||||||
let _, nics = IM.find pid t.pid_nic
|
let _, nics = IM.find pid t.pid_nic
|
||||||
and ru = IM.find pid t.pid_rusage
|
and ru = IM.find pid t.pid_rusage
|
||||||
and vmm = IM.find pid t.pid_vmmapi
|
and vmm =
|
||||||
|
try IM.find pid t.pid_vmmapi with
|
||||||
|
| Not_found ->
|
||||||
|
Logs.err (fun m -> m "failed to find vmm stats for %d" pid);
|
||||||
|
[]
|
||||||
in
|
in
|
||||||
match
|
match
|
||||||
List.fold_left (fun acc nic ->
|
List.fold_left (fun acc nic ->
|
||||||
|
|
|
@ -213,12 +213,12 @@ CAMLprim value vmmanage_sysctl_ifdata (value num) {
|
||||||
|
|
||||||
CAMLprim value vmmanage_vmmapi_open (value name) {
|
CAMLprim value vmmanage_vmmapi_open (value name) {
|
||||||
CAMLparam1(name);
|
CAMLparam1(name);
|
||||||
uerror("vmmapi_open", Nothing);
|
CAMLreturn(Val_int(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
CAMLprim value vmmanage_vmmapi_close (value name) {
|
CAMLprim value vmmanage_vmmapi_close (value name) {
|
||||||
CAMLparam1(name);
|
CAMLparam1(name);
|
||||||
uerror("vmmapi_close", Nothing);
|
CAMLreturn(Val_unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
CAMLprim value vmmanage_vmmapi_stats (value name) {
|
CAMLprim value vmmanage_vmmapi_stats (value name) {
|
||||||
|
|
Loading…
Reference in a new issue