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

188 lines
6.4 KiB
Perl
Raw Normal View History

2015-08-06 16:11:56 +02:00
#
2019-01-09 09:57:11 +01:00
# Copyright 2019 Centreon (http://www.centreon.com/)
2015-08-06 16:11:56 +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.
#
package database::firebird::mode::queries;
2017-08-07 16:41:23 +02:00
use base qw(centreon::plugins::templates::counter);
2015-08-06 16:11:56 +02:00
use strict;
use warnings;
2017-08-07 16:41:23 +02:00
use Digest::MD5 qw(md5_hex);
2015-08-06 16:11:56 +02:00
2017-08-07 16:41:23 +02:00
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_output' }
];
$self->{maps_counters}->{global} = [
{ label => 'total', set => {
2015-08-07 11:33:56 +02:00
key_values => [ { name => 'total', diff => 1 } ],
per_second => 1,
output_template => 'Total : %d',
perfdatas => [
{ label => 'total', template => '%d', value => 'total_per_second',
unit => '/s', min => 0 },
],
}
},
2017-08-07 16:41:23 +02:00
{ label => 'seq-reads', set => {
2015-08-07 11:33:56 +02:00
key_values => [ { name => 'seq_reads', diff => 1 } ],
per_second => 1,
output_template => 'Seq Reads : %d',
perfdatas => [
{ label => 'seq_reads', template => '%d', value => 'seq_reads_per_second',
unit => '/s', min => 0 },
],
}
},
2017-08-07 16:41:23 +02:00
{ label => 'inserts', set => {
2015-08-07 11:33:56 +02:00
key_values => [ { name => 'inserts', diff => 1 } ],
per_second => 1,
output_template => 'Inserts : %d',
perfdatas => [
{ label => 'inserts', template => '%d', value => 'inserts_per_second',
unit => '/s', min => 0 },
],
}
},
2017-08-07 16:41:23 +02:00
{ label => 'updates', set => {
2015-08-07 11:33:56 +02:00
key_values => [ { name => 'updates', diff => 1 } ],
per_second => 1,
output_template => 'Updates : %d',
perfdatas => [
{ label => 'updates', template => '%d', value => 'updates_per_second',
unit => '/s', min => 0 },
],
}
},
2017-08-07 16:41:23 +02:00
{ label => 'deletes', set => {
key_values => [ { name => 'deletes', diff => 1 } ],
2015-08-07 11:33:56 +02:00
per_second => 1,
output_template => 'Deletes : %d',
perfdatas => [
{ label => 'deletes', template => '%d', value => 'deletes_per_second',
unit => '/s', min => 0 },
],
}
},
2017-08-07 16:41:23 +02:00
{ label => 'backouts', set => {
2015-08-07 11:33:56 +02:00
key_values => [ { name => 'backouts', diff => 1 } ],
per_second => 1,
output_template => 'Backouts : %d',
perfdatas => [
{ label => 'backouts', template => '%d', value => 'backouts_per_second',
unit => '/s', min => 0 },
],
}
},
2017-08-07 16:41:23 +02:00
{ label => 'purges', set => {
2015-08-07 11:33:56 +02:00
key_values => [ { name => 'purges', diff => 1 } ],
per_second => 1,
output_template => 'Purges : %d',
perfdatas => [
{ label => 'purges', template => '%d', value => 'purges_per_second',
unit => '/s', min => 0 },
],
}
},
2017-08-07 16:41:23 +02:00
{ label => 'expunges', set => {
2015-08-07 11:33:56 +02:00
key_values => [ { name => 'expunges', diff => 1 } ],
per_second => 1,
output_template => 'Expunges : %d',
perfdatas => [
{ label => 'expunges', template => '%d', value => 'expunges_per_second',
unit => '/s', min => 0 },
],
}
},
2017-08-07 16:41:23 +02:00
];
}
sub prefix_output {
my ($self, %options) = @_;
return "Records ";
}
2015-08-07 11:33:56 +02:00
2015-08-06 16:11:56 +02:00
sub new {
my ($class, %options) = @_;
2017-08-07 16:41:23 +02:00
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
2015-08-06 16:11:56 +02:00
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
2015-08-07 11:33:56 +02:00
{
2015-08-06 16:11:56 +02:00
});
2017-08-07 16:41:23 +02:00
return $self;
2015-08-06 16:11:56 +02:00
}
2015-08-07 11:33:56 +02:00
sub manage_selection {
my ($self, %options) = @_;
2017-08-07 16:41:23 +02:00
$options{sql}->connect();
$options{sql}->query(query => q{SELECT MON$RECORD_SEQ_READS as MYREADS,MON$RECORD_INSERTS as MYINSERTS,
2015-08-07 11:33:56 +02:00
MON$RECORD_UPDATES as MYUPDATES, MON$RECORD_DELETES as MYDELETES, MON$RECORD_BACKOUTS as MYBACKOUTS,
MON$RECORD_PURGES as MYPURGES, MON$RECORD_EXPUNGES as MYEXPUNGES
FROM MON$RECORD_STATS mr WHERE mr.MON$STAT_GROUP = '0'});
2017-08-07 16:41:23 +02:00
my $row = $options{sql}->fetchrow_hashref();
2015-08-07 11:33:56 +02:00
if (!defined($row)) {
$self->{output}->add_option_msg(short_msg => "Cannot get query informations");
$self->{output}->option_exit();
}
2017-08-07 16:41:23 +02:00
$self->{global} = { seq_reads => $row->{MYREADS}, inserts => $row->{MYINSERTS},
2015-08-07 11:33:56 +02:00
updates => $row->{MYUPDATES}, deletes => $row->{MYDELETES},
backouts => $row->{MYBACKOUTS}, purges => $row->{MYPURGES}, expunges => $row->{MYEXPUNGES} };
2017-08-07 16:41:23 +02:00
$self->{global}->{total} = $row->{MYREADS} + $row->{MYINSERTS} + $row->{MYUPDATES} +
2015-08-07 11:33:56 +02:00
$row->{MYDELETES} + $row->{MYBACKOUTS} + $row->{MYPURGES} + $row->{MYEXPUNGES};
2017-08-07 16:41:23 +02:00
$self->{cache_name} = "firebird_" . $self->{mode} . '_' . $options{sql}->get_unique_id4save() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
2015-08-07 11:33:56 +02:00
}
2015-08-06 16:11:56 +02:00
1;
__END__
=head1 MODE
2015-08-07 11:33:56 +02:00
Check queries statistics on current database.
2015-08-06 16:11:56 +02:00
2015-08-07 11:33:56 +02:00
=over 8)
2015-08-06 16:11:56 +02:00
2015-08-07 11:33:56 +02:00
=item B<--warning-*>
2015-08-06 16:11:56 +02:00
Threshold warning.
2015-08-07 11:33:56 +02:00
Can be: 'total', 'seq-reads', 'inserts', 'updates',
'deletes', 'backouts', 'purges', 'expunges'.
2015-08-06 16:11:56 +02:00
2015-08-07 11:33:56 +02:00
=item B<--critical-*>
2015-08-06 16:11:56 +02:00
Threshold critical.
2015-08-07 11:33:56 +02:00
Can be: 'total', 'seq-reads', 'inserts', 'updates',
'deletes', 'backouts', 'purges', 'expunges'.
2015-08-06 16:11:56 +02:00
=back
=cut