From 59e8e2422a905458cca06dfd89dce9ee7a88dda4 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Wed, 25 Jan 2023 09:48:00 +0000 Subject: [PATCH] (plugin) database::postgres - mode hit-ratio wrong calc (#4176) --- src/database/postgres/mode/hitratio.pm | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/database/postgres/mode/hitratio.pm b/src/database/postgres/mode/hitratio.pm index 02ef471f8..643a9cd7c 100644 --- a/src/database/postgres/mode/hitratio.pm +++ b/src/database/postgres/mode/hitratio.pm @@ -77,18 +77,18 @@ sub run { my $new_datas = {}; $new_datas->{last_timestamp} = time(); my $result = $options{sql}->fetchall_arrayref(); - + $self->{output}->output_add( severity => 'OK', short_msg => "All databases hitratio are ok" ); - + foreach my $row (@{$result}) { - $new_datas->{$$row[2] . '_blks_hit'} = $row->[0]; - $new_datas->{$$row[2] . '_blks_read'} = $row->[1]; + $new_datas->{$row->[2] . '_blks_hit'} = $row->[0]; + $new_datas->{$row->[2] . '_blks_read'} = $row->[1]; if (defined($self->{option_results}->{exclude}) && $row->[2] !~ /$self->{option_results}->{exclude}/) { - $self->{output}->output_add(long_msg => "Skipping database '" . $$row[2] . '"'); + $self->{output}->output_add(long_msg => "Skipping database '" . $row->[2] . '"'); next; } @@ -96,16 +96,16 @@ sub run { my $old_blks_read = $self->{statefile_cache}->get(name => $row->[2] . '_blks_read'); next if (!defined($old_blks_hit) || !defined($old_blks_read)); - $old_blks_hit = 0 if ($$row[0] <= $old_blks_hit); - $old_blks_read = 0 if ($$row[1] <= $old_blks_read); + $old_blks_hit = 0 if ($row->[0] < $old_blks_hit); + $old_blks_read = 0 if ($row->[1] < $old_blks_read); $database_check++; my %prcts = (); - my $total_read_requests = $new_datas->{$$row[2] . '_blks_hit'} - $old_blks_hit; - my $total_read_disk = $new_datas->{$$row[2] . '_blks_read'} - $old_blks_read; + my $total_read_requests = $new_datas->{$row->[2] . '_blks_hit'} - $old_blks_hit; + my $total_read_disk = $new_datas->{$row->[2] . '_blks_read'} - $old_blks_read; $prcts{hitratio_now} = (($total_read_requests + $total_read_disk) == 0) ? 100 : $total_read_requests * 100 / ($total_read_requests + $total_read_disk); - $prcts{hitratio} = (($new_datas->{$$row[2] . '_blks_hit'} + + $new_datas->{$$row[2] . '_blks_read'}) == 0) ? 100 : $new_datas->{$$row[2] . '_blks_hit'} * 100 / ($new_datas->{$$row[2] . '_blks_hit'} + $new_datas->{$$row[2] . '_blks_read'}); - + $prcts{hitratio} = (($new_datas->{$row->[2] . '_blks_hit'} + + $new_datas->{$row->[2] . '_blks_read'}) == 0) ? 100 : $new_datas->{$row->[2] . '_blks_hit'} * 100 / ($new_datas->{$$row[2] . '_blks_hit'} + $new_datas->{$row->[2] . '_blks_read'}); + my $exit_code = $self->{perfdata}->threshold_check(value => $prcts{'hitratio' . ((defined($self->{option_results}->{lookback})) ? '' : '_now' )}, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->output_add( long_msg => sprintf( @@ -113,7 +113,7 @@ sub run { $row->[2], $prcts{'hitratio' . ((defined($self->{option_results}->{lookback})) ? '' : '_now')} ) ); - + if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1)) { $self->{output}->output_add( severity => $exit_code, @@ -139,7 +139,7 @@ sub run { min => 0, max => 100 ); } - + $self->{statefile_cache}->write(data => $new_datas); if (!defined($old_timestamp)) { $self->{output}->output_add(