-
Couldn't load subscription status.
- Fork 293
CP-44533 Add running vCPU and running domain of host into rrdd #5307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CP-44533 Add running vCPU and running domain of host into rrdd #5307
Conversation
|
I passed the |
|
The local check fails because the formatter is not up-to-date, please update your local build environment, rebase your pull request on top of the latest master and retry |
ocaml/xcp-rrdd/bin/rrdd/xcp_rrdd.ml
Outdated
| ) | ||
| ] | ||
|
|
||
| (*****************************************************) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep it simple and avoid fancy comments that are difficult to reformat if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely, it can be deleted.
ocaml/xcp-rrdd/bin/rrdd/xcp_rrdd.ml
Outdated
| let rec sum acc n f = | ||
| match n with n when n >= 0 -> sum (acc + f n) (n - 1) f | _ -> acc | ||
|
|
||
| let count_vcpus condition domains xc = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Traditionally, condition is called pred or predicate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will refine it.
ocaml/xcp-rrdd/bin/rrdd/xcp_rrdd.ml
Outdated
| 0 domains | ||
|
|
||
| let count_running_domain domains = | ||
| let running_domains = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This creates garbage that could be avoided. We want to count elements in a list that fulfill a predicate.
List.fold_left (fun count (dom, _, _) -> if dom.Xenctrl.running then count +1 else count) 0 domains
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it because of the way I used creates a new List? Sorry, I don't know much about Ocaml GC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem. It's cheap to iterate over a lost and more expensive to create intermediate complex values like a new list. In my code I iterate over the list and carry a simple integer value.
8030e80 to
7764955
Compare
ocaml/xcp-rrdd/bin/rrdd/xcp_rrdd.ml
Outdated
| 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 = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In light of the discussion of count_running_domain, could this be done in a simpler, similar way? The predicate ctrl.Xenctrl.online && not ctrl.Xenctrl.blocked could be implemented in this function and not passed in from the outside and this would result in one compact function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some other statuses could be added in the future, such as ctrl.Xenctrl.blocked or ctrl.Xenctrl.running. Therefore, I believe keeping the count_running_domain will be beneficial for compatibility
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The xc can be wrapped into pred (renamed to count_vcpus_in_domain).
So basically the functions could be:
let count_vcpus_in_domain domain =
let dom, _, domid = domain in
let f vcpu_id =
let open Xenctrl in
let vcpuinfo = domain_get_vcpuinfo xc domid vcpu_id in
if vcpuinfo.online && not vcpuinfo.blocked then 1 else 0
in
sum 0 dom.Xenctrl.max_vcpu_id f
in
let vcpus =
List.map count_vcpus_in_domain domains
|> List.fold_left (+) 0
in
let count_running_domain domain =
let dom, _, _ = domain in
if dom.Xenctrl.running then 1 else 0
in
let running_domains =
List.map count_running_domain domains
|> List.fold_left (+) 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have reverted this part of change to the original to keep it simple.
7764955 to
cde5bd5
Compare
ocaml/xcp-rrdd/bin/rrdd/xcp_rrdd.ml
Outdated
| () | ||
| ) | ||
| ; ( Rrd.Host | ||
| , Ds.ds_make ~name:"running_vcpus" ~units:"(fraction)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the comment, this is a fraction. But from the calculation, this seems a count number?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
ocaml/xcp-rrdd/bin/rrdd/xcp_rrdd.ml
Outdated
| ~min:0.0 ~ty:Rrd.Gauge ~default:true () | ||
| ) | ||
| ; ( Rrd.Host | ||
| , Ds.ds_make ~name:"running_domains" ~units:"(fraction)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the comment, this is a fraction. But from the calculation, this seems a count number?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could convert fraction -> int.
However, I still have a question. Even though I've set the type of this metric as int64, I'm still receiving decimal values, such as 1.333, when I query it. Is this due to the final display of this metric being the calculated average over a time range?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the RRD will return a consolidated value:
https://docs.xenserver.com/en-us/xenserver/8/developer/sdk-guide/using-http.html#getting-xenserver-operational-metrics
You could try to change the Consolidation Functions (CF) to confirm this. By default it is average. But this should be done by RRD framework already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I think the units requires a string of unit. Like "memory_total_kib" with units "KiB", how about "running_domains" with units "domains"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, I will use domains vcpus as the units.
Signed-off-by: Lunfan Zhang <Lunfan.Zhang@cloud.com>
cde5bd5 to
c5060a1
Compare
This PR aims to add the number of running vCPU and running domain into rrdd:
new test result: