Skip to content

Commit

Permalink
CP-44533 Add running vCPU and running domain of host into rrdd
Browse files Browse the repository at this point in the history
Signed-off-by: Lunfan Zhang <[email protected]>
  • Loading branch information
LunfanZhang committed Dec 22, 2023
1 parent 01dfc98 commit 7764955
Showing 1 changed file with 40 additions and 15 deletions.
55 changes: 40 additions & 15 deletions ocaml/xcp-rrdd/bin/rrdd/xcp_rrdd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -359,26 +359,39 @@ let dss_loadavg () =
)
]

let rec sum acc n f =
match n with n when n >= 0 -> sum (acc + f n) (n - 1) f | _ -> acc

let count_vcpus pred domains xc =
List.fold_left
(fun acc (dom, _, domid) ->
sum acc dom.Xenctrl.max_vcpu_id (fun id ->
let vcpuinfo = Xenctrl.domain_get_vcpuinfo xc domid id in
if pred vcpuinfo then
1
else
0
)
)
0 domains

let count_running_domain domains =
List.fold_left
(fun count (dom, _, _) -> if dom.Xenctrl.running then count + 1 else count)
0 domains

let dss_hostload xc domains =
let physinfo = Xenctrl.physinfo xc in
let pcpus = physinfo.Xenctrl.nr_cpus in
let rec sum acc n f =
match n with n when n >= 0 -> sum (acc + f n) (n - 1) f | _ -> acc
in

let load =
List.fold_left
(fun acc (dom, _, domid) ->
sum 0 dom.Xenctrl.max_vcpu_id (fun id ->
let vcpuinfo = Xenctrl.domain_get_vcpuinfo xc domid id in
if vcpuinfo.Xenctrl.online && not vcpuinfo.Xenctrl.blocked then
1
else
0
)
+ acc
)
0 domains
count_vcpus
(fun ctrl -> ctrl.Xenctrl.online && not ctrl.Xenctrl.blocked)
domains xc
in

let running_domains = count_running_domain domains in

let load_per_cpu = float_of_int load /. float_of_int pcpus in
[
( Rrd.Host
Expand All @@ -390,6 +403,18 @@ let dss_hostload xc domains =
~value:(Rrd.VT_Float load_per_cpu) ~min:0.0 ~ty:Rrd.Gauge ~default:true
()
)
; ( Rrd.Host
, Ds.ds_make ~name:"running_vcpus" ~units:"(fraction)"
~description:"The total number of running vCPU per host"
~value:(Rrd.VT_Int64 (Int64.of_int load))
~min:0.0 ~ty:Rrd.Gauge ~default:true ()
)
; ( Rrd.Host
, Ds.ds_make ~name:"running_domains" ~units:"(fraction)"
~description:"The total number of running domain per host"
~value:(Rrd.VT_Int64 (Int64.of_int running_domains))
~min:0.0 ~ty:Rrd.Gauge ~default:true ()
)
]

(*****************************************************)
Expand Down

0 comments on commit 7764955

Please sign in to comment.