From 0d5407168827cb293abd9f0b5ecd406b16783f01 Mon Sep 17 00:00:00 2001 From: mh Date: Wed, 11 Aug 2010 09:59:09 +0200 Subject: introduce caching for xen plugins calls to the xen binaries such as xm are quite heavy and we therefore cache now a lot of the data that is generated for these plugins and use them as well for the other ones. --- files/plugins/xen-cpu | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'files/plugins/xen-cpu') 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); -- cgit v1.2.3