From d6da997978e8dda4a831f7e3c930f8d006b656dd Mon Sep 17 00:00:00 2001 From: Greg Sabino Mullane Date: Mon, 27 Jun 2011 10:50:48 -0400 Subject: Rename recent tests: 'database' is implicit for most things. Plus, I didn't want to have to re-line up everything inside $action_info :) --- check_postgres.pl | 460 +++++++++++++++++++++++++++--------------------------- 1 file changed, 230 insertions(+), 230 deletions(-) (limited to 'check_postgres.pl') diff --git a/check_postgres.pl b/check_postgres.pl index d745e8572..d4d224ccd 100755 --- a/check_postgres.pl +++ b/check_postgres.pl @@ -920,16 +920,16 @@ our $action_info = { backends => [1, 'Number of connections, compared to max_connections.'], bloat => [0, 'Check for table and index bloat.'], checkpoint => [1, 'Checks how long since the last checkpoint'], + commitratio => [0, 'Report if the commit ratio of a database is too low.'], connection => [0, 'Simple connection check.'], custom_query => [0, 'Run a custom query.'], - database_commitratio => [0, 'Report if the commitratio of a database is too low.'], - database_hitratio => [0, 'Report if the hitratio of a database is too low.'], database_size => [0, 'Report if a database is too big.'], dbstats => [1, 'Returns stats from pg_stat_database: Cacti output only'], disabled_triggers => [0, 'Check if any triggers are disabled'], disk_space => [1, 'Checks space of local disks Postgres is using.'], fsm_pages => [1, 'Checks percentage of pages used in free space map.'], fsm_relations => [1, 'Checks percentage of relations used in free space map.'], + hitratio => [0, 'Report if the hit ratio of a database is too low.'], hot_standby_delay => [1, 'Check the replication delay in hot standby setup'], index_size => [0, 'Checks the size of indexes only.'], table_size => [0, 'Checks the size of tables only.'], @@ -1574,10 +1574,10 @@ check_bloat() if $action eq 'bloat'; check_connection() if $action eq 'connection'; ## Check the commitratio of one or more databases -check_database_commitratio() if $action eq 'database_commitratio'; +check_commitratio() if $action eq 'commitratio'; ## Check the hitratio of one or more databases -check_database_hitratio() if $action eq 'database_hitratio'; +check_hitratio() if $action eq 'hitratio'; ## Check the size of one or more databases check_database_size() if $action eq 'database_size'; @@ -3433,6 +3433,96 @@ sub check_checkpoint { } ## end of check_checkpoint +sub check_commitratio { + + ## Check the commitratio 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 criticals are percentages + ## Limit to a specific user (db owner) with the includeuser option + ## Exclude users with the excludeuser option + + my ($warning, $critical) = validate_range({type => 'percent'}); + + $SQL = qq{ +SELECT + round(100.*sd.xact_commit/(sd.xact_commit+sd.xact_rollback), 2) AS dcommitratio, + d.datname, + u.usename +FROM pg_stat_database sd +JOIN pg_database d ON (d.oid=sd.datid) +JOIN pg_user u ON (u.usesysid=d.datdba) +WHERE sd.xact_commit+sd.xact_rollback<>0 +$USERWHERECLAUSE +}; + if ($opt{perflimit}) { + $SQL .= " ORDER BY 1 DESC LIMIT $opt{perflimit}"; + } + + my $info = run_command($SQL, { regex => qr{\d+}, emptyok => 1, } ); + my $found = 0; + + for $db (@{$info->{db}}) { + my $min = 101; + $found = 1; + my %s; + for my $r (@{$db->{slurp}}) { + + next if skip_item($r->{datname}); + + if ($r->{dcommitratio} <= $min) { + $min = $r->{dcommitratio}; + } + $s{$r->{datname}} = $r->{dcommitratio}; + } + + if ($MRTG) { + do_mrtg({one => $min, msg => "DB: $db->{dbname}"}); + } + if ($min > 100) { + $stats{$db->{dbname}} = 0; + if ($USERWHERECLAUSE) { + add_ok msg('no-match-user'); + } + else { + add_unknown msg('no-match-db'); + } + next; + } + + my $msg = ''; + for (reverse sort {$s{$b} <=> $s{$a} or $a cmp $b } keys %s) { + $msg .= "$_: $s{$_} "; + $db->{perf} .= sprintf ' %s=%s;%s;%s', + perfname($_), $s{$_}, $warning, $critical; + } + if (length $critical and $min <= $critical) { + add_critical $msg; + } + elsif (length $warning and $min <= $warning) { + add_warning $msg; + } + else { + add_ok $msg; + } + } + + ## If no results, probably a version problem + if (!$found and keys %unknown) { + (my $first) = values %unknown; + if ($first->[0][0] =~ /pg_database_size/) { + ndie msg('dbsize-version'); + } + } + + return; + +} ## end of check_commitratio + + sub check_connection { ## Check the connection, get the connection time and version @@ -3552,186 +3642,6 @@ sub check_custom_query { } ## end of check_custom_query -sub check_database_commitratio { - - ## Check the commitratio 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 criticals are percentages - ## Limit to a specific user (db owner) with the includeuser option - ## Exclude users with the excludeuser option - - my ($warning, $critical) = validate_range({type => 'percent'}); - - $SQL = qq{ -SELECT - round(100.*sd.xact_commit/(sd.xact_commit+sd.xact_rollback), 2) AS dcommitratio, - d.datname, - u.usename -FROM pg_stat_database sd -JOIN pg_database d ON (d.oid=sd.datid) -JOIN pg_user u ON (u.usesysid=d.datdba) -WHERE sd.xact_commit+sd.xact_rollback<>0 -$USERWHERECLAUSE -}; - if ($opt{perflimit}) { - $SQL .= " ORDER BY 1 DESC LIMIT $opt{perflimit}"; - } - - my $info = run_command($SQL, { regex => qr{\d+}, emptyok => 1, } ); - my $found = 0; - - for $db (@{$info->{db}}) { - my $min = 101; - $found = 1; - my %s; - for my $r (@{$db->{slurp}}) { - - next if skip_item($r->{datname}); - - if ($r->{dcommitratio} <= $min) { - $min = $r->{dcommitratio}; - } - $s{$r->{datname}} = $r->{dcommitratio}; - } - - if ($MRTG) { - do_mrtg({one => $min, msg => "DB: $db->{dbname}"}); - } - if ($min > 100) { - $stats{$db->{dbname}} = 0; - if ($USERWHERECLAUSE) { - add_ok msg('no-match-user'); - } - else { - add_unknown msg('no-match-db'); - } - next; - } - - my $msg = ''; - for (reverse sort {$s{$b} <=> $s{$a} or $a cmp $b } keys %s) { - $msg .= "$_: $s{$_} "; - $db->{perf} .= sprintf ' %s=%s;%s;%s', - perfname($_), $s{$_}, $warning, $critical; - } - if (length $critical and $min <= $critical) { - add_critical $msg; - } - elsif (length $warning and $min <= $warning) { - add_warning $msg; - } - else { - add_ok $msg; - } - } - - ## If no results, probably a version problem - if (!$found and keys %unknown) { - (my $first) = values %unknown; - if ($first->[0][0] =~ /pg_database_size/) { - ndie msg('dbsize-version'); - } - } - - return; - -} ## end of check_database_commitratio - - -sub check_database_hitratio { - - ## Check the hitratio 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 criticals are percentages - ## Limit to a specific user (db owner) with the includeuser option - ## Exclude users with the excludeuser option - - my ($warning, $critical) = validate_range({type => 'percent'}); - - $SQL = qq{ -SELECT - round(100.*sd.blks_hit/(sd.blks_read+sd.blks_hit), 2) AS dhitratio, - d.datname, - u.usename -FROM pg_stat_database sd -JOIN pg_database d ON (d.oid=sd.datid) -JOIN pg_user u ON (u.usesysid=d.datdba) -WHERE sd.blks_read+sd.blks_hit<>0 -$USERWHERECLAUSE -}; - if ($opt{perflimit}) { - $SQL .= " ORDER BY 1 DESC LIMIT $opt{perflimit}"; - } - - my $info = run_command($SQL, { regex => qr{\d+}, emptyok => 1, } ); - my $found = 0; - - for $db (@{$info->{db}}) { - my $min = 101; - $found = 1; - my %s; - for my $r (@{$db->{slurp}}) { - - next if skip_item($r->{datname}); - - if ($r->{dhitratio} <= $min) { - $min = $r->{dhitratio}; - } - $s{$r->{datname}} = $r->{dhitratio}; - } - - if ($MRTG) { - do_mrtg({one => $min, msg => "DB: $db->{dbname}"}); - } - if ($min > 100) { - $stats{$db->{dbname}} = 0; - if ($USERWHERECLAUSE) { - add_ok msg('no-match-user'); - } - else { - add_unknown msg('no-match-db'); - } - next; - } - - my $msg = ''; - for (reverse sort {$s{$b} <=> $s{$a} or $a cmp $b } keys %s) { - $msg .= "$_: $s{$_} "; - $db->{perf} .= sprintf ' %s=%s;%s;%s', - perfname($_), $s{$_}, $warning, $critical; - } - if (length $critical and $min <= $critical) { - add_critical $msg; - } - elsif (length $warning and $min <= $warning) { - add_warning $msg; - } - else { - add_ok $msg; - } - } - - ## If no results, probably a version problem - if (!$found and keys %unknown) { - (my $first) = values %unknown; - if ($first->[0][0] =~ /pg_database_size/) { - ndie msg('dbsize-version'); - } - } - - return; - -} ## end of check_database_hitratio - - sub check_database_size { ## Check the size of one or more databases @@ -4242,6 +4152,96 @@ FROM (SELECT } ## end of check_fsm_relations +sub check_hitratio { + + ## Check the hitratio 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 criticals are percentages + ## Limit to a specific user (db owner) with the includeuser option + ## Exclude users with the excludeuser option + + my ($warning, $critical) = validate_range({type => 'percent'}); + + $SQL = qq{ +SELECT + round(100.*sd.blks_hit/(sd.blks_read+sd.blks_hit), 2) AS dhitratio, + d.datname, + u.usename +FROM pg_stat_database sd +JOIN pg_database d ON (d.oid=sd.datid) +JOIN pg_user u ON (u.usesysid=d.datdba) +WHERE sd.blks_read+sd.blks_hit<>0 +$USERWHERECLAUSE +}; + if ($opt{perflimit}) { + $SQL .= " ORDER BY 1 DESC LIMIT $opt{perflimit}"; + } + + my $info = run_command($SQL, { regex => qr{\d+}, emptyok => 1, } ); + my $found = 0; + + for $db (@{$info->{db}}) { + my $min = 101; + $found = 1; + my %s; + for my $r (@{$db->{slurp}}) { + + next if skip_item($r->{datname}); + + if ($r->{dhitratio} <= $min) { + $min = $r->{dhitratio}; + } + $s{$r->{datname}} = $r->{dhitratio}; + } + + if ($MRTG) { + do_mrtg({one => $min, msg => "DB: $db->{dbname}"}); + } + if ($min > 100) { + $stats{$db->{dbname}} = 0; + if ($USERWHERECLAUSE) { + add_ok msg('no-match-user'); + } + else { + add_unknown msg('no-match-db'); + } + next; + } + + my $msg = ''; + for (reverse sort {$s{$b} <=> $s{$a} or $a cmp $b } keys %s) { + $msg .= "$_: $s{$_} "; + $db->{perf} .= sprintf ' %s=%s;%s;%s', + perfname($_), $s{$_}, $warning, $critical; + } + if (length $critical and $min <= $critical) { + add_critical $msg; + } + elsif (length $warning and $min <= $warning) { + add_warning $msg; + } + else { + add_ok $msg; + } + } + + ## If no results, probably a version problem + if (!$found and keys %unknown) { + (my $first) = values %unknown; + if ($first->[0][0] =~ /pg_database_size/) { + ndie msg('dbsize-version'); + } + } + + return; + +} ## end of check_hitratio + + sub check_hot_standby_delay { ## Check on the delay in PITR replication between master and slave @@ -8324,6 +8324,29 @@ This action requires the Date::Parse module. For MRTG or simple output, returns the number of seconds. +=head2 B + +(C) Checks the commit ratio of all databases and complains when they are too low. +There is no need to run this command more than once per database cluster. +Databases can be filtered with +the I<--include> and I<--exclude> options. See the L section +for more details. +They can also be filtered by the owner of the database with the +I<--includeuser> and I<--excludeuser> options. +See the L section for more details. + +The warning and critical options should be specified as percentages. There are not +defaults for this action: the warning and critical must be specified. The warning value +cannot be greater than the critical value. The output returns all databases sorted by +commitratio, smallest first. + +Example: Warn if any database on host flagg is less than 90% in commitratio, and critical if less then 80%. + + check_postgres_database_commitratio --host=flagg --warning='90%' --critical='80%' + +For MRTG output, returns the percentage of the database with the smallest commitratio on the first line, +and the name of the database on the fourth line. + =head2 B (C) Simply connects, issues a 'SELECT version()', and leaves. @@ -8386,52 +8409,6 @@ to make it into a standard action that other people can use. This action does not support MRTG or simple output yet. -=head2 B - -(C) Checks the commit ratio of all databases and complains when they are too low. -There is no need to run this command more than once per database cluster. -Databases can be filtered with -the I<--include> and I<--exclude> options. See the L section -for more details. -They can also be filtered by the owner of the database with the -I<--includeuser> and I<--excludeuser> options. -See the L section for more details. - -The warning and critical options should be specified as percentages. There are not -defaults for this action: the warning and critical must be specified. The warning value -cannot be greater than the critical value. The output returns all databases sorted by -commitratio, smallest first. - -Example: Warn if any database on host flagg is less than 90% in commitratio, and critical if less then 80%. - - check_postgres_database_commitratio --host=flagg --warning='90%' --critical='80%' - -For MRTG output, returns the percentage of the database with the smallest commitratio on the first line, -and the name of the database on the fourth line. - -=head2 B - -(C) Checks the hit ratio of all databases and complains when they are too low. -There is no need to run this command more than once per database cluster. -Databases can be filtered with -the I<--include> and I<--exclude> options. See the L section -for more details. -They can also be filtered by the owner of the database with the -I<--includeuser> and I<--excludeuser> options. -See the L section for more details. - -The warning and critical options should be specified as percentages. There are not -defaults for this action: the warning and critical must be specified. The warning value -cannot be greater than the critical value. The output returns all databases sorted by -hitratio, smallest first. - -Example: Warn if any database on host flagg is less than 90% in hitratio, and critical if less then 80%. - - check_postgres_database_hitratio --host=flagg --warning='90%' --critical='80%' - -For MRTG output, returns the percentage of the database with the smallest hitratio on the first line, -and the name of the database on the fourth line. - =head2 B (C) Checks the size of all databases and complains when they are too big. @@ -8672,6 +8649,29 @@ run this check with short intervals. For MRTG output, returns the percent of free-space-map on the first line, the number of relations currently used on the second line. +=head2 B + +(C) Checks the hit ratio of all databases and complains when they are too low. +There is no need to run this command more than once per database cluster. +Databases can be filtered with +the I<--include> and I<--exclude> options. See the L section +for more details. +They can also be filtered by the owner of the database with the +I<--includeuser> and I<--excludeuser> options. +See the L section for more details. + +The warning and critical options should be specified as percentages. There are not +defaults for this action: the warning and critical must be specified. The warning value +cannot be greater than the critical value. The output returns all databases sorted by +hitratio, smallest first. + +Example: Warn if any database on host flagg is less than 90% in hitratio, and critical if less then 80%. + + check_postgres_database_hitratio --host=flagg --warning='90%' --critical='80%' + +For MRTG output, returns the percentage of the database with the smallest hitratio on the first line, +and the name of the database on the fourth line. + =head2 B (C) Checks the streaming replication lag by computing the delta -- cgit v1.2.3