mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
correct code indention, remove whitespaces at EOL, add documentation about vCenter usage
This commit is contained in:
parent
b81e26cdaf
commit
2b23857b4a
@ -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
|
||||
@ -134,20 +147,20 @@ if ($0 =~ /vcenter_(.+)$/) {
|
||||
my $vpid = open(FH, "-|");
|
||||
if ($vpid == 0) {
|
||||
Opts::set_option ('username', $ENV{user} || 'root');
|
||||
Opts::set_option ('password', $ENV{password} || '');
|
||||
Opts::set_option ('password', $ENV{password} || '');
|
||||
Opts::set_option ('server', $ENV{vCenter});
|
||||
Util::connect();
|
||||
foreach (@{Vim::find_entity_views(view_type => 'HostSystem', properties => ['name'])}) {
|
||||
print $_->{name}, "\n";
|
||||
}
|
||||
Util::disconnect();
|
||||
exit 0;
|
||||
Util::connect();
|
||||
foreach (@{Vim::find_entity_views(view_type => 'HostSystem', properties => ['name'])}) {
|
||||
print $_->{name}, "\n";
|
||||
}
|
||||
Util::disconnect();
|
||||
exit 0;
|
||||
} else {
|
||||
while (<FH>) {
|
||||
push @host_names, trim($_);
|
||||
print "# found host ",trim($_)," on vCenter\n" if $DEBUG;
|
||||
}
|
||||
close FH;
|
||||
while (<FH>) {
|
||||
push @host_names, trim($_);
|
||||
print "# found host ",trim($_)," on vCenter\n" if $DEBUG;
|
||||
}
|
||||
close FH;
|
||||
}
|
||||
} else {
|
||||
# get hostname from filename and blurt it out immediately
|
||||
@ -163,319 +176,320 @@ 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 ($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}) {
|
||||
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 {
|
||||
Opts::set_option ('server',$host_name);
|
||||
}
|
||||
|
||||
|
||||
# plugin needs Munin 1.4 or later
|
||||
need_multigraph();
|
||||
|
||||
my $sstarttime = time();
|
||||
|
||||
# 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.");
|
||||
|
||||
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.");
|
||||
|
||||
# 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;
|
||||
|
||||
# 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";
|
||||
|
||||
# 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) {
|
||||
for (@$_) {
|
||||
my $datastore = Vim::get_view (mo_ref => $_);
|
||||
# update freeSpace values (doesn't work on free ESXi)
|
||||
eval { $datastore->RefreshDatastore(); };
|
||||
$datastore->update_view_data();
|
||||
my $uuid =$datastore->summary->url;
|
||||
$uuid =~ s!.+/!!;
|
||||
$resolveNames->{datastore}->{$uuid} = $datastore->name;
|
||||
push (@all_perf_data,
|
||||
{ rollup => "latest",
|
||||
group => "datastore",
|
||||
name => "capacity",
|
||||
value => $datastore->summary->capacity,
|
||||
counter => PerfCounterInfo->new(nameInfo => ElementDescription->new(label => "Capacity", summary => "Maximum amount of storage space on this datastore")),
|
||||
vm => "",
|
||||
instance => $uuid,
|
||||
unit => "Bytes" });
|
||||
push (@all_perf_data,
|
||||
{ rollup => "latest",
|
||||
group => "datastore",
|
||||
name => "freeSpace",
|
||||
value => $datastore->summary->freeSpace,
|
||||
counter => PerfCounterInfo->new(nameInfo => ElementDescription->new(label => "Free", summary => "Total amount of unused, available storage space on this datastore")),
|
||||
vm => "",
|
||||
instance => $uuid,
|
||||
unit => "Bytes" });
|
||||
push (@all_perf_data,
|
||||
{ rollup => "latest",
|
||||
group => "datastore",
|
||||
name => "uncommitted",
|
||||
value => $datastore->summary->uncommitted,
|
||||
counter => PerfCounterInfo->new(nameInfo => ElementDescription->new(label => "Uncommitted", summary => "Total additional storage space, potentially used by all virtual machines on this datastore")),
|
||||
vm => "",
|
||||
instance => $uuid,
|
||||
unit => "Bytes" });
|
||||
}
|
||||
}
|
||||
|
||||
# iterate over all vms
|
||||
for ($host_view->vm) {
|
||||
for (@$_) {
|
||||
my $vm = Vim::get_view (mo_ref => $_);
|
||||
$vm->update_view_data();
|
||||
# store VM id for later iteration
|
||||
my $vmId = $_->{value};
|
||||
push @all_vms, $vmId;
|
||||
# ID to VM name
|
||||
$resolveNames->{vm}->{$vmId} = "VM ".$vm->summary->config->name;
|
||||
$resolveNames->{vmuuid}->{$vmId} = $vm->summary->config->uuid;
|
||||
# fetch disk space usage per datastore
|
||||
for (@{$vm->storage->perDatastoreUsage}) {
|
||||
my $uuid = Vim::get_view(mo_ref => $_->datastore)->summary->url;
|
||||
$uuid =~ s!.+/!!;
|
||||
push (@all_perf_data,
|
||||
{ rollup => "latest",
|
||||
group => "datastore",
|
||||
name => "committed",
|
||||
value => $_->committed,
|
||||
counter => PerfCounterInfo->new(nameInfo => ElementDescription->new(label => "Comitted", summary => "Storage space, in bytes, on this datastore that is actually being used by the virtual machine.\n\nIt includes space actually occupied by disks, logs, snapshots, configuration files etc. Files of the virtual machine which are present on a different datastore (e.g. a virtual disk on another datastore) are not included here.\n\n")),
|
||||
vm => $vmId,
|
||||
instance => $uuid,
|
||||
unit => "Bytes" });
|
||||
push (@all_perf_data,
|
||||
{ rollup => "latest",
|
||||
group => "datastore",
|
||||
name => "uncommitted",
|
||||
value => $_->uncommitted,
|
||||
counter => PerfCounterInfo->new(nameInfo => ElementDescription->new(label => "Uncomitted", summary => "Additional storage space, in bytes, potentially used by the virtual machine on this datastore.\n\nAdditional space may be needed for example when lazily allocated disks grow, or storage for swap is allocated when powering on the virtual machine.\n\nIf the virtual machine is running off delta disks (for example because a snapshot was taken), then only the potential growth of the currently used delta-disks is considered.\n\n")),
|
||||
vm => $vmId,
|
||||
instance => $uuid,
|
||||
unit => "Bytes" });
|
||||
push (@all_perf_data,
|
||||
{ rollup => "latest",
|
||||
group => "datastore",
|
||||
name => "unshared",
|
||||
value => $_->unshared,
|
||||
counter => PerfCounterInfo->new(nameInfo => ElementDescription->new(label => "Unshared", summary => "Storage space, in bytes, occupied by the virtual machine on this datastore that is not shared with any other virtual machine.\n\n")),
|
||||
vm => $vmId,
|
||||
instance => $uuid,
|
||||
unit => "Bytes" });
|
||||
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";
|
||||
}
|
||||
}
|
||||
# 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 );
|
||||
|
||||
# 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
|
||||
next unless ($_->baseUnits =~ /.+/);
|
||||
# create entry with sensor data
|
||||
push (@all_perf_data,
|
||||
{ rollup => "latest",
|
||||
group => "sensors",
|
||||
name => "sensor_".($index++),
|
||||
value => $_->currentReading,
|
||||
counter => PerfCounterInfo->new(nameInfo => ElementDescription->new(label => $_->name, summary => "Sensor data for the ".$_->sensorType." sensor ".$_->name.". ".$_->healthState->summary." (".$_->healthState->label.")")),
|
||||
vm => "",
|
||||
instance => "",
|
||||
unitModifier => $_->unitModifier,
|
||||
unit => $_->baseUnits });
|
||||
}
|
||||
|
||||
# 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) {
|
||||
push (@all_perf_data,
|
||||
{ rollup => "latest",
|
||||
group => "sensors",
|
||||
name => $_."_sensors",
|
||||
value => $sensorCount{$_},
|
||||
counter => PerfCounterInfo->new(nameInfo => ElementDescription->new(label => ucfirst($_), summary => "Count of sensors in the $_ state")),
|
||||
vm => "",
|
||||
instance => "",
|
||||
unit => "Numbers" });
|
||||
}
|
||||
|
||||
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 = ();
|
||||
|
||||
# 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 " }
|
||||
},
|
||||
{ selector => { group => qr/^disk$/i, name => qr/^(read|usage|write)$/i, instance => qr/.+/ },
|
||||
config => { groupBy => "group", graphName => "host_disk_transfer", graphTitle => "Disk Transfer Rates per " }
|
||||
},
|
||||
{ selector => { group => qr/^disk$/i, name => qr/^.+Averaged$/i, instance => qr/.+/ },
|
||||
config => { groupBy => "group", graphName => "host_disk_iops", graphTitle => "Disk I/O operations per " }
|
||||
},
|
||||
{ selector => { group => qr/^disk$/i, name => qr/^.+Latency$/i, instance => qr/.+/, vm => qr/^$/ },
|
||||
config => { groupBy => "vm", graphName => "host_disk_latency", graphTitle => "Disk latency for " }
|
||||
},
|
||||
{ selector => { group => qr/^mem$/i, unit => qr/^KB$/i, rollup => qr/^none$/, vm => qr/^$/ },
|
||||
config => { groupBy => "vm", graphName => "host_memory", graphTitle => "Memory usage for " }
|
||||
},
|
||||
{ selector => { group => qr/^datastore$/i, unit => qr/^Bytes$/i, vm => qr/^$/ },
|
||||
config => { groupBy => "vm", graphName => "usage_datastore", graphTitle => "Disk space usage for ", graphArgs => "--lower-limit 10737418240 --logarithmic --alt-autoscale-min --units=si" }
|
||||
},
|
||||
{ selector => { group => qr/^net$/i, unit => qr/^KBps$/i, vm => qr/^$/ },
|
||||
config => { groupBy => "vm", graphName => "host_traffic_net", graphTitle => "Network traffic for " }
|
||||
},
|
||||
{ selector => { group => qr/^net$/i, unit => qr/^Number$/i, vm => qr/^$/ },
|
||||
config => { groupBy => "vm", graphName => "host_packets_net", graphTitle => "Network packets for " }
|
||||
},
|
||||
{ selector => { group => qr/^power$/i, name => qr/^power$/i },
|
||||
config => { groupBy => "group", graphName => "power_usage", graphTitle => "Host System and VM " }
|
||||
},
|
||||
{ selector => { group => qr/^sys$/i, name => qr/^diskUsage$/i },
|
||||
config => { groupBy => "name", graphName => "host_disk_usage", graphTitle => "Host System " }
|
||||
},
|
||||
{ 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) {
|
||||
my $vmName = clean_fieldname($resolveNames->{vm}->{$_});
|
||||
push @all_graphs, (
|
||||
{ selector => { group => qr/^cpu$/i, name => qr/^usagemhz$/i, vm => qr/^$_$/ },
|
||||
config => { groupBy => "vm", graphName => "$vmName.vm_cpu", graphTitle => "CPU usage for " }
|
||||
},
|
||||
{ selector => { group => qr/^mem$/i, unit => qr/^KB$/i, rollup => qr/^none$/, vm => qr/^$_$/ },
|
||||
config => { groupBy => "vm", graphName => "$vmName.vm_memory", graphTitle => "Memory usage for " }
|
||||
},
|
||||
{ selector => { group => qr/^datastore$/i, unit => qr/^Bytes$/i, vm => qr/^$_$/ },
|
||||
config => { groupBy => "vm", graphName => "$vmName.vm_datastore", graphTitle => "Disk space usage for ", graphArgs => "--lower-limit 10485760 --logarithmic --alt-autoscale-min --units=si" }
|
||||
},
|
||||
{ selector => { group => qr/^virtualDisk$/i, unit => qr/^Millisecond$/i, vm => qr/^$_$/ },
|
||||
config => { groupBy => "vm", graphName => "$vmName.vm_disklat", graphTitle => "Disk latency for " }
|
||||
},
|
||||
{ selector => { group => qr/^virtualDisk$/i, unit => qr/^Number$/i, vm => qr/^$_$/ },
|
||||
config => { groupBy => "vm", graphName => "$vmName.vm_diskiops", graphTitle => "Disk I/O operations for " }
|
||||
},
|
||||
{ selector => { group => qr/^virtualDisk$/i, unit => qr/^KBps$/i, vm => qr/^$_$/ },
|
||||
config => { groupBy => "vm", graphName => "$vmName.vm_disktrans", graphTitle => "Disk transfer rates for " }
|
||||
},
|
||||
{ selector => { group => qr/^net$/i, unit => qr/^KBps$/i, vm => qr/^$_$/ },
|
||||
config => { groupBy => "vm", graphName => "$vmName.vm_traffic_net", graphTitle => "Network traffic for " }
|
||||
},
|
||||
{ selector => { group => qr/^net$/i, unit => qr/^Number$/i, vm => qr/^$_$/ },
|
||||
config => { groupBy => "vm", graphName => "$vmName.vm_packets_net", graphTitle => "Network packets for " }
|
||||
},
|
||||
{ selector => { group => qr/^sys$/i, name => qr/^uptime$/i, vm => qr/^$_$/ },
|
||||
config => { groupBy => "vm", graphName => "$vmName.vm_uptime", graphTitle => "VM uptime " }
|
||||
# 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 {
|
||||
Opts::set_option ('server',$host_name);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
# 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;
|
||||
# plugin needs Munin 1.4 or later
|
||||
need_multigraph();
|
||||
|
||||
# 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
|
||||
my $sstarttime = time();
|
||||
|
||||
# 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.");
|
||||
|
||||
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.");
|
||||
|
||||
# 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;
|
||||
|
||||
# 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";
|
||||
|
||||
# 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) {
|
||||
for (@$_) {
|
||||
my $datastore = Vim::get_view (mo_ref => $_);
|
||||
# update freeSpace values (doesn't work on free ESXi)
|
||||
eval { $datastore->RefreshDatastore(); };
|
||||
$datastore->update_view_data();
|
||||
my $uuid =$datastore->summary->url;
|
||||
$uuid =~ s!.+/!!;
|
||||
$resolveNames->{datastore}->{$uuid} = $datastore->name;
|
||||
push (@all_perf_data,
|
||||
{ rollup => "latest",
|
||||
group => "datastore",
|
||||
name => "capacity",
|
||||
value => $datastore->summary->capacity,
|
||||
counter => PerfCounterInfo->new(nameInfo => ElementDescription->new(label => "Capacity", summary => "Maximum amount of storage space on this datastore")),
|
||||
vm => "",
|
||||
instance => $uuid,
|
||||
unit => "Bytes" });
|
||||
push (@all_perf_data,
|
||||
{ rollup => "latest",
|
||||
group => "datastore",
|
||||
name => "freeSpace",
|
||||
value => $datastore->summary->freeSpace,
|
||||
counter => PerfCounterInfo->new(nameInfo => ElementDescription->new(label => "Free", summary => "Total amount of unused, available storage space on this datastore")),
|
||||
vm => "",
|
||||
instance => $uuid,
|
||||
unit => "Bytes" });
|
||||
push (@all_perf_data,
|
||||
{ rollup => "latest",
|
||||
group => "datastore",
|
||||
name => "uncommitted",
|
||||
value => $datastore->summary->uncommitted,
|
||||
counter => PerfCounterInfo->new(nameInfo => ElementDescription->new(label => "Uncommitted", summary => "Total additional storage space, potentially used by all virtual machines on this datastore")),
|
||||
vm => "",
|
||||
instance => $uuid,
|
||||
unit => "Bytes" });
|
||||
}
|
||||
}
|
||||
|
||||
# iterate over all vms
|
||||
for ($host_view->vm) {
|
||||
for (@$_) {
|
||||
my $vm = Vim::get_view (mo_ref => $_);
|
||||
$vm->update_view_data();
|
||||
# store VM id for later iteration
|
||||
my $vmId = $_->{value};
|
||||
push @all_vms, $vmId;
|
||||
# ID to VM name
|
||||
$resolveNames->{vm}->{$vmId} = "VM ".$vm->summary->config->name;
|
||||
$resolveNames->{vmuuid}->{$vmId} = $vm->summary->config->uuid;
|
||||
# fetch disk space usage per datastore
|
||||
for (@{$vm->storage->perDatastoreUsage}) {
|
||||
my $uuid = Vim::get_view(mo_ref => $_->datastore)->summary->url;
|
||||
$uuid =~ s!.+/!!;
|
||||
push (@all_perf_data,
|
||||
{ rollup => "latest",
|
||||
group => "datastore",
|
||||
name => "committed",
|
||||
value => $_->committed,
|
||||
counter => PerfCounterInfo->new(nameInfo => ElementDescription->new(label => "Comitted", summary => "Storage space, in bytes, on this datastore that is actually being used by the virtual machine.\n\nIt includes space actually occupied by disks, logs, snapshots, configuration files etc. Files of the virtual machine which are present on a different datastore (e.g. a virtual disk on another datastore) are not included here.\n\n")),
|
||||
vm => $vmId,
|
||||
instance => $uuid,
|
||||
unit => "Bytes" });
|
||||
push (@all_perf_data,
|
||||
{ rollup => "latest",
|
||||
group => "datastore",
|
||||
name => "uncommitted",
|
||||
value => $_->uncommitted,
|
||||
counter => PerfCounterInfo->new(nameInfo => ElementDescription->new(label => "Uncomitted", summary => "Additional storage space, in bytes, potentially used by the virtual machine on this datastore.\n\nAdditional space may be needed for example when lazily allocated disks grow, or storage for swap is allocated when powering on the virtual machine.\n\nIf the virtual machine is running off delta disks (for example because a snapshot was taken), then only the potential growth of the currently used delta-disks is considered.\n\n")),
|
||||
vm => $vmId,
|
||||
instance => $uuid,
|
||||
unit => "Bytes" });
|
||||
push (@all_perf_data,
|
||||
{ rollup => "latest",
|
||||
group => "datastore",
|
||||
name => "unshared",
|
||||
value => $_->unshared,
|
||||
counter => PerfCounterInfo->new(nameInfo => ElementDescription->new(label => "Unshared", summary => "Storage space, in bytes, occupied by the virtual machine on this datastore that is not shared with any other virtual machine.\n\n")),
|
||||
vm => $vmId,
|
||||
instance => $uuid,
|
||||
unit => "Bytes" });
|
||||
}
|
||||
# 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 );
|
||||
|
||||
# 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
|
||||
next unless ($_->baseUnits =~ /.+/);
|
||||
# create entry with sensor data
|
||||
push (@all_perf_data,
|
||||
{ rollup => "latest",
|
||||
group => "sensors",
|
||||
name => "sensor_".($index++),
|
||||
value => $_->currentReading,
|
||||
counter => PerfCounterInfo->new(nameInfo => ElementDescription->new(label => $_->name, summary => "Sensor data for the ".$_->sensorType." sensor ".$_->name.". ".$_->healthState->summary." (".$_->healthState->label.")")),
|
||||
vm => "",
|
||||
instance => "",
|
||||
unitModifier => $_->unitModifier,
|
||||
unit => $_->baseUnits });
|
||||
}
|
||||
|
||||
# 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) {
|
||||
push (@all_perf_data,
|
||||
{ rollup => "latest",
|
||||
group => "sensors",
|
||||
name => $_."_sensors",
|
||||
value => $sensorCount{$_},
|
||||
counter => PerfCounterInfo->new(nameInfo => ElementDescription->new(label => ucfirst($_), summary => "Count of sensors in the $_ state")),
|
||||
vm => "",
|
||||
instance => "",
|
||||
unit => "Numbers" });
|
||||
}
|
||||
|
||||
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 = ();
|
||||
|
||||
# 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 " }
|
||||
},
|
||||
{ selector => { group => qr/^disk$/i, name => qr/^(read|usage|write)$/i, instance => qr/.+/ },
|
||||
config => { groupBy => "group", graphName => "host_disk_transfer", graphTitle => "Disk Transfer Rates per " }
|
||||
},
|
||||
{ selector => { group => qr/^disk$/i, name => qr/^.+Averaged$/i, instance => qr/.+/ },
|
||||
config => { groupBy => "group", graphName => "host_disk_iops", graphTitle => "Disk I/O operations per " }
|
||||
},
|
||||
{ selector => { group => qr/^disk$/i, name => qr/^.+Latency$/i, instance => qr/.+/, vm => qr/^$/ },
|
||||
config => { groupBy => "vm", graphName => "host_disk_latency", graphTitle => "Disk latency for " }
|
||||
},
|
||||
{ selector => { group => qr/^mem$/i, unit => qr/^KB$/i, rollup => qr/^none$/, vm => qr/^$/ },
|
||||
config => { groupBy => "vm", graphName => "host_memory", graphTitle => "Memory usage for " }
|
||||
},
|
||||
{ selector => { group => qr/^datastore$/i, unit => qr/^Bytes$/i, vm => qr/^$/ },
|
||||
config => { groupBy => "vm", graphName => "usage_datastore", graphTitle => "Disk space usage for ", graphArgs => "--lower-limit 10737418240 --logarithmic --alt-autoscale-min --units=si" }
|
||||
},
|
||||
{ selector => { group => qr/^net$/i, unit => qr/^KBps$/i, vm => qr/^$/ },
|
||||
config => { groupBy => "vm", graphName => "host_traffic_net", graphTitle => "Network traffic for " }
|
||||
},
|
||||
{ selector => { group => qr/^net$/i, unit => qr/^Number$/i, vm => qr/^$/ },
|
||||
config => { groupBy => "vm", graphName => "host_packets_net", graphTitle => "Network packets for " }
|
||||
},
|
||||
{ selector => { group => qr/^power$/i, name => qr/^power$/i },
|
||||
config => { groupBy => "group", graphName => "power_usage", graphTitle => "Host System and VM " }
|
||||
},
|
||||
{ selector => { group => qr/^sys$/i, name => qr/^diskUsage$/i },
|
||||
config => { groupBy => "name", graphName => "host_disk_usage", graphTitle => "Host System " }
|
||||
},
|
||||
{ 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) {
|
||||
my $vmName = clean_fieldname($resolveNames->{vm}->{$_});
|
||||
push @all_graphs, (
|
||||
{ selector => { group => qr/^cpu$/i, name => qr/^usagemhz$/i, vm => qr/^$_$/ },
|
||||
config => { groupBy => "vm", graphName => "$vmName.vm_cpu", graphTitle => "CPU usage for " }
|
||||
},
|
||||
{ selector => { group => qr/^mem$/i, unit => qr/^KB$/i, rollup => qr/^none$/, vm => qr/^$_$/ },
|
||||
config => { groupBy => "vm", graphName => "$vmName.vm_memory", graphTitle => "Memory usage for " }
|
||||
},
|
||||
{ selector => { group => qr/^datastore$/i, unit => qr/^Bytes$/i, vm => qr/^$_$/ },
|
||||
config => { groupBy => "vm", graphName => "$vmName.vm_datastore", graphTitle => "Disk space usage for ", graphArgs => "--lower-limit 10485760 --logarithmic --alt-autoscale-min --units=si" }
|
||||
},
|
||||
{ selector => { group => qr/^virtualDisk$/i, unit => qr/^Millisecond$/i, vm => qr/^$_$/ },
|
||||
config => { groupBy => "vm", graphName => "$vmName.vm_disklat", graphTitle => "Disk latency for " }
|
||||
},
|
||||
{ selector => { group => qr/^virtualDisk$/i, unit => qr/^Number$/i, vm => qr/^$_$/ },
|
||||
config => { groupBy => "vm", graphName => "$vmName.vm_diskiops", graphTitle => "Disk I/O operations for " }
|
||||
},
|
||||
{ selector => { group => qr/^virtualDisk$/i, unit => qr/^KBps$/i, vm => qr/^$_$/ },
|
||||
config => { groupBy => "vm", graphName => "$vmName.vm_disktrans", graphTitle => "Disk transfer rates for " }
|
||||
},
|
||||
{ selector => { group => qr/^net$/i, unit => qr/^KBps$/i, vm => qr/^$_$/ },
|
||||
config => { groupBy => "vm", graphName => "$vmName.vm_traffic_net", graphTitle => "Network traffic for " }
|
||||
},
|
||||
{ selector => { group => qr/^net$/i, unit => qr/^Number$/i, vm => qr/^$_$/ },
|
||||
config => { groupBy => "vm", graphName => "$vmName.vm_packets_net", graphTitle => "Network packets for " }
|
||||
},
|
||||
{ selector => { group => qr/^sys$/i, name => qr/^uptime$/i, vm => qr/^$_$/ },
|
||||
config => { groupBy => "vm", graphName => "$vmName.vm_uptime", graphTitle => "VM uptime " }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
# 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;
|
||||
|
||||
# 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 {
|
||||
munin_print("values", \@all_perf_data, $_);
|
||||
# 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 $_;
|
||||
print $_;
|
||||
}
|
||||
close ($fh);
|
||||
}
|
||||
@ -519,12 +533,12 @@ sub get_perf_data {
|
||||
foreach (@{$_->{value}}) {
|
||||
my $perfDesc = $perfCounter{$_->id->counterId};
|
||||
next unless defined $perfDesc;
|
||||
push @ret, { rollup => $perfDesc->rollupType->val,
|
||||
group => $perfDesc->groupInfo->key,
|
||||
name => $perfDesc->nameInfo->key,
|
||||
value => process_value_array(\@{$_->{value}}, $perfDesc),
|
||||
push @ret, { rollup => $perfDesc->rollupType->val,
|
||||
group => $perfDesc->groupInfo->key,
|
||||
name => $perfDesc->nameInfo->key,
|
||||
value => process_value_array(\@{$_->{value}}, $perfDesc),
|
||||
counter => $perfDesc,
|
||||
vm => $vm,
|
||||
vm => $vm,
|
||||
instance => $_->id->instance,
|
||||
unit => $perfDesc->unitInfo->label };
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user