summaryrefslogtreecommitdiff
path: root/files/plugins/xen-cpu
diff options
context:
space:
mode:
Diffstat (limited to 'files/plugins/xen-cpu')
-rwxr-xr-xfiles/plugins/xen-cpu20
1 files changed, 8 insertions, 12 deletions
diff --git a/files/plugins/xen-cpu b/files/plugins/xen-cpu
index 0ef301e..b456a14 100755
--- a/files/plugins/xen-cpu
+++ b/files/plugins/xen-cpu
@@ -28,6 +28,10 @@ use strict;
$ENV{PATH} = '/bin:/usr/bin:/usr/sbin';
+# we cache xm list for 5 min for perfomance reasons
+system('((find /var/lib/munin/plugin-state/xm_list.state -mmin -5 2>&1 | grep -qE \'^\/var\/lib\/munin\/plugin-state\/xm_list\.state$\') && [ `cat /var/lib/munin/plugin-state/xm_list.state | wc -l` -gt 1 ]) || /usr/sbin/xm list | grep -v "^Name .* Console$" > /var/lib/munin/plugin-state/xm_list.state');
+system('((find /var/lib/munin/plugin-state/xm_top.state -mmin -5 2>&1 | grep -qE \'^\/var\/lib\/munin\/plugin-state\/xm_top\.state$\') && [ `cat /var/lib/munin/plugin-state/xm_top.state | wc -l` -gt 1 ]) || /usr/sbin/xentop -b -i1 > /var/lib/munin/plugin-state/xm_top.state');
+
my $arg; undef($arg);
if (defined($ARGV[0])) {
$arg = 'config' if ($ARGV[0] eq 'config');
@@ -53,8 +57,9 @@ if (defined($ARGV[0])) {
'graph_info' => 'Display the % of CPU Usage for each domain',
);
- my @domains = `$XM list`;
- shift(@domains); # we dont need the header line
+ 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);
@@ -81,16 +86,7 @@ if (defined($ARGV[0])) {
# Nothing was passed as an argument, so let's just return the proper values
-my @chunks; undef(@chunks);
-
-{
- # run the xentop command a few times because the first reading is not always accurate
- local $/ = undef;
- @chunks = split(/^xentop - .*$/m, `$XMTOP -b -i2 -d2`);
-}
-
-# Take only the last run of xentop
-my @stats = split (/\n/,pop(@chunks));
+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);