1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-26 10:58:12 +00:00

correct code indention, remove whitespaces at EOL, add documentation about vCenter usage

This commit is contained in:
Stefan Seidel 2012-06-11 19:20:09 +02:00
parent b81e26cdaf
commit 2b23857b4a

View file

@ -45,6 +45,19 @@ Then you need to add this host to your munin.conf on the munin server
munin-node, and wait for the data to populate. munin-node, and wait for the data to populate.
-== Query all hosts of a vCenter ==-
An alternate way of using this plugin is to link it to
/etc/munin/plugins/vcenter_<hostname_of_vcenter>
In this mode, the vCenter server specified in the filename is queried
for a list of hosts it manages, and graphs are created for all these
hosts. The option "flatview" is implied in this mode, since one munin
plugin can only be assigned to one host. The option "vCenter" is ignored
since the vCenter server is given through the file name. You can, however
still use the option "flatview" to override the "host_name" under which
the results are reported. Make sure to read the section below about
this option!
-== Graphs don't render ==- -== Graphs don't render ==-
Munin 1.4 has a bug with complex multigraphs like this, see Munin 1.4 has a bug with complex multigraphs like this, see
http://munin-monitoring.org/ticket/1224 for details and a fix if http://munin-monitoring.org/ticket/1224 for details and a fix if
@ -163,84 +176,84 @@ foreach $host_name (@host_names) {
local *FH; local *FH;
my $pid = open(FH, "-|"); my $pid = open(FH, "-|");
if ($pid == 0) { if ($pid == 0) {
######################## CHILD # CHILD
if ((defined $ARGV[0]) and ($ARGV[0] eq "config")) { if ((defined $ARGV[0]) and ($ARGV[0] eq "config")) {
if ($ENV{flatview}) { if ($ENV{flatview}) {
print "host_name $ENV{flatview}\n"; print "host_name $ENV{flatview}\n";
print "# for host $host_name\n" if $DEBUG; print "# for host $host_name\n" if $DEBUG;
} else { } else {
print "host_name $host_name\n"; print "host_name $host_name\n";
} }
} }
# env.user and env.password need to be set in plugin-conf.d # env.user and env.password need to be set in plugin-conf.d
Opts::set_option ('username', $ENV{user} || 'root'); Opts::set_option ('username', $ENV{user} || 'root');
Opts::set_option ('password', $ENV{password} || ''); Opts::set_option ('password', $ENV{password} || '');
if ($ENV{vCenter}) { if ($ENV{vCenter}) {
print "# vCenter: $ENV{vCenter} - host $host_name\n" if $DEBUG; print "# vCenter: $ENV{vCenter} - host $host_name\n" if $DEBUG;
Opts::add_options ( (vihost => { alias => "h", type => "=s", required => 0 }) ); Opts::add_options ( (vihost => { alias => "h", type => "=s", required => 0 }) );
Opts::set_option ('vihost',$host_name); Opts::set_option ('vihost',$host_name);
Opts::set_option ('server',$ENV{vCenter}); Opts::set_option ('server',$ENV{vCenter});
} else { } else {
Opts::set_option ('server',$host_name); Opts::set_option ('server',$host_name);
} }
# plugin needs Munin 1.4 or later # plugin needs Munin 1.4 or later
need_multigraph(); need_multigraph();
my $sstarttime = time(); my $sstarttime = time();
# connect to vSphere host # connect to vSphere host
Util::connect(); Util::connect();
# central object host_view holds all relevant items (VMs, network, etc.) # central object host_view holds all relevant items (VMs, network, etc.)
$host_view = VIExt::get_host_view(1, ['summary', 'network', 'datastore', 'vm', 'runtime', 'configManager.networkSystem', 'configManager.dateTimeSystem']); $host_view = VIExt::get_host_view(1, ['summary', 'network', 'datastore', 'vm', 'runtime', 'configManager.networkSystem', 'configManager.dateTimeSystem']);
Opts::assert_usage(defined($host_view), "Invalid host."); Opts::assert_usage(defined($host_view), "Invalid host.");
my $serviceInst = Vim::get_view (mo_ref => ManagedObjectReference->new(type => 'ServiceInstance', value => 'ServiceInstance')); my $serviceInst = Vim::get_view (mo_ref => ManagedObjectReference->new(type => 'ServiceInstance', value => 'ServiceInstance'));
# Performance Manager for getting the actual values # Performance Manager for getting the actual values
$perfMan = Vim::get_view (mo_ref => $serviceInst->content->perfManager); $perfMan = Vim::get_view (mo_ref => $serviceInst->content->perfManager);
Opts::assert_usage(defined($perfMan), "No PerformanceManager."); Opts::assert_usage(defined($perfMan), "No PerformanceManager.");
# may be needed later # may be needed later
#my $netsys = Vim::get_view(mo_ref => ManagedObjectReference->new(type => 'HostNetworkSystem', value => 'networkSystem')); #my $netsys = Vim::get_view(mo_ref => ManagedObjectReference->new(type => 'HostNetworkSystem', value => 'networkSystem'));
#Opts::assert_usage(defined($netsys), "No NetworkSystem."); #Opts::assert_usage(defined($netsys), "No NetworkSystem.");
# used for getting the current vSphere server time and then # used for getting the current vSphere server time and then
# defining the (now - 5minutes) interval # defining the (now - 5minutes) interval
$dtsys = Vim::get_view(mo_ref => $host_view->{'configManager.dateTimeSystem'}); $dtsys = Vim::get_view(mo_ref => $host_view->{'configManager.dateTimeSystem'});
Opts::assert_usage(defined($dtsys), "No DateTimeSystem."); Opts::assert_usage(defined($dtsys), "No DateTimeSystem.");
print "# time to connect and get objects: ", time() - $sstarttime, "\n" if $DEBUG; print "# time to connect and get objects: ", time() - $sstarttime, "\n" if $DEBUG;
# enumerate all performance counters by their IDs # enumerate all performance counters by their IDs
%perfCounter = map { $_->key => $_ } @{$perfMan->perfCounter}; %perfCounter = map { $_->key => $_ } @{$perfMan->perfCounter};
# holds all performance data # holds all performance data
my @all_perf_data = (); my @all_perf_data = ();
# store VM ids for iteration later on # store VM ids for iteration later on
my @all_vms = (); my @all_vms = ();
$host_view->update_view_data(); $host_view->update_view_data();
# retrieve performance counters for host # retrieve performance counters for host
push @all_perf_data, get_perf_data($host_view); push @all_perf_data, get_perf_data($host_view);
# manually set UF name for host system # manually set UF name for host system
$resolveNames->{vm}->{""} = "Host System"; $resolveNames->{vm}->{""} = "Host System";
# only purpose of this loop is getting the UF network names # only purpose of this loop is getting the UF network names
# network ManagedObjects do not have performance counters # network ManagedObjects do not have performance counters
for ($host_view->network) { for ($host_view->network) {
for (@$_) { for (@$_) {
my $network = Vim::get_view (mo_ref => $_); my $network = Vim::get_view (mo_ref => $_);
$resolveNames->{net}->{$_->{value}} = $_->{value}." (".$network->summary->name.")"; $resolveNames->{net}->{$_->{value}} = $_->{value}." (".$network->summary->name.")";
} }
} }
# purpose of this loop is getting the UF datastore names # purpose of this loop is getting the UF datastore names
# and retrieving capacity and free/uncommitted space # and retrieving capacity and free/uncommitted space
# datastore ManagedObjects do not have performance counters # datastore ManagedObjects do not have performance counters
for ($host_view->datastore) { for ($host_view->datastore) {
for (@$_) { for (@$_) {
my $datastore = Vim::get_view (mo_ref => $_); my $datastore = Vim::get_view (mo_ref => $_);
# update freeSpace values (doesn't work on free ESXi) # update freeSpace values (doesn't work on free ESXi)
@ -277,10 +290,10 @@ for ($host_view->datastore) {
instance => $uuid, instance => $uuid,
unit => "Bytes" }); unit => "Bytes" });
} }
} }
# iterate over all vms # iterate over all vms
for ($host_view->vm) { for ($host_view->vm) {
for (@$_) { for (@$_) {
my $vm = Vim::get_view (mo_ref => $_); my $vm = Vim::get_view (mo_ref => $_);
$vm->update_view_data(); $vm->update_view_data();
@ -325,14 +338,14 @@ for ($host_view->vm) {
# retrieve performance counters for this VM # retrieve performance counters for this VM
push @all_perf_data, get_perf_data ($_); push @all_perf_data, get_perf_data ($_);
} }
} }
# keep track of how many sensors are in which state # keep track of how many sensors are in which state
my %sensorCount = ( green => 0, red => 0, unknown => 0, yellow => 0 ); my %sensorCount = ( green => 0, red => 0, unknown => 0, yellow => 0 );
# iterate over all sensor data # iterate over all sensor data
my $index = 0; my $index = 0;
for (@{$host_view->runtime->healthSystemRuntime->systemHealthInfo->numericSensorInfo}) { for (@{$host_view->runtime->healthSystemRuntime->systemHealthInfo->numericSensorInfo}) {
# update counters # update counters
$sensorCount{$_->healthState->key}++; $sensorCount{$_->healthState->key}++;
# do not create entries for unmonitorable things like software components # do not create entries for unmonitorable things like software components
@ -348,13 +361,13 @@ for (@{$host_view->runtime->healthSystemRuntime->systemHealthInfo->numericSensor
instance => "", instance => "",
unitModifier => $_->unitModifier, unitModifier => $_->unitModifier,
unit => $_->baseUnits }); unit => $_->baseUnits });
} }
# we're finished querying the server, so we can disconnect now # we're finished querying the server, so we can disconnect now
Util::disconnect(); Util::disconnect();
# create entries for the green/red/yellow/unknown counters # create entries for the green/red/yellow/unknown counters
for (keys %sensorCount) { for (keys %sensorCount) {
push (@all_perf_data, push (@all_perf_data,
{ rollup => "latest", { rollup => "latest",
group => "sensors", group => "sensors",
@ -364,19 +377,19 @@ for (keys %sensorCount) {
vm => "", vm => "",
instance => "", instance => "",
unit => "Numbers" }); unit => "Numbers" });
} }
if ($DEBUG) { if ($DEBUG) {
foreach (sort { $a->{group} cmp $b->{group} || $a->{instance} cmp $b->{instance} || $a->{name} cmp $b->{name} || $a->{rollup} cmp $b->{rollup} || $a->{vm} cmp $b->{vm} } @all_perf_data) { foreach (sort { $a->{group} cmp $b->{group} || $a->{instance} cmp $b->{instance} || $a->{name} cmp $b->{name} || $a->{rollup} cmp $b->{rollup} || $a->{vm} cmp $b->{vm} } @all_perf_data) {
print "# $_->{vm}\t$_->{rollup}\t$_->{group}\t$_->{instance}\t$_->{name}\t$_->{value}\t$_->{unit}\n"; print "# $_->{vm}\t$_->{rollup}\t$_->{group}\t$_->{instance}\t$_->{name}\t$_->{value}\t$_->{unit}\n";
} }
} }
# which graphs to draw # which graphs to draw
my @all_graphs = (); my @all_graphs = ();
# host system # host system
push @all_graphs, ( push @all_graphs, (
{ selector => { group => qr/^cpu$/i, name => qr/^usagemhz$/i, instance => qr/^$/ }, { selector => { group => qr/^cpu$/i, name => qr/^usagemhz$/i, instance => qr/^$/ },
config => { groupBy => "group", graphName => "host_cpu", graphTitle => "CPU usage per " } config => { groupBy => "group", graphName => "host_cpu", graphTitle => "CPU usage per " }
}, },
@ -410,10 +423,10 @@ push @all_graphs, (
{ selector => { group => qr/^sys$/i, name => qr/^uptime$/i }, { selector => { group => qr/^sys$/i, name => qr/^uptime$/i },
config => { groupBy => "name", graphName => "uptimes", graphTitle => "Host System and VM ", graphArgs => "--lower-limit 1000 --logarithmic --alt-autoscale-min" } config => { groupBy => "name", graphName => "uptimes", graphTitle => "Host System and VM ", graphArgs => "--lower-limit 1000 --logarithmic --alt-autoscale-min" }
} }
); );
# graphs per VM # graphs per VM
foreach (@all_vms) { foreach (@all_vms) {
my $vmName = clean_fieldname($resolveNames->{vm}->{$_}); my $vmName = clean_fieldname($resolveNames->{vm}->{$_});
push @all_graphs, ( push @all_graphs, (
{ selector => { group => qr/^cpu$/i, name => qr/^usagemhz$/i, vm => qr/^$_$/ }, { selector => { group => qr/^cpu$/i, name => qr/^usagemhz$/i, vm => qr/^$_$/ },
@ -444,35 +457,36 @@ foreach (@all_vms) {
config => { groupBy => "vm", graphName => "$vmName.vm_uptime", graphTitle => "VM uptime " } config => { groupBy => "vm", graphName => "$vmName.vm_uptime", graphTitle => "VM uptime " }
} }
); );
} }
# sensor graphs # sensor graphs
push @all_graphs, ( push @all_graphs, (
{ selector => { group => qr/^sensors$/i }, { selector => { group => qr/^sensors$/i },
config => { groupBy => "unit", graphName => "sensor_", graphTitle => "Sensors ", multiGraph => 1 } config => { groupBy => "unit", graphName => "sensor_", graphTitle => "Sensors ", multiGraph => 1 }
}); });
print "# time to collect all data: ", time() - $sstarttime, "\n" if $DEBUG; print "# time to collect all data: ", time() - $sstarttime, "\n" if $DEBUG;
# actual processing # actual processing
foreach (@all_graphs) { foreach (@all_graphs) {
if ((defined $ARGV[0]) and ($ARGV[0] eq "config")) { if ((defined $ARGV[0]) and ($ARGV[0] eq "config")) {
munin_print("config", \@all_perf_data, $_); munin_print("config", \@all_perf_data, $_);
munin_print("values", \@all_perf_data, $_) if $ENV{MUNIN_CAP_DIRTYCONFIG}; # this doesn't seem to work even on Munin 1.4.6 munin_print("values", \@all_perf_data, $_) if $ENV{MUNIN_CAP_DIRTYCONFIG}; # this doesn't seem to work even on Munin 1.4.6
} else { } else {
munin_print("values", \@all_perf_data, $_); munin_print("values", \@all_perf_data, $_);
} }
}
print "# time of the script: ", time() - $sstarttime, "\n" if $DEBUG;
exit 0;
} else {
# PARENT
push @returns, *FH;
}
} }
print "# time of the script: ", time() - $sstarttime, "\n" if $DEBUG; # gather and print the output of the forked processes
exit 0;
} else {
################################ PARENT
push @returns, *FH;
}
}
foreach my $fh (@returns) { foreach my $fh (@returns) {
while (<$fh>) { while (<$fh>) {
print $_; print $_;