2014-06-22 14:44:35 +02:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
# -*- perl -*-
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
fusion_ a Plugin for displaying VMWare Fusion Stats
|
|
|
|
|
|
|
|
=head1 INTERPRETATION
|
|
|
|
|
|
|
|
This plugin displays the following charts:
|
|
|
|
|
|
|
|
1) pcpu
|
|
|
|
2) pmem
|
|
|
|
3) mem
|
|
|
|
|
|
|
|
You can set the modes with naming the softlink:
|
|
|
|
|
|
|
|
1) fusion_pcpu
|
|
|
|
2) fusion_pmem
|
|
|
|
3) fusion_mem
|
|
|
|
|
|
|
|
This Plugin uses ps for gaining the data:
|
|
|
|
|
|
|
|
> ps -A -c -o pcpu,pmem,rss=,comm,args -r | grep vmware-vmx
|
|
|
|
5,0 19,5 3271768 innoq-winxp.vmx vmware-vmx
|
|
|
|
4,6 10,7 1801768 Gateway.vmx vmware-vmx
|
|
|
|
2,3 5,8 976288 Jenkins.vmx vmware-vmx
|
|
|
|
2,0 22,6 3784144 Mac_OS_X_10.9.vmx vmware-vmx
|
|
|
|
0,0 0,0 620 grep vmware-vmx grep
|
|
|
|
|
|
|
|
So the Output should be pretty standard about all MacOS/Fusion Versions.
|
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
|
|
|
|
No Configuration necessary!
|
|
|
|
|
|
|
|
TODO:
|
|
|
|
still a bug with getting pcpu,pmem,rss=,comm as an output, have filter it with if( $vm[3] =~ /(?<!comm)$/)
|
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
|
|
|
Philipp Haussleiter <philipp@haussleiter.de> (email)
|
|
|
|
|
|
|
|
=head1 LICENSE
|
|
|
|
|
|
|
|
GPLv2
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
# MAIN
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
use File::Basename;
|
|
|
|
|
|
|
|
# pcpu, pmem, mem
|
|
|
|
my $type = basename($0);
|
|
|
|
$type =~ s/fusion_//;
|
|
|
|
|
|
|
|
my $cmd = "ps -A -c -o pcpu,pmem,rss=,args,comm -r | grep vmware-vmx";
|
|
|
|
my $output = `$cmd`;
|
|
|
|
my @lines=split(/\n/,$output);
|
|
|
|
|
|
|
|
if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
|
|
|
|
my $lcount = 0;
|
2017-02-23 19:53:57 +01:00
|
|
|
my $base_config = "graph_category virtualization\n";
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2014-06-22 14:44:35 +02:00
|
|
|
if( $type eq "pcpu" ) {
|
|
|
|
print $base_config;
|
2018-08-02 02:03:42 +02:00
|
|
|
print "graph_args --base 1000 -l 0 -u 100 -r\n";
|
|
|
|
print "graph_scale no\n";
|
2014-06-22 14:44:35 +02:00
|
|
|
print "graph_title CPU usage in % per VM\n";
|
|
|
|
print "graph_vlabel % of CPU usage\n";
|
2018-08-02 02:03:42 +02:00
|
|
|
print "graph_info The Graph shows the CPU usage in % per VM\n";
|
2014-06-22 14:44:35 +02:00
|
|
|
foreach my $line(@lines) {
|
2018-08-02 02:03:42 +02:00
|
|
|
if( $line =~ /(?<!grep)$/) {
|
2014-06-22 14:44:35 +02:00
|
|
|
my @vm = ();
|
|
|
|
my $count = 0;
|
2018-08-02 02:03:42 +02:00
|
|
|
my @array=split(/ /,$line);
|
2014-06-22 14:44:35 +02:00
|
|
|
foreach my $entry(@array) {
|
|
|
|
if( length($entry) > 2 ){
|
|
|
|
$vm[$count]=$entry;
|
|
|
|
$count++;
|
|
|
|
}
|
2018-08-02 02:03:42 +02:00
|
|
|
}
|
2014-06-22 14:44:35 +02:00
|
|
|
$vm[3] =~ s/\.vmx//;
|
2018-08-02 02:03:42 +02:00
|
|
|
my $cat = clean_vmname($vm[3]);
|
2014-06-22 14:44:35 +02:00
|
|
|
if( $cat =~ /(?<!comm)$/) {
|
|
|
|
if( $lcount > 0 ){
|
|
|
|
print $cat,"_pcpu.draw STACK\n";
|
|
|
|
} else {
|
|
|
|
print $cat,"_pcpu.draw AREA\n";
|
|
|
|
}
|
2018-08-02 02:03:42 +02:00
|
|
|
$lcount++;
|
2014-06-22 14:44:35 +02:00
|
|
|
print $cat,"_pcpu.label $vm[3]\n";
|
|
|
|
print $cat,"_pcpu.type GAUGE\n";
|
2018-08-02 02:03:42 +02:00
|
|
|
}
|
2014-06-22 14:44:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( $type eq "pmem" ) {
|
|
|
|
print $base_config;
|
|
|
|
print "graph_args --base 1000 -l 0 -u 100 -r\n";
|
|
|
|
print "graph_scale no\n";
|
|
|
|
print "graph_title Memory usage in % per VM\n";
|
|
|
|
print "graph_vlabel % of Memory usage\n";
|
2018-08-02 02:03:42 +02:00
|
|
|
print "graph_info The Graph shows the Memory usage in % per VM\n";
|
2014-06-22 14:44:35 +02:00
|
|
|
foreach my $line(@lines) {
|
2018-08-02 02:03:42 +02:00
|
|
|
if( $line =~ /(?<!grep)$/ ) {
|
2014-06-22 14:44:35 +02:00
|
|
|
my @vm = ();
|
|
|
|
my $count = 0;
|
2018-08-02 02:03:42 +02:00
|
|
|
my @array=split(/ /,$line);
|
2014-06-22 14:44:35 +02:00
|
|
|
foreach my $entry(@array) {
|
|
|
|
if( length($entry) > 2 ){
|
|
|
|
$vm[$count]=$entry;
|
|
|
|
$count++;
|
|
|
|
}
|
2018-08-02 02:03:42 +02:00
|
|
|
}
|
2014-06-22 14:44:35 +02:00
|
|
|
$vm[3] =~ s/\.vmx//;
|
2018-08-02 02:03:42 +02:00
|
|
|
my $cat = clean_vmname($vm[3]);
|
2014-06-22 14:44:35 +02:00
|
|
|
if( $cat =~ /(?<!comm)$/) {
|
|
|
|
if( $lcount > 0 ){
|
|
|
|
print $cat,"_pmem.draw STACK\n";
|
|
|
|
} else {
|
|
|
|
print $cat,"_pmem.draw AREA\n";
|
|
|
|
}
|
2018-08-02 02:03:42 +02:00
|
|
|
$lcount++;
|
2014-06-22 14:44:35 +02:00
|
|
|
print $cat,"_pmem.label $vm[3]\n";
|
|
|
|
print $cat,"_pmem.type GAUGE\n";
|
2018-08-02 02:03:42 +02:00
|
|
|
}
|
2014-06-22 14:44:35 +02:00
|
|
|
}
|
2018-08-02 02:03:42 +02:00
|
|
|
}
|
2014-06-22 14:44:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if( $type eq "mem" ) {
|
|
|
|
print $base_config;
|
2018-08-02 02:03:42 +02:00
|
|
|
print "graph_args --base 1024 -r --lower-limit 0\n";
|
2014-06-22 14:44:35 +02:00
|
|
|
print "graph_title absolute Memory usage per VM\n";
|
|
|
|
print "graph_vlabel Memory usage\n";
|
2018-08-02 02:03:42 +02:00
|
|
|
print "graph_info The Graph shows the absolute Memory usage per VM\n";
|
2014-06-22 14:44:35 +02:00
|
|
|
foreach my $line(@lines) {
|
2018-08-02 02:03:42 +02:00
|
|
|
if( $line =~ /(?<!grep)$/ ) {
|
2014-06-22 14:44:35 +02:00
|
|
|
my @vm = ();
|
|
|
|
my $count = 0;
|
2018-08-02 02:03:42 +02:00
|
|
|
my @array=split(/ /,$line);
|
2014-06-22 14:44:35 +02:00
|
|
|
foreach my $entry(@array) {
|
|
|
|
if( length($entry) > 2 ){
|
|
|
|
$vm[$count]=$entry;
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
}
|
2018-08-02 02:03:42 +02:00
|
|
|
$vm[3] = clean_vmname($vm[3]);
|
|
|
|
if( $vm[3] =~ /(?<!comm)$/) {
|
2014-06-22 14:44:35 +02:00
|
|
|
if( $lcount > 0 ){
|
|
|
|
print "$vm[3]_mem.draw STACK\n";
|
|
|
|
} else {
|
|
|
|
print "$vm[3]_mem.draw AREA\n";
|
|
|
|
}
|
|
|
|
print "$vm[3]_mem.label $vm[3]\n";
|
2018-08-02 02:03:42 +02:00
|
|
|
print "$vm[3]_mem.type GAUGE\n";
|
|
|
|
$lcount++;
|
|
|
|
}
|
2014-06-22 14:44:35 +02:00
|
|
|
}
|
2018-08-02 02:03:42 +02:00
|
|
|
}
|
2014-06-22 14:44:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
foreach my $line(@lines) {
|
|
|
|
if( $line =~ /(?<!grep)$/ ) {
|
|
|
|
my @vm = ();
|
|
|
|
my $count = 0;
|
2018-08-02 02:03:42 +02:00
|
|
|
my @array=split(/ /,$line);
|
2014-06-22 14:44:35 +02:00
|
|
|
foreach my $entry(@array) {
|
|
|
|
if( length($entry) > 2 ){
|
|
|
|
$vm[$count]=$entry;
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$vm[3] = clean_vmname($vm[3]);
|
2018-08-02 02:03:42 +02:00
|
|
|
if( $vm[3] =~ /(?<!comm)$/) {
|
2014-06-22 14:44:35 +02:00
|
|
|
if( $type eq "pcpu" ) {
|
|
|
|
print "$vm[3]_pcpu.value $vm[0]\n";
|
|
|
|
}
|
|
|
|
if( $type eq "pmem" ) {
|
|
|
|
print "$vm[3]_pmem.value $vm[1]\n";
|
|
|
|
}
|
|
|
|
if( $type eq "mem" ) {
|
|
|
|
my $value = ($vm[2]*1024);
|
|
|
|
print "$vm[3]_mem.value $value\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-08-02 02:03:42 +02:00
|
|
|
}
|
2014-06-22 14:44:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub clean_vmname {
|
|
|
|
my $vm_name = $_[0];
|
|
|
|
$vm_name =~ s/\.vmx//;
|
|
|
|
$vm_name =~ s/\./\_/g;
|
|
|
|
return $vm_name;
|
|
|
|
}
|