ESXi Host and VM Monitoring with Perl SDK

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Post Reply
Boyer1701
Posts: 3
Joined: Fri Apr 05, 2013 4:50 pm

ESXi Host and VM Monitoring with Perl SDK

Post by Boyer1701 »

Hey everyone,

There have been posts in the past about monitoring ESXi hosts / clusters / and VMs from Cacti, but none have been extremely exhaustive and inclusive. The one post linked to a website that was in french and I couldn't understand the flow to get those scripts to work, and many were built for ESX 3 or Nagios.
This community has been a wealth of resources in the past for me so I thought I would share my work here for others as well, and maybe someone could help me tweak it to be even better.

I’m afraid I don’t know much about exporting templates, so I’ve just uploaded the scripts themselves and outlines a few steps to get them to work here in this post.
The VMware Vi Perl SDK 5 with all installed CPAN modules is required. I have Cacti installed on a linux system, so if you’re running Windows you will have to adapt portions of this.

Create a new data input method of type “Script/Command”. Use the following for the “Input String” (Adapt for your environment accordingly):

/usr/bin/perl <path_cacti>/scripts/esxistats_mem.pl --url https://<vcenter>/sdk/webService --username <username> --password <password> --esxiname '<esxiname>'

Add the following Input Fields:

Code: Select all

Name		Field Order	Friendly Name
vcenter	1		vCenter FQDN or IP Address
username	2		Username to login to vCenter
password	3		Password to login to vCenter
esxiname	4		Name of the ESXi host as it appears in vCenter
From here you will need to create your associated Data Templates and then Graph Templates.

I have a couple of issues however. For the user account that accesses vCenter we use Active Directory. I created a new service account in AD and granted it read only permission for use in these scripts. In order to get the script to work I have to put the username in the format “DOMAIN\USERNAME”. Whenever I create a new graph Cacti will drop the slash and in the poller cache it will appear as just “DOMAINUSERNAME”. I have tried adding two slashes but the result is the same. Any suggestions?

Also, the Perl SDK execution is painfully slow. Prior to adding these in my poller runtime was just above 30 seconds (see below graph for runtime):

Image

Now I am hovering around 200 seconds. Does anyone have any Perl script knowledge they can use to help me cut down on execution time? Part of it is the SDK with finding the actual objects and populating the views, which I have cut down on by limiting what properties are pulled from vCenter, but the execution is still too long for my liking.

Hope people find this useful, and if anyone has any suggestions on how to improve the scripts please let me know!! Eventually I would like to add the ability to graph Cluster resources, but I will need to get a better understanding of the Perl SDK first :D

Here are some screenshots:

Datastore Usage
Image

ESXi CPU and Memory
Image
Image

VM CPU and Memory
Image
Image

Config Screenshots
Image
Image
Image
Attachments
vmstats_mem.pl
(1.11 KiB) Downloaded 737 times
vmstats_cpu.pl
(911 Bytes) Downloaded 598 times
esxistats_mem.pl
(1.04 KiB) Downloaded 555 times
esxistats_cpu.pl
(951 Bytes) Downloaded 587 times
datastore_usage.pl
(1.02 KiB) Downloaded 621 times
UUseeU
Posts: 5
Joined: Mon Mar 11, 2013 9:53 pm

Re: ESXi Host and VM Monitoring with Perl SDK

Post by UUseeU »

Could you make these graph percentage? And I need IO NET graph.
Boyer1701
Posts: 3
Joined: Fri Apr 05, 2013 4:50 pm

Re: ESXi Host and VM Monitoring with Perl SDK

Post by Boyer1701 »

UUseeU wrote:Could you make these graph percentage? And I need IO NET graph.
I'm still trying to find in the SDK the properties from the views to find the network I/O. If someone knows them let me know and I can get a script for it.

You can make these percentages without issue, you'd just need to change the output to a single value and then do the calculations in the perl script (don't forget to update the data sources). For example with the ESXi memory usage:

Code: Select all

printf("memPercent:%d \n", ($overallMemoryUsage / ($memorySize / 1024 / 1024)));
jimbobrown
Posts: 2
Joined: Tue May 21, 2013 2:57 pm

Re: ESXi Host and VM Monitoring with Perl SDK

Post by jimbobrown »

This is really helpful, but I'm still missing a few things. Can you export your templates by following the steps below?

  • In the console, click Export Templates on the left-hand side below "Import/Export"
  • From the topmost dropdown, select Data Template
    • Select each of the VMware - ESXi Stats from the Data Template to Export dropdown
    • Make sure Include Dependencies is selected, and choose Save File Locally
  • Rinse and repeat for the Graph templates


Feel free to edit out any passwords by opening the XML in notepad/vi/your favorite text editor.

Those would be immensely appreciated!
stormonts
Cacti User
Posts: 349
Joined: Tue Mar 31, 2009 10:05 am

Re: ESXi Host and VM Monitoring with Perl SDK

Post by stormonts »

Looks like the newest version of dropped the new version of vSphere. We had this working, but after a VSphere upgrade, we not see the following.

Running this:

Code: Select all

/usr/bin/perl /usr/local/cacti-0.8.8a/scripts/esxistats_cpu.pl --url https://vcenter.domain.com/sdk/webService --username cactiuser --password somepassword --esxiname server.domain.com
Give this:

Code: Select all

Server version unavailable at 'https://vcenter.domain.com:443/sdk/vimService.wsdl' at /usr/local/perl-5.16.2/lib/5.16.2/VMware/VICommon.pm line 545, <STDIN> line 1.
Going to that https:// address noted returns this:

Code: Select all

<!--
   Copyright 2005-2013 VMware, Inc.  All rights reserved.
-->
<definitions targetNamespace="urn:vim25Service">
    <import location="vim.wsdl" namespace="urn:vim25"/>
    <service name="VimService">
        <port binding="interface:VimBinding" name="VimPort">
            <soap:address location="https://localhost/sdk/vimService"/>
        </port>
    </service>
</definitions>
Can anyone still get this to work?
hlepesant
Posts: 2
Joined: Mon Sep 30, 2013 2:23 am

Re: ESXi Host and VM Monitoring with Perl SDK

Post by hlepesant »

Edit the scripts and add this line at the begining :

Code: Select all

$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
victimist
Posts: 15
Joined: Mon Nov 25, 2013 7:36 am

Re: ESXi Host and VM Monitoring with Perl SDK

Post by victimist »

Hi Guys

Great Post - Fingers Crossed i can get it Working!

This post mentions that "The VMware Vi Perl SDK 5 with all installed CPAN modules is required".

Could you please confirm if this is required on the Vcenter Server or Cacti Server?

Any chance of a pointer as to where / how to go about getting this?

Thanks

Vic
victimist
Posts: 15
Joined: Mon Nov 25, 2013 7:36 am

Re: ESXi Host and VM Monitoring with Perl SDK

Post by victimist »

Figured out it needs to be on the Cacti Server for those who are stuck ...

The file needed is ...
VMware-vSphere-Perl-SDK-5.0.0-422456.x86_64.tar.gz (untar)

Make sure you have all the pre-reqs :
yum install make openssl openssl-devel cpan perl-XML-LibXML perl-Crypt-SSLeay perl-Class-MethodMaker libxml2-dev e2fsprogs-dev configure gcc libuuid-devel

Now install as described in : http://pubs.vmware.com/vsphere-50/index ... l.4.5.html or http://www.vmware.com/support/developer ... nstall.pdf (pg. 13)


Please could someone export the templates ... ?!
victimist
Posts: 15
Joined: Mon Nov 25, 2013 7:36 am

Re: ESXi Host and VM Monitoring with Perl SDK

Post by victimist »

hlepesant wrote:Edit the scripts and add this line at the begining :

Code: Select all

$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;


Have tried adding the line suggested above, but still i get the Server Version error.

Am running CactiEZ0.7 trying to Query ESX 5.0 U1

Have also added the variable to the enviroment:
export PERL_LWP_SSL_VERIFY_HOSTNAME=0

I found another post suggesting to add: PERL_NET_HTTPS_SSL_SOCKET_CLASS=Net:SSL

Removed and reintsalled vmwarecli but still it doesnt want to connect.

Completely at a loss ... Could someone please help?
victimist
Posts: 15
Joined: Mon Nov 25, 2013 7:36 am

Re: ESXi Host and VM Monitoring with Perl SDK

Post by victimist »

Boyer1701 wrote:Hey everyone,

There have been posts in the past about monitoring ESXi hosts / clusters / and VMs from Cacti, but none have been extremely exhaustive and inclusive. The one post linked to a website that was in french and I couldn't understand the flow to get those scripts to work, and many were built for ESX 3 or Nagios.
This community has been a wealth of resources in the past for me ...
Thanks for Sharing Boyer1701

I have finally got things working (when you dont use a stripped down Linux Distro - Moved from CactiEZ to Full Blown CentOS).

Of the 5 Scripts, 3 work, but 2 Fail. The 2 that fail are the ESX Scripts that check the host. I suspect the property may have moved, but i have no way of knowing where to.

When i run the esxistats_cpu.pl i get "Can't call method "summary" on an undefined value at /var/www/html/cacti/scripts/esxistats_cpu.pl line 38.
"

This Line is : my $overallCpuUsage = $esxi->summary->quickStats->overallCpuUsage;

The confusing bit to me is, Is $esxi undefined or is $overallCpuUsage undefined because it cant find $esxi->summary->quickStats->overallCpuUsage;

Have you come across this before??

Thanks

vic
victimist
Posts: 15
Joined: Mon Nov 25, 2013 7:36 am

Re: ESXi Host and VM Monitoring with Perl SDK

Post by victimist »

It all works when you query vCenter

Beware of this dependency ... It caught me out!
User avatar
phalek
Developer
Posts: 2838
Joined: Thu Jan 31, 2008 6:39 am
Location: Kressbronn, Germany
Contact:

Re: ESXi Host and VM Monitoring with Perl SDK

Post by phalek »

Hi

In order to improve the performance of the script significantly, you should think about caching mechanisms.

I.e. instead of doing this:

- connect to VC
- get info for VM
- disconnect from VC
(repeat for all VMs)

try implementing this instead:
if cache expired do the following:
- connect to VC
- get info for ALL VMs
- store info into Cache
- disconnect from VC

Now ( if cache is valid ):
- get info for VM from Cache

You would remove the connection/disconnection part from the SDK and therefore improve performance of the script especially when monitoring several VMs.

You could use the Cache module for this in Perl: http://search.cpan.org/~jswartz/Cache-C ... e/Cache.pm
Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests