Hi Guys.
This is a long one, it took me around three to four days of searching the web, understanding how the cacti could interact with the vCentre server and poll the VM’s for the data. I then had to figure out how cacti could take this data and graph it.
The main thing to keep in mind is that cacti normally uses SNMP to retrieve data from remote hosts and graph them. You have to make a para-dime shift when thinking about data retrieval from the vCentre servers in that it uses SSL connections over HTTPS.
To start with you need to download the following zip file (scripts (attached to post)) which contains the following two files
esxiograph.sh
check_esx3.pl
These files are the core of how the data is retrieved from the vCentre infrastructure. Firstly the check_esx3.pl pearl script will be called from the esxiograph.sh script using the details specified in a certain format.
These two files will need to be uploaded to your cacti server and placed in the folder “<cacti_path>/scripts” mine was in “/var/www/cacti/scripts/”. Once they have been uploaded you will need to edit the esxiograph.sh to change where it looks for the check_esx3.pl.
nano <cacti_path>/scripts/esxiograph.sh
If you scroll down to the bottom you will see a section referencing the check_esx3.pl script, this needs to be changed to where we just placed the file as this was written for another program.
Before
io_vm)
type=io_vm
io_vm_all=`perl /usr/share/cacti/site/scripts/check_esx3.pl -H $2 -N $3 -u $4 -p $5 -l IO`
check_io_vm
;;
cpu_vm)
type=cpu_vm
cpu_vm_all=`perl /usr/share/cacti/site/scripts/check_esx3.pl -H $2 -N $3 -u $4 -p $5 -l CPU`
check_cpu_vm
;;
mem_vm)
type=mem_vm
mem_vm_all=`perl /usr/share/cacti/site/scripts/check_esx3.pl -H $2 -N $3 -u $4 -p $5 -l MEM`
check_mem_vm
;;
net_vm)
type=net_vm
net_vm_all=`perl /usr/share/cacti/site/scripts/check_esx3.pl -H $2 -N $3 -u $4 -p $5 -l NET`
check_net_vm
;;
io_vs)
type=io_vs
io_vs_all=`perl /usr/share/cacti/site/scripts/check_esx3.pl -H $2 -u $3 -p $4 -l IO`
check_io_vs
;;
cpu_vs)
type=cpu_vs
cpu_vs_all=`perl /usr/share/cacti/site/scripts/check_esx3.pl -H $2 -u $3 -p $4 -l CPU`
check_cpu_vs
;;
mem_vs)
type=mem_vs
mem_vs_all=`perl /usr/share/cacti/site/scripts/check_esx3.pl -H $2 -u $3 -p $4 -l MEM`
check_mem_vs
;;
net_vs)
type=net_vs
net_vs_all=`perl /usr/share/cacti/site/scripts/check_esx3.pl -H $2 -u $3 -p $4 -l NET`
check_net_vs
;;
After
io_vm)
type=io_vm
io_vm_all=`perl <cacti_path>/scripts/check_esx3.pl -H $2 -N $3 -u $4 -p $5 -l IO`
check_io_vm
;;
cpu_vm)
type=cpu_vm
cpu_vm_all=`perl <cacti_path>/scripts/check_esx3.pl -H $2 -N $3 -u $4 -p $5 -l CPU`
check_cpu_vm
;;
mem_vm)
type=mem_vm
mem_vm_all=`perl <cacti_path>/scripts/check_esx3.pl-H $2 -N $3 -u $4 -p $5 -l MEM`
check_mem_vm
;;
net_vm)
type=net_vm
net_vm_all=`perl <cacti_path>/scripts/check_esx3.pl -H $2 -N $3 -u $4 -p $5 -l NET`
check_net_vm
;;
io_vs)
type=io_vs
io_vs_all=`perl <cacti_path>/scripts/check_esx3.pl -H $2 -u $3 -p $4 -l IO`
check_io_vs
;;
cpu_vs)
type=cpu_vs
cpu_vs_all=`perl <cacti_path>/scripts/check_esx3.pl -H $2 -u $3 -p $4 -l CPU`
check_cpu_vs
;;
mem_vs)
type=mem_vs
mem_vs_all=`perl <cacti_path>/scripts/check_esx3.pl -H $2 -u $3 -p $4 -l MEM`
check_mem_vs
;;
net_vs)
type=net_vs
net_vs_all=`perl <cacti_path>/scripts/check_esx3.pl -H $2 -u $3 -p $4 -l NET`
check_net_vs
;;
Ctrl-x and save
Next we need to ensure Perl has been installed on the system. Depending on which distribution of Linux you are using you will need to utilize your own version of package management. For this guide I am using Ubuntu and all references will be apt-get.
apt-get install perl
Once Perl has been installed onto your system, you will need to download the VMWare-vSphere-SDK-for-Perl files from the following link (
http://communities.vmware.com/community ... e_sdk_perl), you will need a vmware.com account to retrieve the files. Then follow the mini-guide below to install the SDK kit.
Download the latest version of the vSphere SDK for Perl package from VMware support page.
In this example we use VMware-vSphere-SDK-for-Perl-4.0.0-161974.i386.tar.gz, but the instructions should apply to newer versions as well.
Upload the file to your nagios server’s /root directory
cd /root
tar xvzf VMware-vSphere-SDK-for-Perl-4.0.0-161974.i386.tar.gz
cd vmware-vsphere-cli-distrib/
./vmware-install.pl
“Creating a new vSphere CLI installer database using the tar4 format.
Installing vSphere CLI.
You must read and accept the vSphere CLI End User License Agreement to continue.
Press enter to display it.”
<ENTER>
“Read through the License Agreement”
“Do you accept? (yes/no)”
yes
“In which directory do you want to install the executable files?
[/usr/bin]”
<ENTER>
“The following Perl modules were found on the system but may be too old to work
with vSphere CLI:
Crypt::SSLeay
Compress::Zlib
The installation of vSphere CLI 4.0.0 build-161974 for Linux
completed successfully. You can decide to remove this software from your system
at any time by invoking the following command:
“/usr/bin/vmware-uninstall-vSphere-CLI.pl”.
Enjoy,
–the VMware team”
Note: “Crypt::SSLeay” and “Compress::Zlib” are not required for check_esx3 to work.
Once the SDK kit has been installed, you will need to create a ‘readonly’ user account on your vSphere system to enable the cacti server to login and retrieve the data. To do this, login to your vCentre server or use the vSphere client to login to the control panel. Once here click on the vcentre server top level and click on permissions. In here you can add your user. If you are in a Windows domain you can add the user in active directory and then add it here. When adding the user only set the permission level to ‘readonly’. Make sure that propagate is ticked so this permission is inherited by all child nodes. On the other hand you could add the permissions on each individual server / host you wish to allow readings from.
Once you have created your user you can use command line code to test that the cacti server can communicate with the vCentre server. This is done with the following commands.
First of all we will test with the check_esx.pl script to ensure that the SDK kit can login with the details and pull the required data.
perl <cacti_path>/scripts/check_esx3.pl -H <vcentre server> -N <name of virtual machine> -u <username> -p “<password>” -l NET
Please ensure that the name of the virtual machine is exactly as the vcentre sees it. In other words it is case sensitive. I have also found that you can not have spaces in your names as this will not poll. If you find any way round this, please let me know.
Once executed you should get some data returned from the server like below.
SSL_connect:before/connect initialization
SSL_connect:SSLv2/v3 write client hello A
SSL_connect:SSLv3 read server hello A
SSL_connect:SSLv3 read server certificate A
SSL_connect:SSLv3 read server certificate request A
SSL_connect:SSLv3 read server done A
SSL_connect:SSLv3 write client certificate A
SSL_connect:SSLv3 write client key exchange A
SSL_connect:SSLv3 write change cipher spec A
SSL_connect:SSLv3 write finished A
SSL_connect:SSLv3 flush data
SSL_connect:SSLv3 read server session ticket A
SSL_connect:SSLv3 read finished A
CHECK_ESX3.PL OK – “virtual machine name” net receive=0.00 KB/s, send=47.43 KB/s | net_receive=0.00KB;; net_send=47.43KB;;
This confirms that the cacti server can login with the credentials specified and it authorized to poll data for that certain machine.
There are several things to remember here, you can either poll the vCentre server or the hyper-visors directly. I have chosen to go with the vCentre server in my environment due to the fact that DRS may start to move machines around for level distribution. This would cause issues later on with graphing if I am directly polling the hyper-visors. On the other hand if you do not have a vCentre server and only hyper-visors this would be perfect. Please also not that the passwords need to be in quotations.
Moving on you will next need to test that the ./esxiograph.sh can parse the data retrieved from the check_esx3.pl and output it in a format that is easily readable by cacti’s graphing system. Please be aware before you test the next step you need to ensure that ‘bc’ is installed on the nagios server. This caused me several hours of headache not knowing why the calculation was not working. Please first install ‘bc’ with the following command.
apt-get install bc
Once this is installed you can go ahead and test the script with the following command
./<cacti_path>/scripts/esxiograph.sh net_vm <vcentre> <vm name> <username> <”password”>
Please note you will need quotation marks around the password again. If all is ok you will get another output, this time in a more cacti friendly output and also in a rate of bits per second.
SSL_connect:before/connect initialization
SSL_connect:SSLv2/v3 write client hello A
SSL_connect:SSLv3 read server hello A
SSL_connect:SSLv3 read server certificate A
SSL_connect:SSLv3 read server done A
SSL_connect:SSLv3 write client key exchange A
SSL_connect:SSLv3 write change cipher spec A
SSL_connect:SSLv3 write finished A
SSL_connect:SSLv3 flush data
SSL_connect:SSLv3 read finished A
read:8000.00 write:16000.00
This should be all you need to do in the CLI side of the installation, next we need to import a template into cacti via the web GUI to allow us to start graphing the data collected.
First of all you need to download the following cacti_host_template_vmware_esxi (attached to this post) file. Extract this to your desktop and then login to your cacti server via the web gui. Once logged in goto the console tab at the top and then goto Import Template under the Import/Export heading. Click choose file and then navigate to the extracted file on your desktop. Then click import.
Once this has imported you will need to add a device. Under the console tab again, goto devices and then add device in the top right. Fill out the description and hostname. From the dropdown menu under host template select ‘VMWare esxi’. You will need to set the downed device detection to PING and make sure all firewalls in between your cacti server and vcentre server allow ping from the cacti IP otherwise the graphs will never be created. You can ignore all other fields and click create.
Once the device has been added goto the console tab and then under heading ‘Create’ click new graph, select your vcentre as the host and you will see 8 options to choose from. The options that start with VM_ are referring to the virtual machines VS_ are referring to the virtual host server (hyper-visor). For this guide I am only concerned with ‘VM Net Load’ select this and click create. You will now have to fill out the options as you did CLI stylie. Populate the vm name (case sensitive), username, and password. Please note the password will need to be in quotation marks such as “*nyy7^%ujl” otherwise it will not work. Click create and the graph will be created.
If after a while you have no graph and receive a error from the RRD tool, I found that the Graph Template for ‘ESXi – VM Net Load’ was using CF Type Last as opposed to Average for the two data sources inbound and outbound. I believe I exported these templates with the changes made but if not you may want to check this.
Any questions, please feel free to ask.
Regards,
Lee