remove tablesize object
This commit is contained in:
parent
f89f5dd31c
commit
b0af945571
|
@ -156,7 +156,8 @@ sub new {
|
|||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
'filter-database:s' => { name => 'filter_database' },
|
||||
'filter-database:s' => { name => 'filter_database' },
|
||||
'filter-table:s' => { name => 'filter_table' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
|
@ -186,8 +187,17 @@ sub manage_selection {
|
|||
$self->{global} = { free => 0, used => 0 };
|
||||
$self->{database} = {};
|
||||
foreach my $row (@$result) {
|
||||
next if (defined($self->{option_results}->{filter_database}) && $self->{option_results}->{filter_database} ne '' &&
|
||||
$row->[0] !~ /$self->{option_results}->{filter_database}/);
|
||||
if (defined($self->{option_results}->{filter_database}) && $self->{option_results}->{filter_database} ne '' &&
|
||||
$row->[0] !~ /$self->{option_results}->{filter_database}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $row->[0] . '.' . $row->[1] . "': no matching filter.", debug => 1);
|
||||
next
|
||||
}
|
||||
if (defined($self->{option_results}->{filter_table}) && $self->{option_results}->{filter_table} ne '' &&
|
||||
$row->[1] !~ /$self->{option_results}->{filter_table}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $row->[0] . '.' . $row->[1] . "': no matching filter.", debug => 1);
|
||||
next
|
||||
}
|
||||
|
||||
if (!defined($self->{database}->{$row->[0]})) {
|
||||
$self->{database}->{$row->[0]} = {
|
||||
display => $row->[0],
|
||||
|
@ -227,7 +237,7 @@ __END__
|
|||
|
||||
=head1 MODE
|
||||
|
||||
Check MySQL databases size.
|
||||
Check MySQL databases size and tables.
|
||||
|
||||
=over 8
|
||||
|
||||
|
@ -235,6 +245,10 @@ Check MySQL databases size.
|
|||
|
||||
Filter database to checks (Can be a regexp).
|
||||
|
||||
=item B<--filter-table>
|
||||
|
||||
Filter table name (can be a regexp).
|
||||
|
||||
=item B<--warning-*> B<--critical-*>
|
||||
|
||||
Thresholds (Can be: 'total-usage', 'total-free', 'db-usage',
|
||||
|
|
|
@ -1,146 +0,0 @@
|
|||
#
|
||||
# Copyright 2020 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# 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::mysql::mode::tablessize;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0 },
|
||||
{ name => 'table', type => 1, cb_prefix_output => 'prefix_table_output', message_multiple => 'All tables sizes are ok' },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'total', nlabel => 'table.usage.bytes', set => {
|
||||
key_values => [ { name => 'total' } ],
|
||||
output_template => 'Total Size : %s%s',
|
||||
output_change_bytes => 1,
|
||||
perfdatas => [
|
||||
{ label => 'total', value => 'total_absolute', template => '%s',
|
||||
unit => 'B', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
$self->{maps_counters}->{table} = [
|
||||
{ label => 'table', nlabel => 'table.usage.bytes', set => {
|
||||
key_values => [ { name => 'size' }, { name => 'display' } ],
|
||||
output_template => 'size : %s%s',
|
||||
output_change_bytes => 1,
|
||||
perfdatas => [
|
||||
{ label => 'table', value => 'size_absolute', template => '%s',
|
||||
unit => 'B', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"filter-db:s" => { name => 'filter_db' },
|
||||
"filter-table:s" => { name => 'filter_table' },
|
||||
});
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub prefix_table_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Table '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$options{sql}->connect();
|
||||
$options{sql}->query(query => "SELECT table_schema AS DB, table_name AS NAME, ROUND(data_length + index_length)
|
||||
FROM information_schema.TABLES");
|
||||
my $result = $options{sql}->fetchall_arrayref();
|
||||
|
||||
if (!($options{sql}->is_version_minimum(version => '5'))) {
|
||||
$self->{output}->add_option_msg(short_msg => "MySQL version '" . $self->{sql}->{version} . "' is not supported.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{global} = { total => 0 };
|
||||
$self->{table} = {};
|
||||
|
||||
foreach my $row (@$result) {
|
||||
next if (!defined($$row[2]));
|
||||
if (defined($self->{option_results}->{filter_table}) && $self->{option_results}->{filter_table} ne '' &&
|
||||
$$row[1] !~ /$self->{option_results}->{filter_table}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $$row[0].'.'.$$row[1] . "': no matching filter.", debug => 1);
|
||||
next;
|
||||
}
|
||||
if (defined($self->{option_results}->{filter_db}) && $self->{option_results}->{filter_db} ne '' &&
|
||||
$$row[0] !~ /$self->{option_results}->{filter_db}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $$row[0].'.'.$$row[1] . "': no matching filter.", debug => 1);
|
||||
next
|
||||
}
|
||||
$self->{table}->{$$row[0].'.'.$$row[1]} = { size => $$row[2], display => $$row[0].'.'.$$row[1] };
|
||||
$self->{global}->{total} += $$row[2] if defined($self->{table}->{$$row[0].'.'.$$row[1]});
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check size of one (or more) table from one (or more) databases
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--filter-counters>
|
||||
|
||||
Only display some counters (regexp can be used).
|
||||
|
||||
=item B<--filter-db>
|
||||
|
||||
Filter DB name (can be a regexp).
|
||||
|
||||
=item B<--filter-table>
|
||||
|
||||
Filter table name (can be a regexp).
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Set warning threshold for number of user. Can be : 'total', 'table'
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Set critical threshold for number of user. Can be : 'total', 'table'
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -26,7 +26,6 @@ use base qw(centreon::plugins::script_sql);
|
|||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
|
@ -45,7 +44,6 @@ sub new {
|
|||
'slow-queries' => 'database::mysql::mode::slowqueries',
|
||||
'sql' => 'centreon::common::protocols::sql::mode::sql',
|
||||
'sql-string' => 'centreon::common::protocols::sql::mode::sqlstring',
|
||||
'tables-size' => 'database::mysql::mode::tablessize',
|
||||
'threads-connected' => 'database::mysql::mode::threadsconnected',
|
||||
'uptime' => 'database::mysql::mode::uptime',
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue