I have written some checks for both esx 25x and esx3.<br><br>These should probably be re-written at some stage, just haven't taken the time to yet, but I hope you get some ideas.<br><br>For ESX 3.0.1 and up you can take the OO approach with VMPerl (See example one) [it's very slow]. I say use
3.0.1 because although the sdk manual says these methods are supported in esx 3.0.0 there seem to be some problems with VmPerl that are fixed in 3.0.1.<br><br>Or you can do most of this stuff by parsing the /proc nodes (see example 2 and 3 below)
<br><br>EX 1.<br>use VMware::VmPerl;<br>use VMware::VmPerl::VM;<br>use VMware::VmPerl::ConnectParams;<br>use strict;<br><br>my @list_of_cfg = </proc/vmware/vm/*/names>; foreach (@list_of_cfg) {<br> my $file_info = `cat $_`;
<br> my @get_vmx_info = split(/\s+/,$file_info);<br> my $cfg_path = $get_vmx_info[2];<br> $cfg_path =~ s/cfgFile.//g;<br> $cfg_path =~ s/\"//g;<br> #print "$cfg_path\n"; }
<br><br> my $connect_params = VMware::VmPerl::ConnectParams::new;<br> my $vm = VMware::VmPerl::VM::new();<br> my $i;<br> if (!$vm->connect($connect_params, $cfg_path)) {<br> my ($error_number, $error_string) = $vm->get_last_error();
<br> undef $vm;<br> die "Could not connect to vm: Error $error_number: $error_string\n";<br> }<br><br> my $name1 = $vm->get_config('displayName');<br> my $mem = $vm->get_config('memsize');
<br> my $OS = $vm->get_config('guestOS');<br> my $mem_active = $vm->get_resource('mem.active');<br> my $mem_ovhd = $vm->get_resource('mem.overhd');<br> my $cpu = $vm->get_resource('
cpu.number');<br> my $mem_swap_in = $vm->get_resource('mem.swapin');<br> my $mem_shared = $vm->get_resource('mem.shared');<br><br><br> print "\n--------------------------------------------------------------- ------------\n";
<br> print "\tMachine Name is: $name1\n";<br> print "\tMachine has: $mem MB RAM\n";<br> print "\tOS: $OS\n";<br> print "\tNum cpu's: $cpu CPU\n";<br>
print "\t--------------------stats--------------------\n";<br> for($i=0; $i<$cpu; $i++) {<br><br> my $usedsec = $vm->get_resource("cpu.${i}.usedsec");<br><br> print "\tUsed vmkernel cpu time for cpu${i}: $usedsec (sec)\n";
<br><br>}<br> print "\tMem swapped in: $mem_swap_in\n";<br> print "\tMem active: $mem_active\n";<br> print "\tMem overhead: $mem_ovhd\n";<br> print "\tMem shared: $mem_shared\n"; }
<br><br>EX2 This gets the swapped/swptgt from /proc/vmware/sched/mem This should work for esx 25x and 3x. (haven't really experimented much though)<br><br>open (INPUT, $proc_vmware_mem) || die "Could not open the file $proc_vmware_mem. Exiting";
<br><br>my @proc_mem_details=<INPUT>;<br><br>close INPUT;<br>my $lastline = $#proc_mem_details;<br>$lastline--;<br><br>#print "LAST_LINE=$lastline\n";<br># The data we're concerned with is located between line 16 and last line -1 my @vm_details=@proc_mem_details[16..$lastline];
<br><br>foreach my $vm_instance (@vm_details)<br>{<br> # We now need to break down the fields for each instance<br> # Replace the space with a definable symbol<br> $vm_instance=~s/\ +/-/g;
<br> $vm_instance=~s/\/-/:/g;<br> $vm_instance=~s/\//:/g;<br> $vm_instance=~s/:/-/g;<br> my @vm_instance_details=split(/-/,$vm_instance);<br><br> my $vm_id=$vm_instance_details[1];<br> my $size=$vm_instance_details[5];
<br> my $sizetgt=$vm_instance_details[6];<br> $sizetgt=~ s/\///g;<br> my $memctl=$vm_instance_details[7];<br> my $mctltgt=$vm_instance_details[8];<br> $mctltgt=~ s/\///g;<br> # We will get the actual name of the vmware instance referenced by vmid from
<br> my $vm_name_detail=`cat /proc/vmware/vm/$vm_id/names`;<br> my @vm_name_details=split(/\ /,$vm_name_detail);<br> my $vm_name=$vm_name_details[$#vm_name_details];<br> $vm_name=~ s/\"//g;
<br> $vm_name=~ s/displayName\=//g;<br> chomp $vm_name;<br><br> my $percentage=($sizetgt/$size);<br> $percentage=sprintf "%2d", 100 *$percentage;<br><br> # Now check the stats
<br> if ($percentage > $paging_threshold){<br> print "ERROR\t-\tThe VM $vm_name is exceeding the allocated paging threshold ($percentage\%/$paging_threshold\%)\n";<br> $num_in_error++;
<br> }else{<br> print "The VM $vm_name is within the allocated paging threshold ($percentage\%/$paging_threshold\%)\n";<br><br> }<br>}<br><br>if ($num_in_error gt 0){<br> exit(255);
<br>}else{<br> exit(0);<br>}<br><br>EX3<br>This takes a look at the disk q length to the luns(and some other info), sleeps for a defined interval, runs the check again and compares the values<br><br>#!/usr/bin/perl -w
<br>use strict;<br><br>my @vmhba_ar = < /proc/vmware/scsi/vmhba*/?:* >; my (@outer_vmfs_contents, @outer_vmhba_ar, @r1, @r2, @vmfs_subdirs); my @bigger = (\@r1, \@r2); my $counter=0; my $check_int=2; my $threshold=3; my $num_in_error;
<br><br>my $lastline_global = $#bigger;<br><br>my $dir = "/vmfs/volumes";<br>opendir(VMFS, $dir) || die "cant open $dir $!\n"; my @vmfs_contents = readdir VMFS; close VMFS; chdir $dir;<br><br><br>foreach (@vmfs_contents) {
<br> if (-l $_ && ! m/^\./ ) {<br> chomp;<br> push @vmfs_subdirs, $_;<br> my @smaller = `sudo /usr/sbin/vmkfstools -Ph $_`;<br> push @outer_vmfs_contents, \@smaller; } }<br><br>
foreach (@bigger) {<br> $counter++;<br> foreach (@vmhba_ar) {<br> my @get_name=split(/scsi/,$_);<br> my $name=$get_name[1];<br> $name =~ s/\//:/g;<br> $name =~ s/^\://g;
<br><br> open(INPUT, $_) || die "cant open $_ $!\n";<br> my @temp=<INPUT>;<br> close INPUT;<br> my $lastline = $#temp;<br> my $line_of_interest = $temp[$lastline];
<br> chomp $line_of_interest;<br> if ($counter le $lastline_global) {<br> push @r1, $line_of_interest; }<br> else {<br> push @r2, $line_of_interest; }
<br><br>} if ($counter le $lastline_global) {<br> sleep $check_int; }<br>}<br><br># This wi<br>grep {<br> my @get_qd_r1=split(/\s+/,$r1[$_]);<br> my $qd_r1=$get_qd_r1[3];<br> my @get_qd_r2=split(/\s+/,$r2[$_]);
<br> my $qd_r2=$get_qd_r2[3];<br> my $press = ($qd_r2 - $qd_r1);<br> if ($press <= $threshold) {<br> push @outer_vmhba_ar, $r2[$_]; }<br> else { my $string = "WARNING - Q'D IO -> \t\t $r2[$_] \n" ;
<br> push @outer_vmhba_ar, $string; <br> $num_in_error++ ; }<br>} 0..$#r1;<br><br>grep {<br> print "\n", @{$outer_vmfs_contents[$_]}, $outer_vmhba_ar[$_], "\n\n"; } 0..$#outer_vmfs_contents;
<br><br>if ($num_in_error gt 0){<br> exit(255);<br>}else{<br> exit(0);<br>}<br><br><br>I'll get round to cleaning these up and making them available at some stage. I've been very lazy though and just left them as is.
<br><br>Hope you get some ideas from these.<br><br>Chris<br><br>