summaryrefslogtreecommitdiffstats
path: root/lib/Nagios/Plugin/Performance.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Nagios/Plugin/Performance.pm')
-rw-r--r--lib/Nagios/Plugin/Performance.pm119
1 files changed, 119 insertions, 0 deletions
diff --git a/lib/Nagios/Plugin/Performance.pm b/lib/Nagios/Plugin/Performance.pm
new file mode 100644
index 0000000..eee1bee
--- /dev/null
+++ b/lib/Nagios/Plugin/Performance.pm
@@ -0,0 +1,119 @@
1package Nagios::Plugin::Performance;
2
3use 5.008004;
4
5use strict;
6use warnings;
7
8use Carp;
9use Nagios::Plugin::Threshold;
10use Class::Struct;
11struct "Nagios::Plugin::Performance" => {
12 label => '$',
13 value => '$',
14 uom => '$',
15 threshold => 'Nagios::Plugin::Threshold',
16 min => '$',
17 max => '$',
18 };
19
20sub perfoutput {
21 my $self = shift;
22 my $output = $self->label."=".$self->value.$self->uom.";".$self->threshold->warning.";".$self->threshold->critical;
23 return $output;
24}
25
26sub _parse {
27 my $class = shift;
28 my $string = shift;
29 my $p = $class->new;
30 $string =~ s/^([^=]+)=([\d\.]+)(\w*);?([\d\.]+)?;?([\d\.]+)?;?([\d\.]+)?;?([\d\.]+)? *//;
31 return undef unless ($1 && $2);
32 $p->label($1);
33 $p->value($2+0);
34 $p->uom($3);
35 $p->threshold(Nagios::Plugin::Threshold->set_thresholds(warning => $4, critical => $5));
36 $p->min($6);
37 $p->max($7);
38 return ($p, $string);
39}
40
41sub parse_perfstring {
42 my ($class, $perfstring) = @_;
43 my @perfs;
44 my $obj;
45 while ($perfstring) {
46 ($obj, $perfstring) = $class->_parse($perfstring);
47 return undef unless $obj;
48 push @perfs, $obj;
49 }
50 return undef unless @perfs;
51 return @perfs;
52}
53
541;
55__END__
56
57=head1 NAME
58
59Nagios::Plugin::Performance - Performance information in a perl object
60
61=head1 SYNOPSIS
62
63 use Nagios::Plugin::Performance;
64
65 @p = Nagios::Plugin::Performance->parse_perfstring("/=382MB;15264;15269;; /var=218MB;9443;9448");
66 print "1st label = ", $p[0]->label, $/;
67 print "1st uom = ", $p[0]->uom, $/;
68 print "2nd crit = ", $p[1]->threshold->critical, $/;
69
70=head1 DESCRIPTION
71
72Handles common Nagios Plugin performance data. This has a public interface because it could be
73used by performance graphing routines, such as nagiostat (http://nagiostat.sourceforge.net),
74perfparse (http://perfparse.sourceforge.net), nagiosgraph (http://nagiosgraph.sourceforge.net) or
75NagiosGrapher (http://www.nagiosexchange.org/NagiosGrapher.84.0.html).
76
77Once the performance string has been parsed, you can query the label, value, uom, or thresholds.
78
79=head1 CLASS METHODS
80
81=over 4
82
83=item Nagios::Plugin::Performance->parse_perfstring($string)
84
85Returns an array of Nagios::Plugin::Performance objects based on the string entered.
86If there is an error parsing the string, undef is returned.
87
88=head1 OBJECT METHODS
89
90=item label, value, uom, min, max
91
92These all return scalars. min and max are not well supported yet.
93
94=item threshold
95
96This returns a Nagios::Plugin::Threshold object.
97
98=back
99
100=head1 SEE ALSO
101
102Nagios::Plugin for information about versioning.
103
104http://nagiosplug.sourceforge.net
105
106=head1 AUTHOR
107
108Ton Voon, E<lt>ton.voon@altinity.comE<gt>
109
110=head1 COPYRIGHT AND LICENSE
111
112Copyright (C) 2006 by Altinity Limited
113
114This library is free software; you can redistribute it and/or modify
115it under the same terms as Perl itself, either Perl version 5.8.4 or,
116at your option, any later version of Perl 5 you may have available.
117
118
119=cut