/
esxi_cpu_mem_
executable file
·52 lines (46 loc) · 1.72 KB
/
esxi_cpu_mem_
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/perl -w
# ESXi host CPU/memory plugin for Munin by Niels Engelen
# http://www.foonet.be
use strict;
use warnings;
use VMware::VIRuntime;
use VMware::VILib;
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
my $esxihost = basename($0);
$esxihost =~ s/esxi\_cpu\_mem\_//;
my $username = Opts::set_option ('username', $ENV{'username'});
my $password = Opts::set_option ('password', $ENV{'password'});
my $url = Opts::set_option ('url', "https://$esxihost/sdk/webService");
my ($host_info);
if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
print "graph_title ESXi CPU/Memory ".$esxihost." \n";
print "graph_args --base 1000 -r --lower-limit 0 --upper-limit 100 \n";
print "graph_vlabel % \n";
print "graph_category ESXi CPU/Memory\n";
print "graph_scale no\n";
print "mem.label MEM used\n";
print "mem.draw AREA\n";
print "cpu.label CPU used\n";
exit 0;
} else {
Opts::parse();
Opts::validate();
Util::connect();
$host_info = Vim::find_entity_view(view_type => 'HostSystem', properties => ['summary.hardware', 'summary.quickStats'], filter => {'summary.runtime.connectionState' => 'connected'});
&get_host_mem_info($host_info);
&get_host_cpu_info($host_info);
Util::disconnect();
exit 0;
}
sub get_host_mem_info {
if ($host_info) {
my $percentMemoryUsed = ($host_info->{'summary.quickStats'}->overallMemoryUsage * 1024 * 1024 / $host_info->{'summary.hardware'}->memorySize) * 100;
printf "mem.value %.2f\n",$percentMemoryUsed;
}
}
sub get_host_cpu_info {
if ($host_info) {
my $percentCpuUsed = ($host_info->{'summary.quickStats'}->overallCpuUsage / ($host_info->{'summary.hardware'}->cpuMhz * $host_info->{'summary.hardware'}->numCpuCores)) * 100;
printf "cpu.value %.2f\n",$percentCpuUsed;
}
}