From 8e92c2a8acec9402750b5de2464dd8b88577a43a Mon Sep 17 00:00:00 2001 From: qgarnier Date: Fri, 9 Jun 2023 16:39:58 +0200 Subject: [PATCH] (plugin) database::mysql - force new perfdata (#4454) --- .../protocols/sql/mode/connectiontime.pm | 16 ++--- src/database/mysql/mode/databasessize.pm | 45 ++++++------- .../mysql/mode/innodbbufferpoolhitrate.pm | 60 +++++++++-------- src/database/mysql/mode/longqueries.pm | 7 +- .../mysql/mode/myisamkeycachehitrate.pm | 60 +++++++++-------- src/database/mysql/mode/openfiles.pm | 7 +- src/database/mysql/mode/opentables.pm | 37 ++++++----- src/database/mysql/mode/passwordexpiration.pm | 2 +- src/database/mysql/mode/qcachehitrate.pm | 65 +++++++++++-------- src/database/mysql/mode/queries.pm | 24 +++---- src/database/mysql/mode/slowqueries.pm | 23 ++++--- src/database/mysql/mode/threadsconnected.pm | 3 +- src/database/mysql/mode/uptime.pm | 43 ++++++------ src/database/mysql/plugin.pm | 1 + 14 files changed, 211 insertions(+), 182 deletions(-) diff --git a/src/centreon/common/protocols/sql/mode/connectiontime.pm b/src/centreon/common/protocols/sql/mode/connectiontime.pm index 889952abb..1287d7031 100644 --- a/src/centreon/common/protocols/sql/mode/connectiontime.pm +++ b/src/centreon/common/protocols/sql/mode/connectiontime.pm @@ -29,12 +29,12 @@ use POSIX; sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, + 'warning:s' => { name => 'warning', }, + 'critical:s' => { name => 'critical' } }); return $self; @@ -45,12 +45,12 @@ sub check_options { $self->SUPER::init(%options); if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); + $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); } } @@ -87,7 +87,7 @@ sub run { min => 0 ); } - + $self->{output}->display(); $self->{output}->exit(); } diff --git a/src/database/mysql/mode/databasessize.pm b/src/database/mysql/mode/databasessize.pm index ca7974d75..05e5c22b6 100644 --- a/src/database/mysql/mode/databasessize.pm +++ b/src/database/mysql/mode/databasessize.pm @@ -36,7 +36,7 @@ sub set_counters { group => [ { name => 'global_db', type => 0, skipped_code => { -10 => 1 } }, { name => 'table', display_long => 0, cb_prefix_output => 'prefix_table_output', - message_multiple => 'All tables are ok', type => 1, skipped_code => { -10 => 1 } }, + message_multiple => 'All tables are ok', type => 1, skipped_code => { -10 => 1 } } ] } ]; @@ -47,9 +47,8 @@ sub set_counters { output_template => 'Used Space: %s %s', output_change_bytes => 1, perfdatas => [ - { value => 'used', template => '%s', unit => 'B', - min => 0 }, - ], + { template => '%s', unit => 'B', min => 0 } + ] } }, { label => 'total-free', nlabel => 'databases.space.free.bytes', set => { @@ -57,11 +56,10 @@ sub set_counters { output_template => 'Free Space: %s %s', output_change_bytes => 1, perfdatas => [ - { value => 'free', template => '%s', unit => 'B', - min => 0 }, - ], + { template => '%s', unit => 'B', min => 0 } + ] } - }, + } ]; $self->{maps_counters}->{global_db} = [ @@ -70,9 +68,8 @@ sub set_counters { output_template => 'Used: %s %s', output_change_bytes => 1, perfdatas => [ - { value => 'used', template => '%s', unit => 'B', - min => 0, label_extra_instance => 1 }, - ], + { template => '%s', unit => 'B', min => 0, label_extra_instance => 1 } + ] } }, { label => 'db-free', nlabel => 'database.space.free.bytes', set => { @@ -80,11 +77,10 @@ sub set_counters { output_template => 'Free: %s %s', output_change_bytes => 1, perfdatas => [ - { value => 'free', template => '%s', unit => 'B', - min => 0, label_extra_instance => 1 }, - ], + { template => '%s', unit => 'B', min => 0, label_extra_instance => 1 } + ] } - }, + } ]; $self->{maps_counters}->{table} = [ @@ -93,9 +89,8 @@ sub set_counters { output_template => 'Used: %s %s', output_change_bytes => 1, perfdatas => [ - { value => 'used', template => '%s', unit => 'B', - min => 0, label_extra_instance => 1 }, - ], + { template => '%s', unit => 'B', min => 0, label_extra_instance => 1 } + ] } }, { label => 'table-free', nlabel => 'table.space.free.bytes', set => { @@ -103,20 +98,18 @@ sub set_counters { output_template => 'Free: %s %s', output_change_bytes => 1, perfdatas => [ - { value => 'free', template => '%s', unit => 'B', - min => 0, label_extra_instance => 1 }, - ], + { template => '%s', unit => 'B', min => 0, label_extra_instance => 1 } + ] } }, { label => 'table-frag', nlabel => 'table.fragmentation.percentage', set => { key_values => [ { name => 'frag' }, { name => 'display' } ], output_template => 'Fragmentation: %.2f %%', perfdatas => [ - { value => 'frag', template => '%.2f', unit => '%', - min => 0, max => 100, label_extra_instance => 1 }, - ], + { template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 } + ] } - }, + } ]; } @@ -157,7 +150,7 @@ sub new { $options{options}->add_options(arguments => { 'filter-database:s' => { name => 'filter_database' }, - 'filter-table:s' => { name => 'filter_table' }, + 'filter-table:s' => { name => 'filter_table' } }); return $self; diff --git a/src/database/mysql/mode/innodbbufferpoolhitrate.pm b/src/database/mysql/mode/innodbbufferpoolhitrate.pm index bd20cbcb3..f1839b850 100644 --- a/src/database/mysql/mode/innodbbufferpoolhitrate.pm +++ b/src/database/mysql/mode/innodbbufferpoolhitrate.pm @@ -28,15 +28,15 @@ use centreon::plugins::statefile; sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - "lookback" => { name => 'lookback', }, - }); + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' }, + 'lookback' => { name => 'lookback' } + }); + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); return $self; @@ -100,29 +100,37 @@ sub run { $prcts{bufferpool_hitrate} = ($new_datas->{Innodb_buffer_pool_read_requests} == 0) ? 100 : ($new_datas->{Innodb_buffer_pool_read_requests} - $new_datas->{Innodb_buffer_pool_reads}) * 100 / $new_datas->{Innodb_buffer_pool_read_requests}; my $exit_code = $self->{perfdata}->threshold_check(value => $prcts{'bufferpool_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now' )}, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("innodb buffer pool hitrate at %.2f%%", $prcts{'bufferpool_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now')}) - ); - $self->{output}->perfdata_add(label => 'bufferpool_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now'), - nlabel => 'database.bufferpool.hitrate' . ((defined($self->{option_results}->{lookback})) ? '.average' : '.delta') . '.percentage', - unit => '%', - value => sprintf("%.2f", $prcts{'bufferpool_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now')}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0); - $self->{output}->perfdata_add(label => 'bufferpool_hitrate' . ((defined($self->{option_results}->{lookback})) ? '_now' : ''), - nlabel => 'database.bufferpool.hitrate' . ((defined($self->{option_results}->{lookback})) ? '.delta' : '.average') . '.percentage', - unit => '%', - value => sprintf("%.2f", $prcts{'bufferpool_hitrate' . ((defined($self->{option_results}->{lookback})) ? '_now' : '')}), - min => 0); + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf("innodb buffer pool hitrate at %.2f%%", $prcts{'bufferpool_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now')}) + ); + + $self->{output}->perfdata_add( + label => 'bufferpool_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now'), + nlabel => 'database.bufferpool.hitrate' . ((defined($self->{option_results}->{lookback})) ? '.average' : '.delta') . '.percentage', + unit => '%', + value => sprintf("%.2f", $prcts{'bufferpool_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now')}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0 + ); + $self->{output}->perfdata_add( + label => 'bufferpool_hitrate' . ((defined($self->{option_results}->{lookback})) ? '_now' : ''), + nlabel => 'database.bufferpool.hitrate' . ((defined($self->{option_results}->{lookback})) ? '.delta' : '.average') . '.percentage', + unit => '%', + value => sprintf("%.2f", $prcts{'bufferpool_hitrate' . ((defined($self->{option_results}->{lookback})) ? '_now' : '')}), + min => 0 + ); } - + $self->{statefile_cache}->write(data => $new_datas); if (!defined($old_timestamp)) { - $self->{output}->output_add(severity => 'OK', - short_msg => "Buffer creation..."); + $self->{output}->output_add( + severity => 'OK', + short_msg => "Buffer creation..." + ); } - + $self->{output}->display(); $self->{output}->exit(); } diff --git a/src/database/mysql/mode/longqueries.pm b/src/database/mysql/mode/longqueries.pm index 61cdc9dbb..10db8dbfe 100644 --- a/src/database/mysql/mode/longqueries.pm +++ b/src/database/mysql/mode/longqueries.pm @@ -27,7 +27,7 @@ use warnings; sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { @@ -35,7 +35,7 @@ sub new { 'critical:s' => { name => 'critical', }, 'seconds:s' => { name => 'seconds', default => 60 }, 'filter-user:s' => { name => 'filter_user' }, - 'filter-command:s' => { name => 'filter_command', default => '^(?!(sleep)$)' }, + 'filter-command:s' => { name => 'filter_command', default => '^(?!(sleep)$)' } }); return $self; @@ -61,7 +61,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{sql} = sqlmode object $self->{sql} = $options{sql}; $self->{sql}->connect(); @@ -98,7 +97,7 @@ sub run { critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), min => 0 ); - + for (my $i = 0; $i < 10 && $i < scalar(@queries); $i++) { $queries[$i]->{query} =~ s/\|/-/mg if (defined($queries[$i]->{query})); $self->{output}->output_add(long_msg => diff --git a/src/database/mysql/mode/myisamkeycachehitrate.pm b/src/database/mysql/mode/myisamkeycachehitrate.pm index 1edaa22ff..74bfba15b 100644 --- a/src/database/mysql/mode/myisamkeycachehitrate.pm +++ b/src/database/mysql/mode/myisamkeycachehitrate.pm @@ -28,15 +28,15 @@ use centreon::plugins::statefile; sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - "lookback" => { name => 'lookback', }, - }); + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning', }, + 'critical:s' => { name => 'critical', }, + 'lookback' => { name => 'lookback' } + }); + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); return $self; @@ -101,29 +101,37 @@ sub run { $prcts{keycache_hitrate} = ($new_datas->{Key_read_requests} == 0) ? 100 : ($new_datas->{Key_read_requests} - $new_datas->{Key_reads}) * 100 / $new_datas->{Key_read_requests}; my $exit_code = $self->{perfdata}->threshold_check(value => $prcts{'keycache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now' )}, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("myisam keycache hitrate at %.2f%%", $prcts{'keycache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now')}) - ); - $self->{output}->perfdata_add(label => 'keycache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now'), - nlabel => 'database.keycache.hitrate' . ((defined($self->{option_results}->{lookback})) ? '.average' : '.delta') . '.percentage', - unit => '%', - value => sprintf("%.2f", $prcts{'keycache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now')}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0); - $self->{output}->perfdata_add(label => 'keycache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '_now' : ''), - nlabel => 'database.keycache.hitrate' . ((defined($self->{option_results}->{lookback})) ? '.delta' : '.average') . '.percentage', - unit => '%', - value => sprintf("%.2f", $prcts{'keycache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '_now' : '')}), - min => 0); + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf("myisam keycache hitrate at %.2f%%", $prcts{'keycache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now')}) + ); + + $self->{output}->perfdata_add( + label => 'keycache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now'), + nlabel => 'database.keycache.hitrate' . ((defined($self->{option_results}->{lookback})) ? '.average' : '.delta') . '.percentage', + unit => '%', + value => sprintf("%.2f", $prcts{'keycache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now')}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0 + ); + $self->{output}->perfdata_add( + label => 'keycache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '_now' : ''), + nlabel => 'database.keycache.hitrate' . ((defined($self->{option_results}->{lookback})) ? '.delta' : '.average') . '.percentage', + unit => '%', + value => sprintf("%.2f", $prcts{'keycache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '_now' : '')}), + min => 0 + ); } - + $self->{statefile_cache}->write(data => $new_datas); if (!defined($old_timestamp)) { - $self->{output}->output_add(severity => 'OK', - short_msg => "Buffer creation..."); + $self->{output}->output_add( + severity => 'OK', + short_msg => "Buffer creation..." + ); } - + $self->{output}->display(); $self->{output}->exit(); } diff --git a/src/database/mysql/mode/openfiles.pm b/src/database/mysql/mode/openfiles.pm index de07b8331..d6d3bfa11 100644 --- a/src/database/mysql/mode/openfiles.pm +++ b/src/database/mysql/mode/openfiles.pm @@ -27,12 +27,12 @@ use warnings; sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { - 'warning:s' => { name => 'warning', }, - 'critical:s' => { name => 'critical', }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' } }); return $self; @@ -84,6 +84,7 @@ sub run { $prct_open, $open_files, $open_files_limit ) ); + $self->{output}->perfdata_add( label => 'open_files', nlabel => 'database.open.files.count', diff --git a/src/database/mysql/mode/opentables.pm b/src/database/mysql/mode/opentables.pm index 3efa584f6..af8ce21f2 100644 --- a/src/database/mysql/mode/opentables.pm +++ b/src/database/mysql/mode/opentables.pm @@ -27,14 +27,13 @@ use warnings; sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - }); + + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' } + }); return $self; } @@ -81,15 +80,21 @@ sub run { my $prct_open = int(100 * $open_tables / $open_tables_limit); my $exit_code = $self->{perfdata}->threshold_check(value => $prct_open, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("%.2f%% of the open files limit reached (%d of max. %d)", - $prct_open, $open_tables, $open_tables_limit)); - $self->{output}->perfdata_add(label => 'open_tables', - nlabel => 'database.open.tables.count', - value => $open_tables, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $open_tables_limit, cast_int => 1), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $open_tables_limit, cast_int => 1), - min => 0); + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf( + "%.2f%% of the open files limit reached (%d of max. %d)", + $prct_open, $open_tables, $open_tables_limit + ) + ); + $self->{output}->perfdata_add( + label => 'open_tables', + nlabel => 'database.open.tables.count', + value => $open_tables, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $open_tables_limit, cast_int => 1), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $open_tables_limit, cast_int => 1), + min => 0 + ); $self->{output}->display(); $self->{output}->exit(); diff --git a/src/database/mysql/mode/passwordexpiration.pm b/src/database/mysql/mode/passwordexpiration.pm index 64a896ce1..c3c293019 100644 --- a/src/database/mysql/mode/passwordexpiration.pm +++ b/src/database/mysql/mode/passwordexpiration.pm @@ -66,7 +66,7 @@ sub set_counters { sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { diff --git a/src/database/mysql/mode/qcachehitrate.pm b/src/database/mysql/mode/qcachehitrate.pm index 13f102a53..a9b903e6d 100644 --- a/src/database/mysql/mode/qcachehitrate.pm +++ b/src/database/mysql/mode/qcachehitrate.pm @@ -28,15 +28,15 @@ use centreon::plugins::statefile; sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - "lookback" => { name => 'lookback', }, - }); + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' }, + 'lookback' => { name => 'lookback' } + }); + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); return $self; @@ -64,7 +64,7 @@ sub run { $self->{sql} = $options{sql}; $self->{sql}->connect(); - + if (!($self->{sql}->is_version_minimum(version => '5'))) { $self->{output}->add_option_msg(short_msg => "MySQL version '" . $self->{sql}->{version} . "' is not supported (need version >= '5.x')."); $self->{output}->option_exit(); @@ -94,8 +94,10 @@ sub run { $self->{output}->option_exit(); } if ($have_query_cache !~ /^yes$/i || $query_cache_size == 0) { - $self->{output}->output_add(severity => 'OK', - short_msg => "Query cache is turned off."); + $self->{output}->output_add( + severity => 'OK', + short_msg => "Query cache is turned off." + ); $self->{output}->display(); $self->{output}->exit(); } @@ -117,29 +119,36 @@ sub run { $prcts{qcache_hitrate} = (($new_datas->{Qcache_hits} + $new_datas->{Com_select}) == 0) ? 100 : ($new_datas->{Qcache_hits}) * 100 / ($new_datas->{Qcache_hits} + $new_datas->{Com_select}); my $exit_code = $self->{perfdata}->threshold_check(value => $prcts{'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now' )}, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("query cache hitrate at %.2f%%", $prcts{'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now')}) - ); - $self->{output}->perfdata_add(label => 'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now'), - nlabel => 'database.qcache.hitrate' . ((defined($self->{option_results}->{lookback})) ? '.average' : '.delta') . '.percentage', - unit => '%', - value => sprintf("%.2f", $prcts{'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now')}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0); - $self->{output}->perfdata_add(label => 'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '_now' : ''), - nlabel => 'database.qcache.hitrate' . ((defined($self->{option_results}->{lookback})) ? '.delta' : '.average') . '.percentage', - unit => '%', - value => sprintf("%.2f", $prcts{'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '_now' : '')}), - min => 0); + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf("query cache hitrate at %.2f%%", $prcts{'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now')}) + ); + $self->{output}->perfdata_add( + label => 'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now'), + nlabel => 'database.qcache.hitrate' . ((defined($self->{option_results}->{lookback})) ? '.average' : '.delta') . '.percentage', + unit => '%', + value => sprintf("%.2f", $prcts{'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now')}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0 + ); + $self->{output}->perfdata_add( + label => 'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '_now' : ''), + nlabel => 'database.qcache.hitrate' . ((defined($self->{option_results}->{lookback})) ? '.delta' : '.average') . '.percentage', + unit => '%', + value => sprintf("%.2f", $prcts{'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '_now' : '')}), + min => 0 + ); } $self->{statefile_cache}->write(data => $new_datas); if (!defined($old_timestamp)) { - $self->{output}->output_add(severity => 'OK', - short_msg => "Buffer creation..."); + $self->{output}->output_add( + severity => 'OK', + short_msg => "Buffer creation..." + ); } - + $self->{output}->display(); $self->{output}->exit(); } diff --git a/src/database/mysql/mode/queries.pm b/src/database/mysql/mode/queries.pm index 5fee8fcc7..905df68d4 100644 --- a/src/database/mysql/mode/queries.pm +++ b/src/database/mysql/mode/queries.pm @@ -26,11 +26,17 @@ use strict; use warnings; use Digest::MD5 qw(md5_hex); +sub prefix_output { + my ($self, %options) = @_; + + return "Requests "; +} + sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'global', type => 0, cb_prefix_output => 'prefix_output' }, + { name => 'global', type => 0, cb_prefix_output => 'prefix_output' } ]; $self->{maps_counters}->{global} = [ @@ -38,10 +44,10 @@ sub set_counters { key_values => [ { name => 'Queries', per_second => 1 } ], output_template => 'Total : %d', perfdatas => [ - { label => 'total_requests', template => '%d', unit => '/s', min => 0 }, - ], + { label => 'total_requests', template => '%d', unit => '/s', min => 0 } + ] } - }, + } ]; foreach ('update', 'delete', 'insert', 'truncate', 'select', 'commit', 'begin') { @@ -66,15 +72,9 @@ sub set_counters { } } -sub prefix_output { - my ($self, %options) = @_; - - return "Requests "; -} - sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { @@ -91,7 +91,7 @@ sub manage_selection { $self->{output}->add_option_msg(short_msg => "MySQL version '" . $self->{sql}->{version} . "' is not supported (need version >= '5.0.76')."); $self->{output}->option_exit(); } - + $options{sql}->query(query => q{ SHOW /*!50000 global */ STATUS WHERE Variable_name IN ('Queries', 'Com_update', 'Com_delete', 'Com_insert', 'Com_truncate', 'Com_select', 'Com_commit', 'Com_begin') }); diff --git a/src/database/mysql/mode/slowqueries.pm b/src/database/mysql/mode/slowqueries.pm index bdec836d7..4f982a66e 100644 --- a/src/database/mysql/mode/slowqueries.pm +++ b/src/database/mysql/mode/slowqueries.pm @@ -31,11 +31,11 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - }); + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' } + }); + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); return $self; @@ -53,7 +53,7 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); $self->{output}->option_exit(); } - + $self->{statefile_cache}->check_options(%options); } @@ -68,7 +68,7 @@ sub run { $self->{output}->add_option_msg(short_msg => "MySQL version '" . $self->{sql}->{version} . "' is not supported (need version >= '5.x')."); $self->{output}->option_exit(); } - + $self->{sql}->query(query => q{SHOW /*!50000 global */ STATUS LIKE 'Slow_queries'}); my ($name, $result) = $self->{sql}->fetchrow_array(); if (!defined($result)) { @@ -97,9 +97,10 @@ sub run { severity => $exit_code, short_msg => sprintf("%d slow queries since last check.", $value) ); + $self->{output}->perfdata_add( label => 'slow_queries_delta', - nlabel => 'database.slowqueries.delta', + nlabel => 'database.slowqueries.delta.count', value => $value, warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), @@ -109,8 +110,10 @@ sub run { $self->{statefile_cache}->write(data => $new_datas); if (!defined($old_timestamp)) { - $self->{output}->output_add(severity => 'OK', - short_msg => "Buffer creation..."); + $self->{output}->output_add( + severity => 'OK', + short_msg => "Buffer creation..." + ); } $self->{output}->display(); diff --git a/src/database/mysql/mode/threadsconnected.pm b/src/database/mysql/mode/threadsconnected.pm index 5974a96e6..9b89837f6 100644 --- a/src/database/mysql/mode/threadsconnected.pm +++ b/src/database/mysql/mode/threadsconnected.pm @@ -27,7 +27,7 @@ use warnings; sub custom_usage_output { my ($self, %options) = @_; - + return sprintf( 'Client connected threads total: %s used: %s (%.2f%%) free: %s (%.2f%%)', $self->{result_values}->{total}, @@ -44,7 +44,6 @@ sub prefix_databse_output { return "Database '" . $options{instance_value}->{name} . "' "; } - sub set_counters { my ($self, %options) = @_; diff --git a/src/database/mysql/mode/uptime.pm b/src/database/mysql/mode/uptime.pm index 232c3cb49..c295baeec 100644 --- a/src/database/mysql/mode/uptime.pm +++ b/src/database/mysql/mode/uptime.pm @@ -28,15 +28,14 @@ use POSIX; sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - "seconds" => { name => 'seconds', }, - }); + + $options{options}->add_options(arguments => { + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, + "seconds" => { name => 'seconds' } + }); return $self; } @@ -63,29 +62,33 @@ sub run { $self->{output}->add_option_msg(short_msg => "MySQL version '" . $self->{sql}->{version} . "' is not supported (need version >= '5.x')."); $self->{output}->option_exit(); } - + $options{sql}->query(query => q{SHOW /*!50000 global */ STATUS LIKE 'Uptime'}); my ($name, $value) = $options{sql}->fetchrow_array(); if (!defined($value)) { $self->{output}->add_option_msg(short_msg => "Cannot get uptime."); $self->{output}->option_exit(); } - + my $exit_code = $self->{perfdata}->threshold_check(value => $value, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); my $msg = sprintf("database is up since %d days", floor($value / 86400)); if (defined($self->{option_results}->{seconds})) { $msg = sprintf("database is up since %d seconds", $value); } - - $self->{output}->output_add(severity => $exit_code, - short_msg => $msg); - $self->{output}->perfdata_add(label => 'uptime', - nlabel => 'database.uptime.seconds', - unit => 's', - value => $value, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0); + + $self->{output}->output_add( + severity => $exit_code, + short_msg => $msg + ); + $self->{output}->perfdata_add( + label => 'uptime', + nlabel => 'database.uptime.seconds', + unit => 's', + value => $value, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0 + ); $self->{output}->display(); $self->{output}->exit(); diff --git a/src/database/mysql/plugin.pm b/src/database/mysql/plugin.pm index 46a7f8e21..14258eda4 100644 --- a/src/database/mysql/plugin.pm +++ b/src/database/mysql/plugin.pm @@ -39,6 +39,7 @@ sub new { 'long-queries' => 'database::mysql::mode::longqueries', 'myisam-keycache-hitrate' => 'database::mysql::mode::myisamkeycachehitrate', 'open-files' => 'database::mysql::mode::openfiles', + 'open-tables' => 'database::mysql::mode::opentables', 'password-expiration' => 'database::mysql::mode::passwordexpiration', 'qcache-hitrate' => 'database::mysql::mode::qcachehitrate', 'queries' => 'database::mysql::mode::queries',