NAME
OSLV::Monitor - OS level virtualization monitoring extend for LibreNMS.
VERSION
Version 1.0.7
SYNOPSIS
Quick summary of what the module does.
Perhaps a little code snippet.
use OSLV::Monitor;
my $monitor = OSLV::Monitor->new();
eval { $monitor->load; };
if ($@) {
print encode_json( { version => 1, data => {}, error => 1, errorString => 'load failed... ' . $@ } ) . "\n";
exit 1;
}
my $data = encode_json( $monitor->run );
print $data."\n";
METHODS
new
Inits the object.
One option is taken and that is a hash ref.
# init with the cbsd backend
my $monitor->new(backend=>'FreeBSD');
The keys are list as below.
- backend :: The name of the backend to use. If undef, it is choosen based on $^O
freebsd :: FreeBSD
linux :: cgroups
- base_dir :: The dir to use for any caches as well as output.
Default :: /var/cache/oslv_monitor
- include :: An array of regexps to match names against for seeing if they should
be included or not. By default everything is return.
- Default :: ['^.+$']
- exclude :: An array of regexps to exclude. By default this array is empty. It is
processed after the include array.
- Default :: []
- time_divider :: What to pass to the backend for the time_divider for that if needed.
Default :: 1000000
- lock :: If true, run takes a exclusive lock on $base_dir/lock so that
overlapping runs do not clobber each other's cache. If another run
holds it, run returns a error right away. See lock_failed.
Default :: 0
load
This loads the specified backend.
eval{ $monitor->load; };
if ( $@ ){
print "Failed to load the backend... ".$@;
}
run
Runs the poller backend and report the results.
If nothing is nothing is loaded, load will be called.
my $status=$monitor->run;
lock_failed
Returns 1 if the last call to run returned early because the lock could not be taken, either due to another run holding it or the lock file not being openable, otherwise 0. Always 0 if lock was not enabled.
This lets a caller tell a skipped run apart from a failed one, such as to keep the output of the previous run instead of replacing it with the error.
my $status = $monitor->run;
if ( $monitor->lock_failed ) {
exit 1;
}
interval_since
Returns the number of seconds between the run that saved a backend's cache and the current run, for turning counter deltas into per second rates.
Two args are taken. The first is the decoded cache hash ref, which holds the time of the run that saved it as {__oslv_monitor__}{time}. The second is the time of the current run, as returned by "time" in Time::HiRes.
300, the expected cron interval, is returned if the cache is undef, lacks a time, as one written by a older version would, or if the time is not before the current one, as happens if the clock was set backwards.
my $run_time = Time::HiRes::time;
my $interval = $monitor->interval_since( $cache, $run_time );
# 1000 / 300 for a run 5 minutes after the previous
my $rate = $counter_delta / $interval;
include
Checks if a name should be included, as decided by the include and exclude regexps passed to "new". The backends call this for each name found.
One arg is taken, the name to check.
Returns 1 if the name matches a include and no excludes, otherwise 0. 0 is also returned if the name is undef, a ref, or "".
# with include => ['^s_'] and exclude => ['^s_cron$']
$monitor->include('s_ssh'); # 1
$monitor->include('s_cron'); # 0
$monitor->include('u_1000'); # 0
AUTHOR
Zane C. Bowers-Hadley, <vvelox at vvelox.net>
BUGS
Please report any bugs or feature requests to bug-oslv-monitor at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=OSLV-Monitor. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc OSLV::Monitor
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
LICENSE AND COPYRIGHT
This software is Copyright (c) 2024 by Zane C. Bowers-Hadley.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)