centreon-plugins/database/mysql/mode/queries.pm

134 lines
4.0 KiB
Perl
Raw Normal View History

2013-12-13 16:14:12 +01:00
#
2020-01-06 15:19:23 +01:00
# Copyright 2020 Centreon (http://www.centreon.com/)
2015-07-21 11:51:02 +02:00
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
2013-12-13 16:14:12 +01:00
package database::mysql::mode::queries;
2019-03-13 17:30:46 +01:00
use base qw(centreon::plugins::templates::counter);
2013-12-13 16:14:12 +01:00
use strict;
use warnings;
2019-03-13 17:30:46 +01:00
use Digest::MD5 qw(md5_hex);
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_output' },
];
$self->{maps_counters}->{global} = [
2019-06-07 14:48:30 +02:00
{ label => 'total', nlabel => 'queries.total.persecond', set => {
2020-05-13 14:18:28 +02:00
key_values => [ { name => 'Queries', per_second => 1 } ],
2019-03-13 17:30:46 +01:00
output_template => 'Total : %d',
perfdatas => [
2020-05-13 14:18:28 +02:00
{ label => 'total_requests', template => '%d', unit => '/s', min => 0 },
2019-03-13 17:30:46 +01:00
],
}
},
];
foreach ('update', 'delete', 'insert', 'truncate', 'select', 'commit', 'begin') {
push @{$self->{maps_counters}->{global}}, {
2019-04-18 10:34:54 +02:00
label => $_, nlabel => 'queries.' . $_ . '.persecond', display_ok => 0, set => {
2020-05-13 14:18:28 +02:00
key_values => [ { name => 'Com_' . $_, per_second => 1 } ],
2019-03-13 17:30:46 +01:00
output_template => $_ . ' : %d',
perfdatas => [
2020-05-13 14:18:28 +02:00
{ label => $_ . '_requests', template => '%d', unit => '/s', min => 0 }
]
2019-03-13 17:30:46 +01:00
}
};
push @{$self->{maps_counters}->{global}}, {
2019-04-17 22:45:31 +02:00
label => $_ . '-count', , nlabel => 'queries.' . $_ . '.count', display_ok => 0, set => {
2019-03-13 17:30:46 +01:00
key_values => [ { name => 'Com_' . $_, diff => 1 } ],
output_template => $_ . ' count : %d',
perfdatas => [
2020-05-13 14:18:28 +02:00
{ label => $_ . '_count', template => '%d', min => 0 }
]
2019-03-13 17:30:46 +01:00
}
};
}
}
sub prefix_output {
my ($self, %options) = @_;
return "Requests ";
}
2013-12-13 16:14:12 +01:00
sub new {
my ($class, %options) = @_;
2019-03-13 17:30:46 +01:00
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
2013-12-13 16:14:12 +01:00
bless $self, $class;
2019-03-13 17:30:46 +01:00
$options{options}->add_options(arguments => {
});
2013-12-13 16:14:12 +01:00
return $self;
}
2019-03-13 17:30:46 +01:00
sub manage_selection {
2013-12-13 16:14:12 +01:00
my ($self, %options) = @_;
2019-03-13 17:30:46 +01:00
$options{sql}->connect();
if (!($options{sql}->is_version_minimum(version => '5.0.76'))) {
2013-12-13 16:14:12 +01:00
$self->{output}->add_option_msg(short_msg => "MySQL version '" . $self->{sql}->{version} . "' is not supported (need version >= '5.0.76').");
$self->{output}->option_exit();
}
2019-03-13 17:30:46 +01:00
$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')
});
$self->{global} = {};
my $result = $options{sql}->fetchall_arrayref();
2013-12-13 16:14:12 +01:00
foreach my $row (@{$result}) {
2019-03-13 17:30:46 +01:00
$self->{global}->{$$row[0]} = $$row[1];
2013-12-13 16:14:12 +01:00
}
2019-03-13 17:30:46 +01:00
$self->{cache_name} = "mysql_" . $self->{mode} . '_' . $options{sql}->get_unique_id4save() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
2013-12-13 16:14:12 +01:00
}
1;
__END__
=head1 MODE
Check average number of queries executed.
=over 8
2019-03-13 17:30:46 +01:00
=item B<--warning-*>
2013-12-13 16:14:12 +01:00
Threshold warning.
2019-03-13 17:30:46 +01:00
Can be: 'total', 'update', 'insert', 'delete', 'truncate',
'select', 'begin', 'commit'.
2013-12-13 16:14:12 +01:00
2019-03-13 17:30:46 +01:00
=item B<--critical-*>
2013-12-13 16:14:12 +01:00
Threshold critical.
2019-03-13 17:30:46 +01:00
Can be: 'total', 'update', 'insert', 'delete', 'truncate',
'select', 'begin', 'commit'.
2013-12-13 16:14:12 +01:00
=back
=cut