summaryrefslogtreecommitdiff
path: root/check_postgres.pl
diff options
context:
space:
mode:
authorGreg Sabino Mullane2009-08-23 12:38:07 +0000
committerGreg Sabino Mullane2009-08-23 12:38:07 +0000
commit16120a7559a7f087968fdf5df251023d67860eed (patch)
treed9061048109159c03f25349f3c1f25eb9a477bfa /check_postgres.pl
parente375c8631cd6cafa3cc235f643a7d6230a632cd5 (diff)
Add fix from Glyn Astill for warning > critical in replicate_row
Diffstat (limited to 'check_postgres.pl')
-rwxr-xr-xcheck_postgres.pl119
1 files changed, 81 insertions, 38 deletions
diff --git a/check_postgres.pl b/check_postgres.pl
index bc54bd548..bc9d7bcdb 100755
--- a/check_postgres.pl
+++ b/check_postgres.pl
@@ -29,7 +29,7 @@ $Data::Dumper::Varname = 'POSTGRES';
$Data::Dumper::Indent = 2;
$Data::Dumper::Useqq = 1;
-our $VERSION = '2.10.0';
+our $VERSION = '2.10.1';
use vars qw/ %opt $PSQL $res $COM $SQL $db /;
@@ -1998,6 +1998,21 @@ sub size_in_bytes { ## no critic (RequireArgUnpacking)
} ## end of size_in_bytes
+sub bytes_in_size {
+
+ ## Given a number in bytes and a unit, return the number in the unit.
+ ## Defaults to bytes
+
+ my ($val,$unit) = ($_[0],lc substr($_[1]||'s',0,1));
+ $val=0 if (!$val);
+ return sprintf("%.3f", $val / ($unit eq 'b' ? 1 : $unit eq 'k' ? 1024 : $unit eq 'm' ? 1024**2 :
+ $unit eq 'g' ? 1024**3 : $unit eq 't' ? 1024**4 :
+ $unit eq 'p' ? 1024**5 : $unit eq 'e' ? 1024**6 :
+ $unit eq 'z' ? 1024**7 : 1));
+
+} ## end of bytes_in_size
+
+
sub size_in_seconds {
my ($string,$type) = @_;
@@ -2094,7 +2109,7 @@ sub validate_range {
my $arg = shift;
defined $arg and ref $arg eq 'HASH' or ndie qq{validate_range must be called with a hashref\n};
- return ('','') if $MRTG and !$arg->{forcemrtg};
+ return ('','','','') if $MRTG and !$arg->{forcemrtg};
my $type = $arg->{type} or ndie qq{validate_range must be provided a 'type'\n};
@@ -2105,6 +2120,10 @@ sub validate_range {
my $critical = exists $opt{critical} ? $opt{critical} :
exists $opt{warning} ? '' : $arg->{default_critical} || '';
+ # We need the extension : KB,GB, etc... or % for cleaner nagios output
+ my $wuom;
+ my $cuom;
+
if ('string' eq $type) {
## Don't use this unless you have to
}
@@ -2114,12 +2133,14 @@ sub validate_range {
ndie msg('range-seconds', 'warning');
}
$warning = $1;
+ $wuom = 's';
}
if (length $critical) {
if ($critical !~ $timesecre) {
ndie msg('range-seconds', 'critical')
}
$critical = $1;
+ $cuom = 's';
if (length $warning and $warning > $critical) {
ndie msg('range-warnbigtime', $warning, $critical);
}
@@ -2134,6 +2155,8 @@ sub validate_range {
if (length $warning and length $critical and $warning > $critical) {
ndie msg('range-warnbigtime', $warning, $critical);
}
+ $wuom = 's';
+ $cuom = 's';
}
elsif ('version' eq $type) {
my $msg = msg('range-version');
@@ -2153,12 +2176,17 @@ sub validate_range {
ndie msg('range-badsize', 'critical');
}
$critical = size_in_bytes($1,$2);
+ $cuom=uc "$2b";
}
if (length $warning) {
if ($warning !~ $sizere) {
ndie msg('range-badsize', 'warning');
}
+die "Got $1 and $2\n";
+
+$wuom = "$1";
$warning = size_in_bytes($1,$2);
+ $wuom=uc "$2b";
if (length $critical and $warning > $critical) {
ndie msg('range-warnbigsize', $warning, $critical);
}
@@ -2205,29 +2233,39 @@ sub validate_range {
if ($critical !~ /^\d+\%$/) {
ndie msg('range-badpercent', 'critical');
}
+ $cuom = '%';
}
if (length $warning) {
if ($warning !~ /^\d+\%$/) {
ndie msg('range-badpercent', 'warning');
}
+ $wuom = '%';
}
}
elsif ('size or percent' eq $type) {
if (length $critical) {
if ($critical =~ $sizere) {
$critical = size_in_bytes($1,$2);
+ $cuom=uc "$2b";
}
elsif ($critical !~ /^\d+\%$/) {
ndie msg('range-badpercsize', 'critical');
}
+ else {
+ $cuom = '%';
+ }
}
if (length $warning) {
if ($warning =~ $sizere) {
$warning = size_in_bytes($1,$2);
+ $wuom=uc "$2b";
}
elsif ($warning !~ /^\d+\%$/) {
ndie msg('range-badpercsize', 'warning');
}
+ else {
+ $wuom = '%';
+ }
}
elsif (! length $critical) {
ndie msg('range-noopt-size');
@@ -2295,7 +2333,7 @@ sub validate_range {
}
}
- return ($warning,$critical);
+ return ($warning,$critical, $wuom, $cuom);
} ## end of validate_range
@@ -2308,7 +2346,7 @@ sub check_autovac_freeze {
## Warning and criticals are percentages
## Can also ignore databases with exclude, and limit with include
- my ($warning, $critical) = validate_range
+ my ($warning, $critical, $wuom, $cuom) = validate_range
({
type => 'percent',
default_warning => '90%',
@@ -2560,7 +2598,7 @@ sub check_bloat {
$LIMIT = $opt{perflimit};
}
- my ($warning, $critical) = validate_range
+ my ($warning, $critical, $wuom, $cuom) = validate_range
({
type => 'size or percent',
default_warning => '1 GB',
@@ -2817,7 +2855,7 @@ sub check_database_size {
## Limit to a specific user (db owner) with the includeuser option
## Exclude users with the excludeuser option
- my ($warning, $critical) = validate_range({type => 'size'});
+ my ($warning, $critical, $wuom, $cuom) = validate_range({type => 'size'});
$USERWHERECLAUSE =~ s/AND/WHERE/;
@@ -2858,9 +2896,16 @@ sub check_database_size {
}
my $msg = '';
+ my ($nwarn, $ncrit)= ('', '');
+ $nwarn = bytes_in_size($warning,$wuom) if ($warning);
+ $ncrit = bytes_in_size($critical,$wuom) if ($critical);
+
for (sort {$s{$b}[0] <=> $s{$a}[0] or $a cmp $b } keys %s) {
$msg .= "$_: $s{$_}[0] ($s{$_}[1]) ";
- $db->{perf} .= " $_=$s{$_}[0]";
+ $wuom=$cuom if (!$wuom);
+ $db->{perf} .= " '$_'="
+ .bytes_in_size($s{$_}[0],$wuom)."$wuom"
+ .";$nwarn".";$ncrit";
}
if (length $critical and $max >= $critical) {
add_critical $msg;
@@ -2897,7 +2942,7 @@ sub check_disk_space {
## NOTE: Needs to run on the same system (for now)
## XXX Allow custom ssh commands for remote df and the like
- my ($warning, $critical) = validate_range
+ my ($warning, $critical, $wuom, $cuom) = validate_range
({
type => 'size or percent',
default_warning => '90%',
@@ -3075,7 +3120,7 @@ sub check_fsm_pages {
## Critical and warning are a percentage of max_fsm_pages
## Example: --critical=95
- my ($warning, $critical) = validate_range
+ my ($warning, $critical, $wuom, $cuom) = validate_range
({
type => 'percent',
default_warning => '85%',
@@ -3136,7 +3181,7 @@ sub check_fsm_relations {
## Critical and warning are a percentage of max_fsm_relations
## Example: --critical=95
- my ($warning, $critical) = validate_range
+ my ($warning, $critical, $wuom, $cuom) = validate_range
({
type => 'percent',
default_warning => '85%',
@@ -3195,7 +3240,7 @@ sub check_wal_files {
## Critical and warning are the number of files
## Example: --critical=40
- my ($warning, $critical) = validate_range({type => 'integer', leastone => 1});
+ my ($warning, $critical, $wuom, $cuom) = validate_range({type => 'integer', leastone => 1});
## Figure out where the pg_xlog directory is
$SQL = q{SELECT count(*) FROM pg_ls_dir('pg_xlog') WHERE pg_ls_dir ~ E'^[0-9A-F]{24}$'}; ## no critic (RequireInterpolationOfMetachars)
@@ -3248,7 +3293,7 @@ sub check_relation_size {
## Limit to a specific user (relation owner) with the includeuser option
## Exclude users with the excludeuser option
- my ($warning, $critical) = validate_range({type => 'size'});
+ my ($warning, $critical, $wuom, $cuom) = validate_range({type => 'size'});
$SQL = q{SELECT pg_relation_size(c.oid), pg_size_pretty(pg_relation_size(c.oid)), relkind, relname, nspname };
$SQL .= sprintf 'FROM pg_class c, pg_namespace n WHERE (relkind = %s) AND n.oid = c.relnamespace',
@@ -3354,7 +3399,7 @@ sub check_last_vacuum_analyze {
## Example:
## --exclude=~pg_ --include=pg_class,pg_attribute
- my ($warning, $critical) = validate_range
+ my ($warning, $critical, $wuom, $cuom) = validate_range
({
type => 'time',
default_warning => '1 day',
@@ -3470,7 +3515,7 @@ sub check_listener {
$opt{critical} = $opt{mrtg};
}
- my ($warning, $critical) = validate_range({type => 'restringex', forcemrtg => 1});
+ my ($warning, $critical, $wuom, $cuom) = validate_range({type => 'restringex', forcemrtg => 1});
my $string = length $critical ? $critical : $warning;
my $regex = ($string =~ s/^~//) ? '~' : '=';
@@ -3517,7 +3562,7 @@ sub check_locks {
## Lock names are case-insensitive, and do not need the "lock" at the end.
## Example: --warning=100 --critical="total=200;exclusive=20;waiting=5"
- my ($warning, $critical) = validate_range
+ my ($warning, $critical, $wuom, $cuom) = validate_range
({
type => 'multival',
default_warning => 100,
@@ -3758,7 +3803,7 @@ sub check_query_runtime {
## --warning="100s" --critical="120s" --queryname="speedtest1"
## --warning="5min" --critical="15min" --queryname="speedtest()"
- my ($warning, $critical) = validate_range({type => 'time'});
+ my ($warning, $critical, $wuom, $cuom) = validate_range({type => 'time'});
my $queryname = $opt{queryname} || '';
@@ -3812,7 +3857,7 @@ sub check_query_time {
## Limit to a specific user with the includeuser option
## Exclude users with the excludeuser option
- my ($warning, $critical) = validate_range
+ my ($warning, $critical, $wuom, $cuom) = validate_range
({
type => 'time',
default_warning => '2 minutes',
@@ -3884,7 +3929,7 @@ sub check_txn_time {
## Limit to a specific user with the includeuser option
## Exclude users with the excludeuser option
- my ($warning, $critical) = validate_range
+ my ($warning, $critical, $wuom, $cuom) = validate_range
({
type => 'time',
});
@@ -3957,7 +4002,7 @@ sub check_txn_idle {
## Limit to a specific user with the includeuser option
## Exclude users with the excludeuser option
- my ($warning, $critical) = validate_range
+ my ($warning, $critical, $wuom, $cuom) = validate_range
({
type => 'time',
});
@@ -4040,7 +4085,7 @@ sub check_settings_checksum {
## Example:
## check_postgres_settings_checksum --critical="4e7ba68eb88915d3d1a36b2009da4acd"
- my ($warning, $critical) = validate_range({type => 'checksum', onlyone => 1});
+ my ($warning, $critical, $wuom, $cuom) = validate_range({type => 'checksum', onlyone => 1});
eval {
require Digest::MD5;
@@ -4099,7 +4144,7 @@ sub check_timesync {
## Supports: Nagios, MRTG
## Warning and critical are given in number of seconds difference
- my ($warning,$critical) = validate_range
+ my ($warning,$critical, $wuom, $cuom) = validate_range
({
type => 'seconds',
default_warning => 2,
@@ -4151,7 +4196,7 @@ sub check_txn_wraparound {
## See: http://www.postgresql.org/docs/current/static/routine-vacuuming.html#VACUUM-FOR-WRAPAROUND
## It makes no sense to run this more than once on the same cluster
- my ($warning, $critical) = validate_range
+ my ($warning, $critical, $wuom, $cuom) = validate_range
({
type => 'positive integer',
default_warning => 1_300_000_000,
@@ -4220,7 +4265,7 @@ sub check_version {
}
}
- my ($warning, $critical) = validate_range({type => 'version', forcemrtg => 1});
+ my ($warning, $critical, $wuom, $cuom) = validate_range({type => 'version', forcemrtg => 1});
my ($warnfull, $critfull) = (($warning =~ /^\d+\.\d+$/ ? 0 : 1),($critical =~ /^\d+\.\d+$/ ? 0 : 1));
@@ -4272,7 +4317,7 @@ sub check_custom_query {
my $valtype = $opt{valtype} || 'integer';
- my ($warning, $critical) = validate_range({type => $valtype, leastone => 1});
+ my ($warning, $critical, $wuom, $cuom) = validate_range({type => $valtype, leastone => 1});
my $query = $opt{query} or ndie msg('custom-nostring');
@@ -4334,10 +4379,10 @@ sub check_replicate_row {
## Supports: Nagios, MRTG
## Warning and critical are time to replicate to all slaves
- my ($warning, $critical) = validate_range({type => 'time', leastone => 1, forcemrtg => 1});
+ my ($warning, $critical, $wuom, $cuom) = validate_range({type => 'time', leastone => 1, forcemrtg => 1});
- if ($warning and $critical and $critical > $warning) {
- ndie msg('range-warnsmall');
+ if ($warning and $critical and $warning > $critical) {
+ ndie msg('range-warnbig');
}
if (!$opt{repinfo}) {
@@ -5743,7 +5788,7 @@ sub check_sequence {
## Warning and critical are percentages
## Can exclude and include sequences
- my ($warning, $critical) = validate_range
+ my ($warning, $critical, $wuom, $cuom) = validate_range
({
type => 'percent',
default_warning => '85%',
@@ -5872,7 +5917,7 @@ sub check_checkpoint {
## Warning and critical are seconds
## Requires $ENV{PGDATA} or --datadir
- my ($warning, $critical) = validate_range
+ my ($warning, $critical, $wuom, $cuom) = validate_range
({
type => 'time',
leastone => 1,
@@ -5969,7 +6014,7 @@ sub check_disabled_triggers {
## Supports: Nagios, MRTG
## Warning and critical are integers, defaults to 1
- my ($warning, $critical) = validate_range
+ my ($warning, $critical, $wuom, $cuom) = validate_range
({
type => 'positive integer',
default_warning => 1,
@@ -6135,7 +6180,7 @@ sub check_prepared_txns {
## Most installations probably want no prepared_transactions
## Supports: Nagios, MRTG
- my ($warning, $critical) = validate_range
+ my ($warning, $critical, $wuom, $cuom) = validate_range
({
type => 'seconds',
default_warning => '1',
@@ -6211,7 +6256,7 @@ sub show_dbstats {
## Supports: Cacti
## Assumes psql and target are the same version for the 8.3 check
- my ($warning, $critical) = validate_range
+ my ($warning, $critical, $wuom, $cuom) = validate_range
({
type => 'cacti',
});
@@ -6264,7 +6309,7 @@ sub show_dbstats {
B<check_postgres.pl> - a Postgres monitoring script for Nagios, MRTG, Cacti, and others
-This documents describes check_postgres.pl version 2.10.0
+This documents describes check_postgres.pl version 2.10.1
=head1 SYNOPSIS
@@ -7707,15 +7752,13 @@ Items not specifically attributed are by Greg Sabino Mullane.
=item B<Version 2.11.0>
- Add the --no-check_postgresrc flag.
- Ensure check_postgresrc options are completely overriden by command-line options.
-
-=item B<Version 2.10.1>
-
Add Nagios perf output to the wal_files check (Cédric Villemain)
Add support for .check_postgresrc, per request from Albe Laurenz.
Allow list of web fetch methods to be changed with the --get_method option.
Add support for the --language argument, which overrides any ENV.
+ Add the --no-check_postgresrc flag.
+ Ensure check_postgresrc options are completely overriden by command-line options.
+ Fix incorrect warning > critical logic in replicate_rows (Glyn Astill)
=item B<Version 2.10.0> (August 3, 2009)