Title: [opsview] [9784] Improved cache handling in check_apache_performance
- Revision
- 9784
- Author
- tvoon
- Date
- 2012-08-09 18:20:14 +0100 (Thu, 09 Aug 2012)
Log Message
Improved cache handling in check_apache_performance
Modified Paths
Modified: trunk/CHANGES
===================================================================
--- trunk/CHANGES 2012-08-09 17:00:03 UTC (rev 9783)
+++ trunk/CHANGES 2012-08-09 17:20:14 UTC (rev 9784)
@@ -23,6 +23,7 @@
Log the full query_host command into opsview-web.log if there is an error picked up
Updated Perl modules as of July 2012
Allow check_snmp performance data units to be overridden
+ Improved cache handling in check_apache_performance
NOTICES:
Removed support for Ubuntu Hardy
Opsview Web does not install new monitor packs on start - use install_all_opspacks command line utility
Modified: trunk/opsview-core/nagios-plugins/check_apache_performance
===================================================================
--- trunk/opsview-core/nagios-plugins/check_apache_performance 2012-08-09 17:00:03 UTC (rev 9783)
+++ trunk/opsview-core/nagios-plugins/check_apache_performance 2012-08-09 17:20:14 UTC (rev 9784)
@@ -24,7 +24,10 @@
use Nagios::Plugin;
use LWP::UserAgent;
use URI::URL;
+use Time::HiRes;
+my $cache_file_base = "/tmp/_check_apache_performance-";
+
#valid metricnames array. Keep this list sorted.
my @valid_metricname = (
"accesses", "active_sessions",
@@ -182,9 +185,27 @@
=~ /Total\s+accesses:\s+(\d+)\s+-\s+Total\s+Traffic:\s+([\d\.]+)\s+(\w+)/
)
{
+
+ # Don't interfere with the cached data if we're not actually using these values in this invocation
+ next
+ if (
+ $np->opts->metricname
+ && $np->opts->metricname ne "accesses"
+ && $np->opts->metricname ne "traffic"
+ );
+
+ # Use a per-metric cache file, or an 'all' file if we're not checking a specific metric
+ my $file_label;
+ if ( $np->opts->metricname ) {
+ $file_label = $np->opts->metricname;
+ }
+ else {
+ $file_label = "all";
+ }
+
my ( $traffic_uom, $traffic_m ) = &convert_uoms( "$3" );
my $v = $2 * $traffic_m;
- my $stat = &get_rate( $1, $v );
+ my $stat = &get_rate( $1, $v, $file_label );
$results{'accesses'} = $stat->{'accesses'};
$results{'traffic'} = $stat->{'traffic'} . " " . $traffic_uom;
}
@@ -323,22 +344,24 @@
#sub to get the performance rate of change of metric
sub get_rate {
- my ( $accesses, $traffic ) = @_;
- my $diff = Nagios::Plugin::Differences->new();
- my $ts = {
+ my ( $accesses, $traffic, $label ) = @_;
+ my $cache_file_name = "$cache_file_base$hostname-$label-lastrun.tmp";
+
+ my $diff = Nagios::Plugin::Differences->new( "file" => $cache_file_name );
+ my $ts = {
accesses => $accesses,
traffic => $traffic
};
eval { $diff->load_last; };
if ($@) {
my $read_data = $ts;
- $diff->new_reading($read_data);
+ $diff->new_reading( $read_data, scalar(Time::HiRes::gettimeofday) );
$diff->persist;
$np->nagios_exit( UNKNOWN, "Couldn't see last state $@" );
}
my $read_data = $ts;
- $diff->new_reading($read_data);
+ $diff->new_reading( $read_data, scalar(Time::HiRes::gettimeofday) );
$diff->persist;
my $stat = $diff->rate( 'forward_difference_unknown_wrap' );
return $stat;
_______________________________________________
Opsview-checkins mailing list
[email protected]
http://lists.opsview.org/lists/listinfo/opsview-checkins