2014年6月25日 星期三

Monitor VMware ESXi 5.1 Host & display on Cacti

Monitor VMware ESXi 5.1 Host & display on Cacti

1.yum install make openssl openssl-devel cpan perl-XML-LibXML perl-Crypt-SSLeay perl-Class-MethodMaker libxml2-dev e2fsprogs-dev configure gcc libuuid-devel 

2.Download vSphere SDK for Perl 5.5 and then

        tar zxvf VMware-vSphere-Perl-SDK-5.5.0-1384587.x86_64.tar.gz (64bit) -C /opt
   or
        tar zxvf VMware-vSphere-Perl-SDK-5.5.0-1384587.i386.tar.gz (32bit) -C /opt


        perl /opt/vmware-vsphere-cli-distrib/vmware-install.pl

      

3.test your perl script 

#============================Script=====================================# 
#script by kent
#!/usr/bin/perl -w
# This script is a collection of esxihost cpu/mem percentage
use strict;
use warnings;
use VMware::VIRuntime;
use VMware::VILib;
$SIG{__DIE__} = sub{Util::disconnect()};
$Util::script_version = "1.0";
my @cpu;my @mem;my $ind2;my $len;my $sub;
my $cc=1;my $result="";

Opts::parse();

Opts::validate(\&validate);
Util::connect();

open(open_file,"</var/www/cacti/scripts/esxihostlist.txt");#read your esxihostname

while(<open_file>)
{
chomp;
 $ind2=index($_,".");
 $len=2;
 $sub=substr($_,$ind2-$len,$len);
my $esxi= Vim::find_entity_view(view_type => 'HostSystem',filter => {name =>$_},properties => ['summary']);
my $overallCpuUsage = $esxi->summary->quickStats->overallCpuUsage;
my $overallMemoryUsage = $esxi->summary->quickStats->overallMemoryUsage;
my $memorySize = $esxi->summary->hardware->memorySize;
$mem[$sub]=sprintf("%.1f",($overallMemoryUsage*100/($memorySize/1024/1024)));
$cpu[$sub]=sprintf("%.1f",$overallCpuUsage*100/19200);
$result=$result."cpu"."$sub".":"."$cpu[$sub]"." ";
$result=$result."mem"."$sub".":"."$mem[$sub]"." ";
$cc++;
}
print "$result\n";
#open(open_file1,">/var/www/cacti/scripts/esxiresult.txt");
#print open_file1 "$result";
Util::disconnect();
sub validate { return 1; }
#=========================esxihostlist form===============================#
ggyy-server-172024018001.net.tw
ggyy-server-172024018002.net.tw
ggyy-server-172024018003.net.tw
#======================================================================#



   






output must be the form:
 <fieldname_1>:<value_1> <fieldname_2>:<value_2> ... <fieldname_n>:<value_n>



4.Setting your Data Input Method
   



















 Input Field: your script input information( ps: username、password.....)
Output Field: your script output data 
                   (*Ensure your output field Name&Input field equal your script variable)

5.Setting your Data Template

6.Setting your Graph Template

7.Insert graph template to your device

8.create graph 
   






  

沒有留言:

張貼留言