(plugin) database::mysql - force new perfdata (#4454)

This commit is contained in:
qgarnier 2023-06-09 16:39:58 +02:00 committed by GitHub
parent b35b0f9728
commit 8e92c2a8ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 211 additions and 182 deletions

View File

@ -29,12 +29,12 @@ use POSIX;
sub new { sub new {
my ($class, %options) = @_; 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; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
"warning:s" => { name => 'warning', }, 'warning:s' => { name => 'warning', },
"critical:s" => { name => 'critical', }, 'critical:s' => { name => 'critical' }
}); });
return $self; return $self;
@ -45,12 +45,12 @@ sub check_options {
$self->SUPER::init(%options); $self->SUPER::init(%options);
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { 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}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { 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}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
} }

View File

@ -36,7 +36,7 @@ sub set_counters {
group => [ group => [
{ name => 'global_db', type => 0, skipped_code => { -10 => 1 } }, { name => 'global_db', type => 0, skipped_code => { -10 => 1 } },
{ name => 'table', display_long => 0, cb_prefix_output => 'prefix_table_output', { 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_template => 'Used Space: %s %s',
output_change_bytes => 1, output_change_bytes => 1,
perfdatas => [ perfdatas => [
{ value => 'used', template => '%s', unit => 'B', { template => '%s', unit => 'B', min => 0 }
min => 0 }, ]
],
} }
}, },
{ label => 'total-free', nlabel => 'databases.space.free.bytes', set => { { label => 'total-free', nlabel => 'databases.space.free.bytes', set => {
@ -57,11 +56,10 @@ sub set_counters {
output_template => 'Free Space: %s %s', output_template => 'Free Space: %s %s',
output_change_bytes => 1, output_change_bytes => 1,
perfdatas => [ perfdatas => [
{ value => 'free', template => '%s', unit => 'B', { template => '%s', unit => 'B', min => 0 }
min => 0 }, ]
],
} }
}, }
]; ];
$self->{maps_counters}->{global_db} = [ $self->{maps_counters}->{global_db} = [
@ -70,9 +68,8 @@ sub set_counters {
output_template => 'Used: %s %s', output_template => 'Used: %s %s',
output_change_bytes => 1, output_change_bytes => 1,
perfdatas => [ perfdatas => [
{ value => 'used', template => '%s', unit => 'B', { template => '%s', unit => 'B', min => 0, label_extra_instance => 1 }
min => 0, label_extra_instance => 1 }, ]
],
} }
}, },
{ label => 'db-free', nlabel => 'database.space.free.bytes', set => { { label => 'db-free', nlabel => 'database.space.free.bytes', set => {
@ -80,11 +77,10 @@ sub set_counters {
output_template => 'Free: %s %s', output_template => 'Free: %s %s',
output_change_bytes => 1, output_change_bytes => 1,
perfdatas => [ perfdatas => [
{ value => 'free', template => '%s', unit => 'B', { template => '%s', unit => 'B', min => 0, label_extra_instance => 1 }
min => 0, label_extra_instance => 1 }, ]
],
} }
}, }
]; ];
$self->{maps_counters}->{table} = [ $self->{maps_counters}->{table} = [
@ -93,9 +89,8 @@ sub set_counters {
output_template => 'Used: %s %s', output_template => 'Used: %s %s',
output_change_bytes => 1, output_change_bytes => 1,
perfdatas => [ perfdatas => [
{ value => 'used', template => '%s', unit => 'B', { template => '%s', unit => 'B', min => 0, label_extra_instance => 1 }
min => 0, label_extra_instance => 1 }, ]
],
} }
}, },
{ label => 'table-free', nlabel => 'table.space.free.bytes', set => { { label => 'table-free', nlabel => 'table.space.free.bytes', set => {
@ -103,20 +98,18 @@ sub set_counters {
output_template => 'Free: %s %s', output_template => 'Free: %s %s',
output_change_bytes => 1, output_change_bytes => 1,
perfdatas => [ perfdatas => [
{ value => 'free', template => '%s', unit => 'B', { template => '%s', unit => 'B', min => 0, label_extra_instance => 1 }
min => 0, label_extra_instance => 1 }, ]
],
} }
}, },
{ label => 'table-frag', nlabel => 'table.fragmentation.percentage', set => { { label => 'table-frag', nlabel => 'table.fragmentation.percentage', set => {
key_values => [ { name => 'frag' }, { name => 'display' } ], key_values => [ { name => 'frag' }, { name => 'display' } ],
output_template => 'Fragmentation: %.2f %%', output_template => 'Fragmentation: %.2f %%',
perfdatas => [ perfdatas => [
{ value => 'frag', template => '%.2f', unit => '%', { template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 }
min => 0, max => 100, label_extra_instance => 1 }, ]
],
} }
}, }
]; ];
} }
@ -157,7 +150,7 @@ sub new {
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'filter-database:s' => { name => 'filter_database' }, 'filter-database:s' => { name => 'filter_database' },
'filter-table:s' => { name => 'filter_table' }, 'filter-table:s' => { name => 'filter_table' }
}); });
return $self; return $self;

View File

@ -28,15 +28,15 @@ use centreon::plugins::statefile;
sub new { sub new {
my ($class, %options) = @_; 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; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'warning:s' => { name => 'warning' },
"warning:s" => { name => 'warning', }, 'critical:s' => { name => 'critical' },
"critical:s" => { name => 'critical', }, 'lookback' => { name => 'lookback' }
"lookback" => { name => 'lookback', }, });
});
$self->{statefile_cache} = centreon::plugins::statefile->new(%options); $self->{statefile_cache} = centreon::plugins::statefile->new(%options);
return $self; return $self;
@ -100,27 +100,35 @@ 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}; $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' } ]); 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, $self->{output}->output_add(
short_msg => sprintf("innodb buffer pool hitrate at %.2f%%", $prcts{'bufferpool_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now')}) 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 => '%', $self->{output}->perfdata_add(
value => sprintf("%.2f", $prcts{'bufferpool_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now')}), label => 'bufferpool_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now'),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), nlabel => 'database.bufferpool.hitrate' . ((defined($self->{option_results}->{lookback})) ? '.average' : '.delta') . '.percentage',
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), unit => '%',
min => 0); value => sprintf("%.2f", $prcts{'bufferpool_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now')}),
$self->{output}->perfdata_add(label => 'bufferpool_hitrate' . ((defined($self->{option_results}->{lookback})) ? '_now' : ''), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
nlabel => 'database.bufferpool.hitrate' . ((defined($self->{option_results}->{lookback})) ? '.delta' : '.average') . '.percentage', critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
unit => '%', min => 0
value => sprintf("%.2f", $prcts{'bufferpool_hitrate' . ((defined($self->{option_results}->{lookback})) ? '_now' : '')}), );
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); $self->{statefile_cache}->write(data => $new_datas);
if (!defined($old_timestamp)) { if (!defined($old_timestamp)) {
$self->{output}->output_add(severity => 'OK', $self->{output}->output_add(
short_msg => "Buffer creation..."); severity => 'OK',
short_msg => "Buffer creation..."
);
} }
$self->{output}->display(); $self->{output}->display();

View File

@ -27,7 +27,7 @@ use warnings;
sub new { sub new {
my ($class, %options) = @_; 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; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
@ -35,7 +35,7 @@ sub new {
'critical:s' => { name => 'critical', }, 'critical:s' => { name => 'critical', },
'seconds:s' => { name => 'seconds', default => 60 }, 'seconds:s' => { name => 'seconds', default => 60 },
'filter-user:s' => { name => 'filter_user' }, 'filter-user:s' => { name => 'filter_user' },
'filter-command:s' => { name => 'filter_command', default => '^(?!(sleep)$)' }, 'filter-command:s' => { name => 'filter_command', default => '^(?!(sleep)$)' }
}); });
return $self; return $self;
@ -61,7 +61,6 @@ sub check_options {
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
# $options{sql} = sqlmode object
$self->{sql} = $options{sql}; $self->{sql} = $options{sql};
$self->{sql}->connect(); $self->{sql}->connect();

View File

@ -28,15 +28,15 @@ use centreon::plugins::statefile;
sub new { sub new {
my ($class, %options) = @_; 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; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'warning:s' => { name => 'warning', },
"warning:s" => { name => 'warning', }, 'critical:s' => { name => 'critical', },
"critical:s" => { name => 'critical', }, 'lookback' => { name => 'lookback' }
"lookback" => { name => 'lookback', }, });
});
$self->{statefile_cache} = centreon::plugins::statefile->new(%options); $self->{statefile_cache} = centreon::plugins::statefile->new(%options);
return $self; return $self;
@ -101,27 +101,35 @@ 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}; $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' } ]); 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, $self->{output}->output_add(
short_msg => sprintf("myisam keycache hitrate at %.2f%%", $prcts{'keycache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now')}) 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 => '%', $self->{output}->perfdata_add(
value => sprintf("%.2f", $prcts{'keycache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now')}), label => 'keycache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now'),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), nlabel => 'database.keycache.hitrate' . ((defined($self->{option_results}->{lookback})) ? '.average' : '.delta') . '.percentage',
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), unit => '%',
min => 0); value => sprintf("%.2f", $prcts{'keycache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now')}),
$self->{output}->perfdata_add(label => 'keycache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '_now' : ''), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
nlabel => 'database.keycache.hitrate' . ((defined($self->{option_results}->{lookback})) ? '.delta' : '.average') . '.percentage', critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
unit => '%', min => 0
value => sprintf("%.2f", $prcts{'keycache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '_now' : '')}), );
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); $self->{statefile_cache}->write(data => $new_datas);
if (!defined($old_timestamp)) { if (!defined($old_timestamp)) {
$self->{output}->output_add(severity => 'OK', $self->{output}->output_add(
short_msg => "Buffer creation..."); severity => 'OK',
short_msg => "Buffer creation..."
);
} }
$self->{output}->display(); $self->{output}->display();

View File

@ -27,12 +27,12 @@ use warnings;
sub new { sub new {
my ($class, %options) = @_; 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; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'warning:s' => { name => 'warning', }, 'warning:s' => { name => 'warning' },
'critical:s' => { name => 'critical', }, 'critical:s' => { name => 'critical' }
}); });
return $self; return $self;
@ -84,6 +84,7 @@ sub run {
$prct_open, $open_files, $open_files_limit $prct_open, $open_files, $open_files_limit
) )
); );
$self->{output}->perfdata_add( $self->{output}->perfdata_add(
label => 'open_files', label => 'open_files',
nlabel => 'database.open.files.count', nlabel => 'database.open.files.count',

View File

@ -27,14 +27,13 @@ use warnings;
sub new { sub new {
my ($class, %options) = @_; 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; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'warning:s' => { name => 'warning' },
"warning:s" => { name => 'warning', }, 'critical:s' => { name => 'critical' }
"critical:s" => { name => 'critical', }, });
});
return $self; return $self;
} }
@ -81,15 +80,21 @@ sub run {
my $prct_open = int(100 * $open_tables / $open_tables_limit); 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' } ]); 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, $self->{output}->output_add(
short_msg => sprintf("%.2f%% of the open files limit reached (%d of max. %d)", severity => $exit_code,
$prct_open, $open_tables, $open_tables_limit)); short_msg => sprintf(
$self->{output}->perfdata_add(label => 'open_tables', "%.2f%% of the open files limit reached (%d of max. %d)",
nlabel => 'database.open.tables.count', $prct_open, $open_tables, $open_tables_limit
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), $self->{output}->perfdata_add(
min => 0); 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}->display();
$self->{output}->exit(); $self->{output}->exit();

View File

@ -66,7 +66,7 @@ sub set_counters {
sub new { sub new {
my ($class, %options) = @_; 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; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {

View File

@ -28,15 +28,15 @@ use centreon::plugins::statefile;
sub new { sub new {
my ($class, %options) = @_; 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; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'warning:s' => { name => 'warning' },
"warning:s" => { name => 'warning', }, 'critical:s' => { name => 'critical' },
"critical:s" => { name => 'critical', }, 'lookback' => { name => 'lookback' }
"lookback" => { name => 'lookback', }, });
});
$self->{statefile_cache} = centreon::plugins::statefile->new(%options); $self->{statefile_cache} = centreon::plugins::statefile->new(%options);
return $self; return $self;
@ -94,8 +94,10 @@ sub run {
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
if ($have_query_cache !~ /^yes$/i || $query_cache_size == 0) { if ($have_query_cache !~ /^yes$/i || $query_cache_size == 0) {
$self->{output}->output_add(severity => 'OK', $self->{output}->output_add(
short_msg => "Query cache is turned off."); severity => 'OK',
short_msg => "Query cache is turned off."
);
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();
} }
@ -117,27 +119,34 @@ 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}); $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' } ]); 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, $self->{output}->output_add(
short_msg => sprintf("query cache hitrate at %.2f%%", $prcts{'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now')}) 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', $self->{output}->perfdata_add(
unit => '%', label => 'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now'),
value => sprintf("%.2f", $prcts{'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now')}), nlabel => 'database.qcache.hitrate' . ((defined($self->{option_results}->{lookback})) ? '.average' : '.delta') . '.percentage',
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), unit => '%',
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), value => sprintf("%.2f", $prcts{'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now')}),
min => 0); warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
$self->{output}->perfdata_add(label => 'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '_now' : ''), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
nlabel => 'database.qcache.hitrate' . ((defined($self->{option_results}->{lookback})) ? '.delta' : '.average') . '.percentage', min => 0
unit => '%', );
value => sprintf("%.2f", $prcts{'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '_now' : '')}), $self->{output}->perfdata_add(
min => 0); 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); $self->{statefile_cache}->write(data => $new_datas);
if (!defined($old_timestamp)) { if (!defined($old_timestamp)) {
$self->{output}->output_add(severity => 'OK', $self->{output}->output_add(
short_msg => "Buffer creation..."); severity => 'OK',
short_msg => "Buffer creation..."
);
} }
$self->{output}->display(); $self->{output}->display();

View File

@ -26,11 +26,17 @@ use strict;
use warnings; use warnings;
use Digest::MD5 qw(md5_hex); use Digest::MD5 qw(md5_hex);
sub prefix_output {
my ($self, %options) = @_;
return "Requests ";
}
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $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} = [ $self->{maps_counters}->{global} = [
@ -38,10 +44,10 @@ sub set_counters {
key_values => [ { name => 'Queries', per_second => 1 } ], key_values => [ { name => 'Queries', per_second => 1 } ],
output_template => 'Total : %d', output_template => 'Total : %d',
perfdatas => [ 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') { 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 { sub new {
my ($class, %options) = @_; 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; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {

View File

@ -31,11 +31,11 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'warning:s' => { name => 'warning' },
"warning:s" => { name => 'warning', }, 'critical:s' => { name => 'critical' }
"critical:s" => { name => 'critical', }, });
});
$self->{statefile_cache} = centreon::plugins::statefile->new(%options); $self->{statefile_cache} = centreon::plugins::statefile->new(%options);
return $self; return $self;
@ -97,9 +97,10 @@ sub run {
severity => $exit_code, severity => $exit_code,
short_msg => sprintf("%d slow queries since last check.", $value) short_msg => sprintf("%d slow queries since last check.", $value)
); );
$self->{output}->perfdata_add( $self->{output}->perfdata_add(
label => 'slow_queries_delta', label => 'slow_queries_delta',
nlabel => 'database.slowqueries.delta', nlabel => 'database.slowqueries.delta.count',
value => $value, value => $value,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
@ -109,8 +110,10 @@ sub run {
$self->{statefile_cache}->write(data => $new_datas); $self->{statefile_cache}->write(data => $new_datas);
if (!defined($old_timestamp)) { if (!defined($old_timestamp)) {
$self->{output}->output_add(severity => 'OK', $self->{output}->output_add(
short_msg => "Buffer creation..."); severity => 'OK',
short_msg => "Buffer creation..."
);
} }
$self->{output}->display(); $self->{output}->display();

View File

@ -44,7 +44,6 @@ sub prefix_databse_output {
return "Database '" . $options{instance_value}->{name} . "' "; return "Database '" . $options{instance_value}->{name} . "' ";
} }
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;

View File

@ -28,15 +28,14 @@ use POSIX;
sub new { sub new {
my ($class, %options) = @_; 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; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ "warning:s" => { name => 'warning' },
"warning:s" => { name => 'warning', }, "critical:s" => { name => 'critical' },
"critical:s" => { name => 'critical', }, "seconds" => { name => 'seconds' }
"seconds" => { name => 'seconds', }, });
});
return $self; return $self;
} }
@ -77,15 +76,19 @@ sub run {
$msg = sprintf("database is up since %d seconds", $value); $msg = sprintf("database is up since %d seconds", $value);
} }
$self->{output}->output_add(severity => $exit_code, $self->{output}->output_add(
short_msg => $msg); severity => $exit_code,
$self->{output}->perfdata_add(label => 'uptime', short_msg => $msg
nlabel => 'database.uptime.seconds', );
unit => 's', $self->{output}->perfdata_add(
value => $value, label => 'uptime',
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), nlabel => 'database.uptime.seconds',
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), unit => 's',
min => 0); 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}->display();
$self->{output}->exit(); $self->{output}->exit();

View File

@ -39,6 +39,7 @@ sub new {
'long-queries' => 'database::mysql::mode::longqueries', 'long-queries' => 'database::mysql::mode::longqueries',
'myisam-keycache-hitrate' => 'database::mysql::mode::myisamkeycachehitrate', 'myisam-keycache-hitrate' => 'database::mysql::mode::myisamkeycachehitrate',
'open-files' => 'database::mysql::mode::openfiles', 'open-files' => 'database::mysql::mode::openfiles',
'open-tables' => 'database::mysql::mode::opentables',
'password-expiration' => 'database::mysql::mode::passwordexpiration', 'password-expiration' => 'database::mysql::mode::passwordexpiration',
'qcache-hitrate' => 'database::mysql::mode::qcachehitrate', 'qcache-hitrate' => 'database::mysql::mode::qcachehitrate',
'queries' => 'database::mysql::mode::queries', 'queries' => 'database::mysql::mode::queries',