1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
diff --git a/libexec/check_mysql_performance b/libexec/check_mysql_performance
index 9a7e0a5..0e59d35 100755
--- a/libexec/check_mysql_performance
+++ b/libexec/check_mysql_performance
@@ -11,9 +11,9 @@ use Nagios::Plugin;
my $np = Nagios::Plugin->new(
'usage' => <<EOH,
-Usage: %s [-H host] [-d DSN] -u -p --group
+Usage: %s [-H host] [-d DSN] [--perfdata ] [[-u] [-p]|--extra-opts=[section][\@file]] --group
EOH
- 'version' => '1.00',
+ 'version' => '1.10',
'url' => 'http://www.capside.com',
'extra' => <<EOH,
@@ -21,16 +21,15 @@ Threshold formats are specified at:
http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT
'blurb' => qq{Copyright (c) CAPSiDE.
-
-This plugin montitors the % use of CPU usage on Linux systems for various types of CPU usage.
EOH
);
$np->add_arg(
spec => 'perfdata=s',
help => <<EOH,
---perfdata performance data to output
- Host to query
+--perfdata performance data to check and output
+ e.g. metric[=warn_range;][critcal_range],metric,...
+ note semicolons will need escaping when entered in the UI
EOH
required => 0,
);
@@ -108,7 +107,8 @@ $SIG{'ALRM'} = sub {
$np->nagios_exit( CRITICAL, 'ERROR: Timed out.' );
};
-my ( $code, $message ) = ( OK, 'All parameters OK' );
+my ( $code, $message ) = ( undef, undef );
+$np->add_message( OK, "All parameters OK" );
my @fields;
if ( not $np->opts->perfdata ) {
@@ -116,30 +116,50 @@ if ( not $np->opts->perfdata ) {
}
else {
@fields = split( /,/, $np->opts->perfdata );
-
- # @fields = split /,/, join ',', @{$np->opts->perfdata};
}
# Add all performance data
+my $thresholds;
+my $value;
+my $warning;
+my $critical;
+my $minimum;
+my $maximum;
foreach my $key (@fields) {
+ if ( $key =~ /=/ ) {
+ ($key, $thresholds) = split( /=/, $key );
+ ($warning, $critical) = split ( /;/, $thresholds );
+ } else {
+ $thresholds = undef;
+ $warning = undef;
+ $critical = undef;
+ }
if ( $mysql->{'stats'}->{$key}->{'type'} eq 'ABS' ) {
next if ( not defined $read_data->{$key} );
- $np->add_perfdata(
- 'label' => $key,
- 'value' => $read_data->{$key},
- 'uom' => '',
- );
- }
- elsif ( $mysql->{'stats'}->{$key}->{'type'} eq 'DERIVE' ) {
+ $value = $read_data->{$key};
+ } elsif ( $mysql->{'stats'}->{$key}->{'type'} eq 'DERIVE' ) {
next if ( not defined $stat->{$key} );
- $np->add_perfdata(
- 'label' => $key,
- 'value' => $stat->{$key},
- 'uom' => '',
+ $value = $stat->{$key};
+ }
+ $np->add_perfdata(
+ 'label' => $key,
+ 'value' => $value,
+ 'uom' => '',
+ 'warning' => $warning,
+ 'critical' => $critical,
+ );
+ if ( $thresholds ) {
+ $code = $np->check_threshold(
+ 'check' => $value,
+ 'warning' => $warning,
+ 'critical' => $critical,
);
+ if ( $code ) {
+ $np->add_message($code, "$key beyond thresholds,");
+ }
}
}
-
+($code, $message) = $np->check_messages();
$np->nagios_exit( $code, $message );
package MySQL::Stats;
|