Skip to content

Conversation

@LunfanZhang
Copy link
Collaborator

@LunfanZhang LunfanZhang commented Dec 19, 2023

This PR aims to add the number of running vCPU and running domain into rrdd:

  1. For the running vCPUs, I derive this information from 'xenctrl.vcpuinfo', where the vCPU's state is marked as 'online' and 'not blocked'. Although we could calculate it based solely on the 'running' states, I find that 'online' and 'not blocked' covers a wider range of scenarios.
  2. For the running domains, I straightforwardly derive this data from 'xenctrl.domaininfo', where the domain's state is indicated as 'running.
  3. I convert the Dom0 memory_internal_free from B to KiB, due to the official document declare the unit of this attribution is KiB, see:
    image_720

new test result:

[root@xrtuk-13-07 ~]# xe host-data-source-query data-source=running_vcpus
1.000000
[root@xrtuk-13-07 ~]# xe host-data-source-query data-source=running_domains
1.000000
[root@xrtuk-13-07 ~]# xe vm-data-source-query vm=14466515-ef55-43c7-a0ec-018994064f2e data-source=memory_internal_free
2191387.500000

@LunfanZhang
Copy link
Collaborator Author

LunfanZhang commented Dec 20, 2023

I passed the check format locally, I don't know why it failed on the remote check. Is there anyone who has permission to retrigger check format again?

@psafont
Copy link
Member

psafont commented Dec 20, 2023

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

)
]

(*****************************************************)
Copy link
Contributor

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.

Copy link
Collaborator Author

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.

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 =
Copy link
Contributor

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will refine it.

0 domains

let count_running_domain domains =
let running_domains =
Copy link
Contributor

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

Copy link
Collaborator Author

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.

Copy link
Contributor

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.

@LunfanZhang LunfanZhang force-pushed the private/luzhan_github/CP-44533 branch from 8030e80 to 7764955 Compare December 22, 2023 09:33
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 =
Copy link
Contributor

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.

Copy link
Collaborator Author

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

Copy link
Member

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

Copy link
Collaborator Author

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.

@LunfanZhang LunfanZhang force-pushed the private/luzhan_github/CP-44533 branch from 7764955 to cde5bd5 Compare December 26, 2023 02:10
()
)
; ( Rrd.Host
, Ds.ds_make ~name:"running_vcpus" ~units:"(fraction)"
Copy link
Member

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

~min:0.0 ~ty:Rrd.Gauge ~default:true ()
)
; ( Rrd.Host
, Ds.ds_make ~name:"running_domains" ~units:"(fraction)"
Copy link
Member

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?

Copy link
Collaborator Author

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?

Copy link
Member

@minglumlu minglumlu Jan 2, 2024

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.

Copy link
Member

@minglumlu minglumlu Jan 2, 2024

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"?

Copy link
Collaborator Author

@LunfanZhang LunfanZhang Jan 3, 2024

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>
@LunfanZhang LunfanZhang force-pushed the private/luzhan_github/CP-44533 branch from cde5bd5 to c5060a1 Compare January 3, 2024 09:54
@minglumlu minglumlu merged commit 53d2e8c into xapi-project:master Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants