summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xfiles/plugins/xen-cpu147
1 files changed, 75 insertions, 72 deletions
diff --git a/files/plugins/xen-cpu b/files/plugins/xen-cpu
index b456a14..da36f6d 100755
--- a/files/plugins/xen-cpu
+++ b/files/plugins/xen-cpu
@@ -3,15 +3,19 @@
# Script to minitor the cpu usage of Xen domains
#
# Author: Adam Crews <doo <at> shroom <dot> com>
-#
+#
# License: GPL
# Based on the origional xen script from Matthias Pfafferodt, syntron at web.de
#
# Note: Your munin config must run this as root.
#
# Parameters
-# config (required)
-# autoconf (optional - used by munin-config)
+# config (required)
+# autoconf (optional - used by munin-config)
+#
+# Changelog:
+# Properly ignore the xentop output header line.
+# Ward Vandewege (ward@gnu.org), 2011-04-20
#
#%# family=auto
#%# capabilities=autoconf
@@ -34,54 +38,54 @@ system('((find /var/lib/munin/plugin-state/xm_top.state -mmin -5 2>&1 | grep -qE
my $arg; undef($arg);
if (defined($ARGV[0])) {
- $arg = 'config' if ($ARGV[0] eq 'config');
- $arg = 'autoconf' if ($ARGV[0] eq 'autoconf');
-
- if ( "$arg" eq 'autoconf') {
- if ( -e $XM && -e $XMTOP ) {
- print "yes\n";
- exit 0;
- } else {
- print "no ($XM and/or $XMTOP not found\n";
- exit 1;
- }
- }
-
- if ( "$arg" eq 'config') {
- my %cnf; undef(%cnf);
- %cnf = (
- 'graph_title' => 'Xen Domain CPU Usage',
- 'graph_args' => '--base 1000 -l 0 --upper-limit 100 --rigid',
- 'graph_vlabel' => 'Percent (%)',
- 'graph_category' => 'xen',
- 'graph_info' => 'Display the % of CPU Usage for each domain',
- );
-
- my @domains = `cat /var/lib/munin/plugin-state/xm_list.state`;
+ $arg = 'config' if ($ARGV[0] eq 'config');
+ $arg = 'autoconf' if ($ARGV[0] eq 'autoconf');
+
+ if ( "$arg" eq 'autoconf') {
+ if ( -e $XM && -e $XMTOP ) {
+ print "yes\n";
+ exit 0;
+ } else {
+ print "no ($XM and/or $XMTOP not found\n";
+ exit 1;
+ }
+ }
+
+ if ( "$arg" eq 'config') {
+ my %cnf; undef(%cnf);
+ %cnf = (
+ 'graph_title' => 'Xen Domain CPU Usage',
+ 'graph_args' => '--base 1000 -l 0 --upper-limit 100 --rigid',
+ 'graph_vlabel' => 'Percent (%)',
+ 'graph_category' => 'xen',
+ 'graph_info' => 'Display the % of CPU Usage for each domain',
+ );
+
+ my @domains = `cat /var/lib/munin/plugin-state/xm_list.state`;
# the header line is not in the cached file
- #shift(@domains); # we dont need the header line
- my $cnt = "0";
- foreach my $domain ( @domains ) {
- my ($dom,undef) = split(/\s/, $domain, 2);
- # we need to change - and . to _ or things get weird with the graphs
- # some decent quoting would probably fix this, but this works for now
- $dom =~ s/[-.]/_/g;
-
- $cnf{ "$dom" . '.label' } = "$dom";
- $cnf{ "$dom" . '.draw' } = 'STACK';
- $cnf{ "$dom" . '.min' } = '0';
- $cnf{ "$dom" . '.max' } = '100';
- $cnf{ "$dom" . '.info' } = '% CPU used for ' . "$dom";
-
- if ( "$cnt" == "0") { $cnf{$dom.'.draw'} = 'AREA'; }
- $cnt++;
- }
-
- foreach my $key (sort(keys(%cnf))) {
- print "$key $cnf{$key}\n";
- }
- exit 0;
- }
+ #shift(@domains); # we dont need the header line
+ my $cnt = "0";
+ foreach my $domain ( @domains ) {
+ my ($dom,undef) = split(/\s/, $domain, 2);
+ # we need to change - and . to _ or things get weird with the graphs
+ # some decent quoting would probably fix this, but this works for now
+ $dom =~ s/[-.]/_/g;
+
+ $cnf{ "$dom" . '.label' } = "$dom";
+ $cnf{ "$dom" . '.draw' } = 'STACK';
+ $cnf{ "$dom" . '.min' } = '0';
+ $cnf{ "$dom" . '.max' } = '100';
+ $cnf{ "$dom" . '.info' } = '% CPU used for ' . "$dom";
+
+ if ( "$cnt" == "0") { $cnf{$dom.'.draw'} = 'AREA'; }
+ $cnt++;
+ }
+
+ foreach my $key (sort(keys(%cnf))) {
+ print "$key $cnf{$key}\n";
+ }
+ exit 0;
+ }
}
# Nothing was passed as an argument, so let's just return the proper values
@@ -89,33 +93,32 @@ if (defined($ARGV[0])) {
my @stats = `cat /var/lib/munin/plugin-state/xm_top.state`;
# remove the first 4 items that are junk that we don't need.
-shift(@stats);
-shift(@stats);
-shift(@stats);
-shift(@stats);
+shift(@stats);
+shift(@stats);
+shift(@stats);
+shift(@stats);
my %vals; undef(%vals);
foreach my $domain (@stats) {
- # trim the leading whitespace
- $domain =~ s/^\s+//;
- my @v_tmp = split(/\s+/, $domain);
-
- # we need to change - and . to _ or things get weird with the graphs
- # some decent quoting would probably fix this, but this works for now
- $v_tmp[0] =~ s/[-.]/_/g;
-
- $vals{$v_tmp[0]}{'cpu_percent'} = $v_tmp[3];
- $vals{$v_tmp[0]}{'vcpu'} = $v_tmp[8];
- if ( $vals{$v_tmp[0]}{'vcpu'} =~ m/n\/a/ ) {
- my $cpu = `grep -c "processor" < /proc/cpuinfo`;
- if ( $cpu =~ m/^(\d+)$/ ) {
- $vals{$v_tmp[0]}{'vcpu'} = $1;
- }
- }
+ # trim the leading whitespace
+ $domain =~ s/^\s+//;
+ my @v_tmp = split(/\s+/, $domain);
+
+ # we need to change - and . to _ or things get weird with the graphs
+ # some decent quoting would probably fix this, but this works for now
+ $v_tmp[0] =~ s/[-.]/_/g;
+
+ $vals{$v_tmp[0]}{'cpu_percent'} = $v_tmp[3];
+ $vals{$v_tmp[0]}{'vcpu'} = $v_tmp[8];
+ if ( $vals{$v_tmp[0]}{'vcpu'} =~ m/n\/a/ ) {
+ my $cpu = `grep -c "processor" < /proc/cpuinfo`;
+ if ( $cpu =~ m/^(\d+)$/ ) {
+ $vals{$v_tmp[0]}{'vcpu'} = $1;
+ }
+ }
}
foreach my $key (sort(keys(%vals))) {
- print "$key.value " . ($vals{$key}{'cpu_percent'}/$vals{'Domain_0'}{'vcpu'}), "\n";
+ print "$key.value " . ($vals{$key}{'cpu_percent'}/$vals{'Domain_0'}{'vcpu'}), "\n";
}
-