Navigation Menu

Skip to content

Commit

Permalink
Merge commit 'petdance/master'
Browse files Browse the repository at this point in the history
Conflicts:
	TODO
	check_postgres.pl
  • Loading branch information
Greg Sabino Mullane committed Apr 7, 2010
2 parents 0d0b329 + f427b70 commit 79c0d64
Show file tree
Hide file tree
Showing 2 changed files with 183 additions and 12 deletions.
13 changes: 11 additions & 2 deletions TODO
@@ -1,5 +1,9 @@
Quick list of outstanding items / bugs / feature requests for CP: Quick list of outstanding items / bugs / feature requests for CP:


* Add a --output=plain, for simple human-readable output.

* Add a --output=csv, for importing into various targets.

* Language testing: force to EN? * Language testing: force to EN?


* Allow a flag to determine if skipped into goes into perf or not * Allow a flag to determine if skipped into goes into perf or not
Expand Down Expand Up @@ -29,8 +33,6 @@ Quick list of outstanding items / bugs / feature requests for CP:


* Check at least one table has been vacuumed/analyzed since X time * Check at least one table has been vacuumed/analyzed since X time


* Put on CPAN

* Check every table has been vacuum|analyze at least once. (no NULL) * Check every table has been vacuum|analyze at least once. (no NULL)


* Check at least one table has been vacuumed|analyzed since X hours/days/... * Check at least one table has been vacuumed|analyzed since X hours/days/...
Expand All @@ -43,3 +45,10 @@ Quick list of outstanding items / bugs / feature requests for CP:


* For the Nagios 'perf' output on last_analyze and last_vacuum (and other things with a time), * For the Nagios 'perf' output on last_analyze and last_vacuum (and other things with a time),
consider making a single global timing call. consider making a single global timing call.

# Perl-specific

* Put on CPAN

* Create a Perl::Critic test suite

182 changes: 172 additions & 10 deletions check_postgres.pl
Expand Up @@ -286,7 +286,7 @@ package check_postgres;
'txnwrap-cbig' => q{The 'critical' value must be less than 2 billion}, 'txnwrap-cbig' => q{The 'critical' value must be less than 2 billion},
'txnwrap-wbig' => q{The 'warning' value must be less than 2 billion}, 'txnwrap-wbig' => q{The 'warning' value must be less than 2 billion},
'unknown-error' => q{Unknown error}, 'unknown-error' => q{Unknown error},
'usage' => qq{\nUsage: \$1 <options>\n Try "\$1 --help" for a complete list of options\n\n}, 'usage' => qq{\nUsage: \$1 <options>\n Try "\$1 --help" for a complete list of options\n Try "\$1 --man" for the full manual\n},
'username' => q{username}, 'username' => q{username},
'vac-msg' => q{DB: $1 TABLE: $2}, 'vac-msg' => q{DB: $1 TABLE: $2},
'vac-nomatch-a' => q{No matching tables have ever been analyzed}, 'vac-nomatch-a' => q{No matching tables have ever been analyzed},
Expand Down Expand Up @@ -683,6 +683,7 @@ package check_postgres;
'version|V', 'version|V',
'verbose|v+', 'verbose|v+',
'help|h', 'help|h',
'man',
'output=s', 'output=s',
'simple', 'simple',
'showperf=i', 'showperf=i',
Expand Down Expand Up @@ -735,6 +736,12 @@ package check_postgres;
and keys %opt and keys %opt
and ! @ARGV; and ! @ARGV;


if ( $opt{man} ) {
require Pod::Usage;
Pod::Usage::pod2usage({-verbose => 2});
exit;
}

## Put multi-val options from check_postgresrc in place, only if no command-line args! ## Put multi-val options from check_postgresrc in place, only if no command-line args!
for my $mv (keys %tempopt) { for my $mv (keys %tempopt) {
$opt{$mv} ||= delete $tempopt{$mv}; $opt{$mv} ||= delete $tempopt{$mv};
Expand Down Expand Up @@ -906,18 +913,19 @@ package check_postgres;
--PSQL=FILE location of the psql executable; avoid using if possible --PSQL=FILE location of the psql executable; avoid using if possible
-v, --verbose verbosity level; can be used more than once to increase the level -v, --verbose verbosity level; can be used more than once to increase the level
-h, --help display this help information -h, --help display this help information
--man display the full manual
-t X, --timeout=X how long in seconds before we timeout. Defaults to 30 seconds. -t X, --timeout=X how long in seconds before we timeout. Defaults to 30 seconds.
--symlinks create named symlinks to the main program for each action --symlinks create named symlinks to the main program for each action
Actions: Actions:
Which test is determined by the --action option, or by the name of the program Which test is determined by the --action option, or by the name of the program
$action_usage $action_usage
For a complete list of options and full documentation, please view the POD for this file. For a complete list of options and full documentation, view the manual.
Two ways to do this is to run:
pod2text $ME | less $ME --man
pod2man $ME | man -l -
Or simply visit: http://bucardo.org/check_postgres/ Or visit: http://bucardo.org/check_postgres/
}; };
Expand Down Expand Up @@ -1047,10 +1055,15 @@ sub add_response {
push @{$type->{''}} => [$msg, length $nohost > 1 ? $nohost : '']; push @{$type->{''}} => [$msg, length $nohost > 1 ? $nohost : ''];
return; return;
} }
<<<<<<< HEAD:check_postgres.pl
=======
my $dbservice = $db->{dbservice};
my $dbname = $db->{dbname};
>>>>>>> petdance/master:check_postgres.pl
my $header = sprintf q{%s%s%s}, my $header = sprintf q{%s%s%s},
$action_info->{$action}[0] ? '' : (defined $db->{dbservice} and length $db->{dbservice}) ? $action_info->{$action}[0] ? '' : (defined $dbservice and length $dbservice) ?
qq{service=$db->{dbservice} } : qq{DB "$db->{dbname}" }, qq{service=$dbservice } : qq{DB "$dbname" },
$db->{host} eq '<none>' ? '' : qq{(host:$db->{host}) }, $db->{host} eq '<none>' ? '' : qq{(host:$db->{host}) },
defined $db->{port} ? ($db->{port} eq $opt{defaultport} ? '' : qq{(port=$db->{port}) }) : ''; defined $db->{port} ? ($db->{port} eq $opt{defaultport} ? '' : qq{(port=$db->{port}) }) : '';
$header =~ s/\s+$//; $header =~ s/\s+$//;
Expand Down Expand Up @@ -2635,6 +2648,8 @@ sub check_backends {
my $ok = 1; my $ok = 1;
if ($e1) { ## minus if ($e1) { ## minus
$ok = 0 if $limit-$total >= $e2; $ok = 0 if $limit-$total >= $e2;
<<<<<<< HEAD:check_postgres.pl
=======
} }
elsif ($e3) { ## percent elsif ($e3) { ## percent
my $nowpercent = $total/$limit*100; my $nowpercent = $total/$limit*100;
Expand All @@ -2661,8 +2676,37 @@ sub check_backends {
if (!$ok) { if (!$ok) {
add_warning $msg; add_warning $msg;
return; return;
>>>>>>> petdance/master:check_postgres.pl
}
elsif ($e3) { ## percent
my $nowpercent = $total/$limit*100;
$ok = 0 if $nowpercent >= $e2;
}
else { ## raw number
$ok = 0 if $total >= $e2;
}
if (!$ok) {
add_critical $msg;
return;
} }
if ($w1) {
$ok = 0 if $limit-$total >= $w2;
}
elsif ($w3) {
my $nowpercent = $total/$limit*100;
$ok = 0 if $nowpercent >= $w2;
}
else {
$ok = 0 if $total >= $w2;
}
if (!$ok) {
add_warning $msg;
return;
}
add_ok $msg;
add_ok $msg; add_ok $msg;
return; return;
Expand Down Expand Up @@ -3061,6 +3105,7 @@ sub check_custom_query {
my ($warning, $critical) = validate_range({type => $valtype, leastone => 1}); my ($warning, $critical) = validate_range({type => $valtype, leastone => 1});
my $query = $opt{query} or ndie msg('custom-nostring'); my $query = $opt{query} or ndie msg('custom-nostring');
<<<<<<< HEAD:check_postgres.pl
my $reverse = $opt{reverse} || 0; my $reverse = $opt{reverse} || 0;
Expand Down Expand Up @@ -3128,6 +3173,75 @@ sub check_database_size {
## Limit to a specific user (db owner) with the includeuser option ## Limit to a specific user (db owner) with the includeuser option
## Exclude users with the excludeuser option ## Exclude users with the excludeuser option
=======
my $reverse = $opt{reverse} || 0;
my $info = run_command($query);
for $db (@{$info->{db}}) {
if (! @{$db->{slurp}}) {
add_unknown msg('custom-norows');
next;
}
my $goodrow = 0;
for my $r (@{$db->{slurp}}) {
my ($data,$msg) = ($r->{result}, $r->{data}||'');
$goodrow++;
$db->{perf} .= " $msg";
my $gotmatch = 0;
if (length $critical) {
if (($valtype eq 'string' and $data eq $critical)
or
($reverse ? $data <= $critical : $data >= $critical)) { ## covers integer, time, size
add_critical "$data";
$gotmatch = 1;
}
}
if (length $warning and ! $gotmatch) {
if (($valtype eq 'string' and $data eq $warning)
or
($reverse ? $data <= $warning : $data >= $warning)) {
add_warning "$data";
$gotmatch = 1;
}
}
if (! $gotmatch) {
add_ok "$data";
}
} ## end each row returned
if (!$goodrow) {
add_unknown msg('custom-invalid');
}
}
return;
} ## end of check_custom_query
sub check_database_size {
## Check the size of one or more databases
## Supports: Nagios, MRTG
## mrtg reports the largest two databases
## By default, checks all databases
## Can check specific one(s) with include
## Can ignore some with exclude
## Warning and critical are bytes
## Valid units: b, k, m, g, t, e
## All above may be written as plural or with a trailing 'b'
## Limit to a specific user (db owner) with the includeuser option
## Exclude users with the excludeuser option
>>>>>>> petdance/master:check_postgres.pl
my ($warning, $critical) = validate_range({type => 'size'}); my ($warning, $critical) = validate_range({type => 'size'});
$USERWHERECLAUSE =~ s/AND/WHERE/; $USERWHERECLAUSE =~ s/AND/WHERE/;
Expand All @@ -3145,9 +3259,15 @@ sub check_database_size {
} }
my $info = run_command($SQL, { regex => qr{\d+}, emptyok => 1, } ); my $info = run_command($SQL, { regex => qr{\d+}, emptyok => 1, } );
<<<<<<< HEAD:check_postgres.pl
my $found = 0;
=======
my $found = 0; my $found = 0;
>>>>>>> petdance/master:check_postgres.pl
for $db (@{$info->{db}}) { for $db (@{$info->{db}}) {
my $max = -1; my $max = -1;
$found = 1; $found = 1;
Expand Down Expand Up @@ -4486,9 +4606,15 @@ sub check_prepared_txns {
FROM pg_prepared_xacts FROM pg_prepared_xacts
ORDER BY prepared ASC ORDER BY prepared ASC
}; };
<<<<<<< HEAD:check_postgres.pl
my $info = run_command($SQL, {regex => qr[\w+], emptyok => 1 } );
=======
my $info = run_command($SQL, {regex => qr[\w+], emptyok => 1 } ); my $info = run_command($SQL, {regex => qr[\w+], emptyok => 1 } );
>>>>>>> petdance/master:check_postgres.pl
my $msg = msg('preptxn-none'); my $msg = msg('preptxn-none');
my $found = 0; my $found = 0;
for $db (@{$info->{db}}) { for $db (@{$info->{db}}) {
Expand Down Expand Up @@ -6627,9 +6753,20 @@ sub check_txn_idle {
} }
else { else {
add_ok $msg; add_ok $msg;
<<<<<<< HEAD:check_postgres.pl
} }
} }
## If no results, let's be paranoid and check their settings
if (!$found) {
if ($USERWHERECLAUSE) {
add_ok msg('no-match-user');
=======
>>>>>>> petdance/master:check_postgres.pl
}
verify_version();
}
## If no results, let's be paranoid and check their settings ## If no results, let's be paranoid and check their settings
if (!$found) { if (!$found) {
if ($USERWHERECLAUSE) { if ($USERWHERECLAUSE) {
Expand Down Expand Up @@ -6671,6 +6808,7 @@ sub check_txn_time {
FROM pg_stat_activity FROM pg_stat_activity
WHERE xact_start IS NOT NULL $USERWHERECLAUSE WHERE xact_start IS NOT NULL $USERWHERECLAUSE
}; };
<<<<<<< HEAD:check_postgres.pl
my $info = run_command($SQL, { regex => qr{\d+ \|\s+\s+}, emptyok => 1 } ); my $info = run_command($SQL, { regex => qr{\d+ \|\s+\s+}, emptyok => 1 } );
Expand All @@ -6681,6 +6819,18 @@ sub check_txn_time {
ndie msg('txntime-fail'); ndie msg('txntime-fail');
} }
=======
my $info = run_command($SQL, { regex => qr{\d+ \|\s+\s+}, emptyok => 1 } );
$db = $info->{db}[0];
my $slurp = $db->{slurp};
if (! exists $db->{ok}) {
ndie msg('txntime-fail');
}
>>>>>>> petdance/master:check_postgres.pl
if ($slurp !~ /\w/ and $USERWHERECLAUSE) { if ($slurp !~ /\w/ and $USERWHERECLAUSE) {
$stats{$db->{dbname}} = 0; $stats{$db->{dbname}} = 0;
add_ok msg('no-match-user'); add_ok msg('no-match-user');
Expand Down Expand Up @@ -7121,6 +7271,10 @@ =head1 OTHER OPTIONS
Displays a help screen with a summary of all actions and options. Displays a help screen with a summary of all actions and options.
=item B<--man>
Displays the entire manual.
=item B<-V> or B<--version> =item B<-V> or B<--version>
Shows the current version. Shows the current version.
Expand Down Expand Up @@ -7171,8 +7325,9 @@ =head1 OTHER OPTIONS
=item B<--output=VAL> =item B<--output=VAL>
Determines the format of the output, for use in various programs. The default is 'nagios'. No Determines the format of the output, for use in various programs. The
other systems are supported yet. default is 'nagios'. Available options are 'nagios', 'mrtg', 'simple'
and 'cacti'.
=item B<--mrtg=VAL> =item B<--mrtg=VAL>
Expand Down Expand Up @@ -8440,6 +8595,11 @@ =head1 HISTORY
=over 4 =over 4
=item B<?>
Add --man option to show the entire manual. (Andy Lester)
=item B<Version 2.15.0> =item B<Version 2.15.0>
Redo the internal run_command() sub to use -x and hashes instead of regexes. Redo the internal run_command() sub to use -x and hashes instead of regexes.
Expand Down Expand Up @@ -8973,3 +9133,5 @@ =head1 LICENSE AND COPYRIGHT
OF SUCH DAMAGE. OF SUCH DAMAGE.
=cut =cut
# vi: hardtabs=8 shiftwidth=8 noexpandtab nosmarttab

0 comments on commit 79c0d64

Please sign in to comment.