Ad Widget

Collapse

How to get Vmware cpu overccomit value (pCPU:vCPU ratio) for a vmware cluster?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rayg00n
    Junior Member
    • Jan 2023
    • 23

    #1

    How to get Vmware cpu overccomit value (pCPU:vCPU ratio) for a vmware cluster?

    Does anybody know hot to get(calculate) the level of overcommiting cpu in a vmware cluster ?
    Cannot find appropiative perf counter or metric to obtain data via VMware REST API

    Zabbix version 6.4.2.


    Description of my problem:

    1. There is a vmware cluster with 3 esxi-nodes inside (esx-srv1,esx-srv2,esx-srv3)
    2. Vsphere and Esxi hosts have 7.0.3U version
    3. Item to collect all vCPU in a cluster is showed on a screenshot below.

    I used vmware REST API methods (https) to obtain data from url like:​

    https://<your_vsphere.ip.address>/rest/vcenter/vm?filter.power_states.1=POWERED_ON&filter.cluster s.1=<your_cluster_id>


    Result is parsed to summarize all cpu_counts of all powered VM's filtered by <your_cluster_id>

    Javascript code to make thing done:
    Code:
    parameters = JSON.parse(value);    //parsing parameters
    
    // Getting the session ID - autentication
    req = new HttpRequest();        
    req.addHeader('Authorization: Basic '+parameters.username_pass);
    resp = req.post(parameters.vcenter_url_session);
    session_id = resp.match(/(?:[a-zA-Z0-9]{32})/g);
    
    // Using session ID to obtain REST API data
    req_vm_list = new HttpRequest();
    req_vm_list.addHeader('vmware-api-session-id: '+session_id);
    resp_vm_list = req_vm_list.get(parameters.vcenter_vm_list+'&amp;filter.clusters.1='+parameters.domain_id);
    
    // Json Tranformation
    json_data = resp_vm_list;
    json_data = json_data.match(/"cpu_count":(\d.*?)}/g);
    json_data = String(json_data).replace(/"cpu_count"/g, '{"cpu_count"');
    json_data = json_data.replace(/:/g, ': ');
    json_data = '[' + json_data + ']';
    
    // Summarize of cpu_counts
    const vm_cpu_array = JSON.parse(json_data);
    
       var cpu_sum = 0;
       for (i = 0; i &lt; vm_cpu_array.length; i ++) {
          var number = parseFloat(vm_cpu_array[i].cpu_count);
          cpu_sum += number;
      }
    
    // Return
    return(cpu_sum);​
    It's works.

    4. How to get all numbers of cpu cores\threads in a vmware cluster?

    I can get all esxi-host ID's in my cluster
    +
    I know how to get total number of cpu cores or threads for a one esxi-host by using this key:

    vmware.hv.hw.cpu.threads[url,uuid]

    But how can I use this key^ inside javascript above (for..do..loop)?
    Is it possible to run simple check keys inside javascript code?

    Any help would be appreciated.
    Attached Files
    Last edited by Rayg00n; 26-05-2023, 12:21.
Working...