root/lib/Resmon/Module.pm

Revision 08e7243a3d45b0161416493e76a32e1723a8f3f4, 0.8 kB (checked in by Mark Harrison <mark@mivok.net>, 2 years ago)

Fix per-check interval/cached metrics

Credit: Michal Racek <michal.racek@t-systems.sk>

In Resmon 1, it was possible to add an interval parameter to an individual
check to give it a larger check interval than regular checks (cached results
would be returned in the meantime). This functionality wasn't properly carried
over into resmon 2, and this commit fixes that.

  • Property mode set to 100644
Line 
1 package Resmon::Module;
2 use strict;
3 use warnings;
4
5 sub new {
6     my ($class, $check_name, $config) = @_;
7     my $self = {};
8     $self->{config} = $config;
9     $self->{check_name} = $check_name;
10     bless ($self, $class);
11     return $self;
12 }
13
14 sub handler {
15     die "Monitor not implemented. Perhaps this is a wilcard only module?\n";
16 }
17
18 sub wildcard_handler {
19     die "Monitor not implemented. Perhaps this is a non-wildcard module?\n";
20 }
21
22 sub cache_metrics {
23     # Simple method to cache the results of a check
24     my $self = shift;
25     $self->{lastmetrics} = shift;
26     $self->{lastupdate} = time;
27 }
28
29 sub get_cached_metrics {
30     my $self = shift;
31     return undef unless $self->{config}->{interval};
32     my $now = time;
33     if(($self->{lastupdate} + $self->{config}->{interval}) >= $now) {
34         return $self->{lastmetrics};
35     }
36     return undef;
37 }
38
39 1;
Note: See TracBrowser for help on using the browser.