[check_postgres] Problems with check_bloat

Luis Vazquez luis at asterisk.uy
Tue Jul 21 16:35:56 UTC 2015


Hi Greg,
I've trying to use the check_BLOAT action and I've found many problems.

* In first place the check seems to work (mostly) OK when I put a size 
value in the warning and/or critical options, but will allways git a
CRITICAL output if I pass percentages. Here is a sample output showing 
both cases:

With sizes  values:  OK:
$ ./check_postgres.pl --host 172.16.200.71 --dbservice=nagios 
--showtime=1 --action=bloat --db=XXXX --warning='50M' --critical='100M' 
--perflimit 5
*POSTGRES_BLOAT OK:* service=nagios (host:172.16.200.71) (db XXXX) table 
public.ir_translation rows:43329 pages:1178 shouldbe:877 (1.3X) *wasted 
size:2465792 (2 MB)* | public.ir_translation=2465792B 
ir_translation_comments_index=0B ir_translation_ltn=0B 
ir_translation_module_index=0B ir_translation_res_id_index=0B

With percentage values: CRITICAL => wrong:
./check_postgres.pl --host 172.16.200.71 --dbservice=nagios 
--action=bloat --db=XXXX --warning='80%' --critical='90%' --perflimit 5
*POSTGRES_BLOAT **CRITICAL:* service=nagios (host:172.16.200.71) (db 
XXXX) table public.ir_translation rows:43329 pages:1178 shouldbe:877 
(1.3X) *wasted size:2465792 (2 MB)* | public.ir_translation=2465792B 
ir_translation_comments_index=0B ir_translation_ltn=0B 
ir_translation_module_index=0B ir_translation_res_id_index=0B*

*Motivated from this I started looking the code trying to figure out the 
problem.
I still haven't found how to fix it,  but in the meantime I'have found 
some other details that seems wrong to me:

* The function check_bloat uses two hardcoded variables $MINPAGES and 
$MINIPAGES that seems to be the minimum pages for a table or an index to 
be taken into account.
**Playing with those values I've found some code that is really cryptic 
(and I thing is a bug) when you check the result of the select returned 
from the run_command() to see if you have an empty result set.
Here you are using an scalar matching operator 
(http://mkweb.bcgsc.ca/intranet/perlbook/prog/ch05_02.htm) to check for 
a non empty value in an array o maps object ($db->{slurp}).
** LINE: 3905 **
    $db = $info->{db}[0];

     if (*$db->{slurp} !~ /\w+/o*) {
         add_ok msg('bloat-nomin') unless $MRTG;
         return;
     }
The referred message is 'bloat-nomin'=> q{no relations meet the minimum 
bloat criteria},

When I increase the values of $MINPAGES/$MINIPAGES so there are no 
results in the select, $db->{slurp} is an empty array reference but the 
if condition keeps giving false because you are matching against the 
string representation of the reference, something like: ARRAY(0x24daec0).

I have verified that in the run_command() function you make sure to 
return an array: $db->{slurp} = \@stuff
So to check for no results, I think you should instead check for an 
undefined (to be on the safe side) or an empty array reference with 
something like this:
if (!defined(*$db->{slurp}*) || @*$db->{slurp}* == 0) {
         add_ok msg('bloat-nomin') unless $MRTG;
         return;
     }

* The final point is just a detail and not a big concern; but I see the 
default for MINIPAGES is 10 but the default for MINPAGES is 0 which 
doen't make many sense to me. I think both default values should be 
positive and they should be taken as optional parameters; and even 
default to the same value if only the --minpages option is given. I'm 
offering myself to implement this if you agree to include these changes.


Best regards
Luis

-- 
------------------------------------------------------------------------
"Las ideas no duran mucho, hay que hacer algo con ellas"
~ Santiago Ramón y Cajal 
<http://es.wikipedia.org/wiki/Santiago_Ram%C3%B3n_y_Cajal>
------------------------------------------------------------------------

Ing. Luis Vazquez - AsteriskUY Soluciones Corporativas

Comunicación VoIP y Soluciones IT Open Source
Elastix Certified Engineer

------------------------------------------------------------------------
Lauro Muller 1888 Ap. 201
CP: 11300 | Montevideo, Uruguay
Tel: 099117751 | luis at asterisk.uy <mailto:luis at asterisk.org.uy> Linux 
<http://www.linux.org> GNU <http://www.gnu.org> Asterisk 
<http://www.asterisk.org> Elastix <http://www.elastix.com> Centreon 
<http://www.centreon.com> GLPI <http://www.glpi-project.org> Bacula 
<http://www.baculasystems.com/> Zimbra <http://www.zimbra.com/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.endcrypt.com/pipermail/check_postgres/attachments/20150721/3f202c37/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: linux.png
Type: image/png
Size: 3531 bytes
Desc: not available
URL: <https://mail.endcrypt.com/pipermail/check_postgres/attachments/20150721/3f202c37/attachment-0007.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gnu.png
Type: image/png
Size: 6164 bytes
Desc: not available
URL: <https://mail.endcrypt.com/pipermail/check_postgres/attachments/20150721/3f202c37/attachment-0008.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: astlogo.jpg
Type: image/jpeg
Size: 4528 bytes
Desc: not available
URL: <https://mail.endcrypt.com/pipermail/check_postgres/attachments/20150721/3f202c37/attachment-0001.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: elastix.png
Type: image/png
Size: 3564 bytes
Desc: not available
URL: <https://mail.endcrypt.com/pipermail/check_postgres/attachments/20150721/3f202c37/attachment-0009.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: centreon.png
Type: image/png
Size: 5532 bytes
Desc: not available
URL: <https://mail.endcrypt.com/pipermail/check_postgres/attachments/20150721/3f202c37/attachment-0010.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: glpi.png
Type: image/png
Size: 3637 bytes
Desc: not available
URL: <https://mail.endcrypt.com/pipermail/check_postgres/attachments/20150721/3f202c37/attachment-0011.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bacula.png
Type: image/png
Size: 3677 bytes
Desc: not available
URL: <https://mail.endcrypt.com/pipermail/check_postgres/attachments/20150721/3f202c37/attachment-0012.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: zimbra.png
Type: image/png
Size: 3473 bytes
Desc: not available
URL: <https://mail.endcrypt.com/pipermail/check_postgres/attachments/20150721/3f202c37/attachment-0013.png>


More information about the Check_postgres mailing list