Quantcast
Channel: VMware Communities : Discussion List - vSphere Client SDK
Viewing all articles
Browse latest Browse all 2218

Unable to query overallCpuUsage Counter (SDK Web Service) ?

$
0
0

Hi Folks,


I am working on a Monitor solution and came across a issue I'm struggling to resolve. Initially, the idea was to use Cacti to monitor ESX using SNMP. That SNMP part idea soon disappeared when I realised the favoured method for monitoring was the SDK webservice.

 

After installing cacti, and vcli and its dependencies I got hold of some scripts and gave them a whirl.  The datastore counters work fine, the VM counters wok fine, but the ESX host counters don't seem to be working.

 

When running the ESX script it errors on line 20 with

"Can't call method "summary" on an undefined value at <scriptPath>/esxistats_cpu.pl line 20 .


When I query VM using the same script with slight changes, it works fine.

overallCpuUsage:17

 

I tried researching the issue further and came across https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/index-properties.html which confirmed the paths I'm trying to query are correct.

 

If someone out there is reading this and understands why its happening or maybe even how to fix it, please let me know!

 

Many thanks in Avance

The ESX Script:

To Invoke use:  <pathToPerl>/perl <scriptPath>/esxistats_mem.pl --url https://<ESXServer>/sdk/webService --username <username> --password <password> --esxiname '<esxiname>'

#!/usr/bin/perl -w
use strict;
use warnings;
use VMware::VIRuntime;
use VMware::VILib;
$SIG{__DIE__} = sub{Util::disconnect()};
$Util::script_version = "1.0";
my %opts = (   esxiname => {      type => "=s",      help => "ESXi Name as it appears in vCenter",      required => 1,   },
);
Opts::add_options(%opts);
Opts::parse();
Opts::validate(\&validate);
Util::connect();
my $esxi = Vim::find_entity_view(view_type => 'HostSystem', filter => {name => Opts::get_option('esxiname')}, properties => ['summary']);
my $overallCpuUsage = $esxi->summary->quickStats->overallCpuUsage;
printf("overallCpuUsage:%d \n", $overallCpuUsage);
Util::disconnect();
sub validate { return 1; }


The VM Script

To Invoke use:  <pathToPerl>/perl <scriptPath>/esxistats_mem.pl --url https://<ESXServer>/sdk/webService --username <username> --password <password> --vmname '<vmname>'

#!/usr/bin/perl -w
use strict;
use warnings;
use VMware::VIRuntime;
use VMware::VILib;
$SIG{__DIE__} = sub{Util::disconnect()};
$Util::script_version = "1.0";
my %opts = (   vmname => {      type => "=s",      help => "VM Name as it appears in vCenter",      required => 1,   },
);
Opts::add_options(%opts);
Opts::parse();
Opts::validate(\&validate);
Util::connect();
my $vm = Vim::find_entity_view(view_type => 'VirtualMachine', filter => {name => Opts::get_option('vmname')}, properties => ['summary']);
my $overallCpuUsage = $vm->summary->quickStats->overallCpuUsage;
printf("overallCpuUsage:%d \n", $overallCpuUsage);
Util::disconnect();
sub validate { return 1; }

Viewing all articles
Browse latest Browse all 2218

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>