diff options
author | Ton Voon <tonvoon@users.sourceforge.net> | 2006-06-08 12:27:44 +0000 |
---|---|---|
committer | Ton Voon <tonvoon@users.sourceforge.net> | 2006-06-08 12:27:44 +0000 |
commit | 2c6651034f76e2bccb549a867485f8fabbf07cb1 (patch) | |
tree | 8de53d7efe4564017e1ebce73353c7e3a3c8b548 /lib/Nagios/Plugin/Performance.pm | |
parent | 83e29d795dddf34a652cda8665179b77372ddcfe (diff) | |
download | monitoring-plugin-perl-2c6651034f76e2bccb549a867485f8fabbf07cb1.tar.gz |
Initial revision
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1419 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'lib/Nagios/Plugin/Performance.pm')
-rw-r--r-- | lib/Nagios/Plugin/Performance.pm | 119 |
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 @@ | |||
1 | package Nagios::Plugin::Performance; | ||
2 | |||
3 | use 5.008004; | ||
4 | |||
5 | use strict; | ||
6 | use warnings; | ||
7 | |||
8 | use Carp; | ||
9 | use Nagios::Plugin::Threshold; | ||
10 | use Class::Struct; | ||
11 | struct "Nagios::Plugin::Performance" => { | ||
12 | label => '$', | ||
13 | value => '$', | ||
14 | uom => '$', | ||
15 | threshold => 'Nagios::Plugin::Threshold', | ||
16 | min => '$', | ||
17 | max => '$', | ||
18 | }; | ||
19 | |||
20 | sub 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 | |||
26 | sub _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 | |||
41 | sub 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 | |||
54 | 1; | ||
55 | __END__ | ||
56 | |||
57 | =head1 NAME | ||
58 | |||
59 | Nagios::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 | |||
72 | Handles common Nagios Plugin performance data. This has a public interface because it could be | ||
73 | used by performance graphing routines, such as nagiostat (http://nagiostat.sourceforge.net), | ||
74 | perfparse (http://perfparse.sourceforge.net), nagiosgraph (http://nagiosgraph.sourceforge.net) or | ||
75 | NagiosGrapher (http://www.nagiosexchange.org/NagiosGrapher.84.0.html). | ||
76 | |||
77 | Once 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 | |||
85 | Returns an array of Nagios::Plugin::Performance objects based on the string entered. | ||
86 | If there is an error parsing the string, undef is returned. | ||
87 | |||
88 | =head1 OBJECT METHODS | ||
89 | |||
90 | =item label, value, uom, min, max | ||
91 | |||
92 | These all return scalars. min and max are not well supported yet. | ||
93 | |||
94 | =item threshold | ||
95 | |||
96 | This returns a Nagios::Plugin::Threshold object. | ||
97 | |||
98 | =back | ||
99 | |||
100 | =head1 SEE ALSO | ||
101 | |||
102 | Nagios::Plugin for information about versioning. | ||
103 | |||
104 | http://nagiosplug.sourceforge.net | ||
105 | |||
106 | =head1 AUTHOR | ||
107 | |||
108 | Ton Voon, E<lt>ton.voon@altinity.comE<gt> | ||
109 | |||
110 | =head1 COPYRIGHT AND LICENSE | ||
111 | |||
112 | Copyright (C) 2006 by Altinity Limited | ||
113 | |||
114 | This library is free software; you can redistribute it and/or modify | ||
115 | it under the same terms as Perl itself, either Perl version 5.8.4 or, | ||
116 | at your option, any later version of Perl 5 you may have available. | ||
117 | |||
118 | |||
119 | =cut | ||