1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-26 02:48:28 +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.
-== 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 ==-
Munin 1.4 has a bug with complex multigraphs like this, see
http://munin-monitoring.org/ticket/1224 for details and a fix if
@ -163,84 +176,84 @@ foreach $host_name (@host_names) {
local *FH;
my $pid = open(FH, "-|");
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}) {
print "host_name $ENV{flatview}\n";
print "# for host $host_name\n" if $DEBUG;
} else {
print "host_name $host_name\n";
}
}
}
# env.user and env.password need to be set in plugin-conf.d
Opts::set_option ('username', $ENV{user} || 'root');
Opts::set_option ('password', $ENV{password} || '');
if ($ENV{vCenter}) {
# env.user and env.password need to be set in plugin-conf.d
Opts::set_option ('username', $ENV{user} || 'root');
Opts::set_option ('password', $ENV{password} || '');
if ($ENV{vCenter}) {
print "# vCenter: $ENV{vCenter} - host $host_name\n" if $DEBUG;
Opts::add_options ( (vihost => { alias => "h", type => "=s", required => 0 }) );
Opts::set_option ('vihost',$host_name);
Opts::set_option ('server',$ENV{vCenter});
} else {
} else {
Opts::set_option ('server',$host_name);
}
}
# plugin needs Munin 1.4 or later
need_multigraph();
# plugin needs Munin 1.4 or later
need_multigraph();
my $sstarttime = time();
my $sstarttime = time();
# connect to vSphere host
Util::connect();
# connect to vSphere host
Util::connect();
# 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']);
Opts::assert_usage(defined($host_view), "Invalid host.");
# 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']);
Opts::assert_usage(defined($host_view), "Invalid host.");
my $serviceInst = Vim::get_view (mo_ref => ManagedObjectReference->new(type => 'ServiceInstance', value => 'ServiceInstance'));
# Performance Manager for getting the actual values
$perfMan = Vim::get_view (mo_ref => $serviceInst->content->perfManager);
Opts::assert_usage(defined($perfMan), "No PerformanceManager.");
my $serviceInst = Vim::get_view (mo_ref => ManagedObjectReference->new(type => 'ServiceInstance', value => 'ServiceInstance'));
# Performance Manager for getting the actual values
$perfMan = Vim::get_view (mo_ref => $serviceInst->content->perfManager);
Opts::assert_usage(defined($perfMan), "No PerformanceManager.");
# may be needed later
#my $netsys = Vim::get_view(mo_ref => ManagedObjectReference->new(type => 'HostNetworkSystem', value => 'networkSystem'));
#Opts::assert_usage(defined($netsys), "No NetworkSystem.");
# may be needed later
#my $netsys = Vim::get_view(mo_ref => ManagedObjectReference->new(type => 'HostNetworkSystem', value => 'networkSystem'));
#Opts::assert_usage(defined($netsys), "No NetworkSystem.");
# used for getting the current vSphere server time and then
# defining the (now - 5minutes) interval
$dtsys = Vim::get_view(mo_ref => $host_view->{'configManager.dateTimeSystem'});
Opts::assert_usage(defined($dtsys), "No DateTimeSystem.");
# used for getting the current vSphere server time and then
# defining the (now - 5minutes) interval
$dtsys = Vim::get_view(mo_ref => $host_view->{'configManager.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
%perfCounter = map { $_->key => $_ } @{$perfMan->perfCounter};
# holds all performance data
my @all_perf_data = ();
# store VM ids for iteration later on
my @all_vms = ();
# enumerate all performance counters by their IDs
%perfCounter = map { $_->key => $_ } @{$perfMan->perfCounter};
# holds all performance data
my @all_perf_data = ();
# store VM ids for iteration later on
my @all_vms = ();
$host_view->update_view_data();
# retrieve performance counters for host
push @all_perf_data, get_perf_data($host_view);
# manually set UF name for host system
$resolveNames->{vm}->{""} = "Host System";
$host_view->update_view_data();
# retrieve performance counters for host
push @all_perf_data, get_perf_data($host_view);
# manually set UF name for host system
$resolveNames->{vm}->{""} = "Host System";
# only purpose of this loop is getting the UF network names
# network ManagedObjects do not have performance counters
for ($host_view->network) {
# only purpose of this loop is getting the UF network names
# network ManagedObjects do not have performance counters
for ($host_view->network) {
for (@$_) {
my $network = Vim::get_view (mo_ref => $_);
$resolveNames->{net}->{$_->{value}} = $_->{value}." (".$network->summary->name.")";
}
}
}
# purpose of this loop is getting the UF datastore names
# and retrieving capacity and free/uncommitted space
# datastore ManagedObjects do not have performance counters
for ($host_view->datastore) {
# purpose of this loop is getting the UF datastore names
# and retrieving capacity and free/uncommitted space
# datastore ManagedObjects do not have performance counters
for ($host_view->datastore) {
for (@$_) {
my $datastore = Vim::get_view (mo_ref => $_);
# update freeSpace values (doesn't work on free ESXi)
@ -277,10 +290,10 @@ for ($host_view->datastore) {
instance => $uuid,
unit => "Bytes" });
}
}
}
# iterate over all vms
for ($host_view->vm) {
# iterate over all vms
for ($host_view->vm) {
for (@$_) {
my $vm = Vim::get_view (mo_ref => $_);
$vm->update_view_data();
@ -325,14 +338,14 @@ for ($host_view->vm) {
# retrieve performance counters for this VM
push @all_perf_data, get_perf_data ($_);
}
}
}
# keep track of how many sensors are in which state
my %sensorCount = ( green => 0, red => 0, unknown => 0, yellow => 0 );
# keep track of how many sensors are in which state
my %sensorCount = ( green => 0, red => 0, unknown => 0, yellow => 0 );
# iterate over all sensor data
my $index = 0;
for (@{$host_view->runtime->healthSystemRuntime->systemHealthInfo->numericSensorInfo}) {
# iterate over all sensor data
my $index = 0;
for (@{$host_view->runtime->healthSystemRuntime->systemHealthInfo->numericSensorInfo}) {
# update counters
$sensorCount{$_->healthState->key}++;
# do not create entries for unmonitorable things like software components
@ -348,13 +361,13 @@ for (@{$host_view->runtime->healthSystemRuntime->systemHealthInfo->numericSensor
instance => "",
unitModifier => $_->unitModifier,
unit => $_->baseUnits });
}
}
# we're finished querying the server, so we can disconnect now
Util::disconnect();
# we're finished querying the server, so we can disconnect now
Util::disconnect();
# create entries for the green/red/yellow/unknown counters
for (keys %sensorCount) {
# create entries for the green/red/yellow/unknown counters
for (keys %sensorCount) {
push (@all_perf_data,
{ rollup => "latest",
group => "sensors",
@ -364,19 +377,19 @@ for (keys %sensorCount) {
vm => "",
instance => "",
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) {
print "# $_->{vm}\t$_->{rollup}\t$_->{group}\t$_->{instance}\t$_->{name}\t$_->{value}\t$_->{unit}\n";
}
}
}
# which graphs to draw
my @all_graphs = ();
# which graphs to draw
my @all_graphs = ();
# host system
push @all_graphs, (
# host system
push @all_graphs, (
{ selector => { group => qr/^cpu$/i, name => qr/^usagemhz$/i, instance => qr/^$/ },
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 },
config => { groupBy => "name", graphName => "uptimes", graphTitle => "Host System and VM ", graphArgs => "--lower-limit 1000 --logarithmic --alt-autoscale-min" }
}
);
);
# graphs per VM
foreach (@all_vms) {
# graphs per VM
foreach (@all_vms) {
my $vmName = clean_fieldname($resolveNames->{vm}->{$_});
push @all_graphs, (
{ 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 " }
}
);
}
}
# sensor graphs
push @all_graphs, (
# sensor graphs
push @all_graphs, (
{ selector => { group => qr/^sensors$/i },
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
foreach (@all_graphs) {
# actual processing
foreach (@all_graphs) {
if ((defined $ARGV[0]) and ($ARGV[0] eq "config")) {
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
} else {
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;
exit 0;
} else {
################################ PARENT
push @returns, *FH;
}
}
# gather and print the output of the forked processes
foreach my $fh (@returns) {
while (<$fh>) {
print $_;