(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 {
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;

View File

@ -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;

View File

@ -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,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};
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(
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'),
$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' : ''),
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);
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();

View File

@ -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();

View File

@ -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,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};
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(
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'),
$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' : ''),
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);
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();

View File

@ -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',

View File

@ -27,13 +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', },
$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',
$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);
min => 0
);
$self->{output}->display();
$self->{output}->exit();

View File

@ -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 => {

View File

@ -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;
@ -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,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});
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(
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'),
$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' : ''),
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);
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();

View File

@ -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 => {

View File

@ -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;
@ -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();

View File

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

View File

@ -28,14 +28,13 @@ 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;
@ -77,15 +76,19 @@ sub run {
$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',
$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);
min => 0
);
$self->{output}->display();
$self->{output}->exit();

View File

@ -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',