enhance plugin: php apc and firebird
This commit is contained in:
parent
920ef2025f
commit
defbc8dbb8
|
@ -293,7 +293,7 @@ Threshold for HTTP timeout (Default: 30)
|
|||
|
||||
Threshold warning.
|
||||
Can be: 'request-rate', 'request-rate-now',
|
||||
'hit-rate', 'hit-rate-now', 'miss-rate', 'miss-rate-now', 'insert-rate',
|
||||
'hit-rate', 'hit-rate-now', 'miss-rate', 'miss-rate-now',
|
||||
'hit-percent', 'hit-percent-now'.
|
||||
'*-now' are rate between two calls.
|
||||
|
||||
|
@ -301,7 +301,7 @@ Can be: 'request-rate', 'request-rate-now',
|
|||
|
||||
Threshold critical.
|
||||
Can be: 'request-rate', 'request-rate-now',
|
||||
'hit-rate', 'hit-rate-now', 'miss-rate', 'miss-rate-now', 'insert-rate',
|
||||
'hit-rate', 'hit-rate-now', 'miss-rate', 'miss-rate-now',
|
||||
'hit-percent', 'hit-percent-now'.
|
||||
'*-now' are rate between two calls.
|
||||
|
||||
|
|
|
@ -127,9 +127,9 @@ Threshold warning (number of long queries).
|
|||
|
||||
Threshold critical (number of long queries).
|
||||
|
||||
=item B<--critical>
|
||||
=item B<--seconds>
|
||||
|
||||
Threshold critical (number of long queries).
|
||||
Filter queries over X seconds (Default: 60).
|
||||
|
||||
=item B<--filter-user>
|
||||
|
||||
|
|
|
@ -20,56 +20,61 @@
|
|||
|
||||
package database::firebird::mode::memory;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::values;
|
||||
|
||||
my $maps_counters = {
|
||||
global => {
|
||||
'000_used' => { set => {
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0, cb_prefix_output => 'prefix_output' }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'used', set => {
|
||||
key_values => [ { name => 'database_used' }, { name => 'database_allocated' } ],
|
||||
closure_custom_calc => \&custom_unit_calc, closure_custom_calc_extra_options => { label_ref => 'database' },
|
||||
closure_custom_output => \&custom_used_output,
|
||||
closure_custom_calc => $self->can('custom_unit_calc'), closure_custom_calc_extra_options => { label_ref => 'database' },
|
||||
closure_custom_output => $self->can('custom_used_output'),
|
||||
threshold_use => 'prct',
|
||||
closure_custom_perfdata => \&custom_used_perfdata,
|
||||
closure_custom_perfdata => $self->can('custom_used_perfdata'),
|
||||
}
|
||||
},
|
||||
'001_attachment' => { set => {
|
||||
{ label => 'attachment', set => {
|
||||
key_values => [ { name => 'attachment_used' }, { name => 'database_allocated' } ],
|
||||
closure_custom_calc => \&custom_unit_calc, closure_custom_calc_extra_options => { label_ref => 'attachment' },
|
||||
closure_custom_output => \&custom_unit_output,
|
||||
closure_custom_calc => $self->can('custom_unit_calc'), closure_custom_calc_extra_options => { label_ref => 'attachment' },
|
||||
closure_custom_output => $self->can('custom_unit_output'),
|
||||
threshold_use => 'prct',
|
||||
closure_custom_perfdata => \&custom_unit_perfdata,
|
||||
closure_custom_perfdata => $self->can('custom_unit_perfdata'),
|
||||
}
|
||||
},
|
||||
'002_transaction' => { set => {
|
||||
{ label => 'transaction', set => {
|
||||
key_values => [ { name => 'transaction_used' }, { name => 'database_allocated' } ],
|
||||
closure_custom_calc => \&custom_unit_calc, closure_custom_calc_extra_options => { label_ref => 'transaction' },
|
||||
closure_custom_output => \&custom_unit_output,
|
||||
closure_custom_calc => $self->can('custom_unit_calc'), closure_custom_calc_extra_options => { label_ref => 'transaction' },
|
||||
closure_custom_output => $self->can('custom_unit_output'),
|
||||
threshold_use => 'prct',
|
||||
closure_custom_perfdata => \&custom_unit_perfdata,
|
||||
closure_custom_perfdata => $self->can('custom_unit_perfdata'),
|
||||
}
|
||||
},
|
||||
'003_statement' => { set => {
|
||||
{ label => 'statement', set => {
|
||||
key_values => [ { name => 'statement_used' }, { name => 'database_allocated' } ],
|
||||
closure_custom_calc => \&custom_unit_calc, closure_custom_calc_extra_options => { label_ref => 'statement' },
|
||||
closure_custom_output => \&custom_unit_output,
|
||||
closure_custom_calc => $self->can('custom_unit_calc'), closure_custom_calc_extra_options => { label_ref => 'statement' },
|
||||
closure_custom_output => $self->can('custom_unit_output'),
|
||||
threshold_use => 'prct',
|
||||
closure_custom_perfdata => \&custom_unit_perfdata,
|
||||
closure_custom_perfdata => $self->can('custom_unit_perfdata'),
|
||||
}
|
||||
},
|
||||
'004_call' => { set => {
|
||||
{ label => 'call', set => {
|
||||
key_values => [ { name => 'call_used' }, { name => 'database_allocated' } ],
|
||||
closure_custom_calc => \&custom_unit_calc, closure_custom_calc_extra_options => { label_ref => 'call' },
|
||||
closure_custom_output => \&custom_unit_output,
|
||||
closure_custom_calc => $self->can('custom_unit_calc'), closure_custom_calc_extra_options => { label_ref => 'call' },
|
||||
closure_custom_output => $self->can('custom_unit_output'),
|
||||
threshold_use => 'prct',
|
||||
closure_custom_perfdata => \&custom_unit_perfdata,
|
||||
closure_custom_perfdata => $self->can('custom_unit_perfdata'),
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
];
|
||||
}
|
||||
|
||||
sub custom_used_output {
|
||||
my ($self, %options) = @_;
|
||||
|
@ -130,6 +135,12 @@ sub custom_unit_calc {
|
|||
return 0;
|
||||
}
|
||||
|
||||
sub prefix_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Memory ";
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
|
@ -140,101 +151,25 @@ sub new {
|
|||
{
|
||||
});
|
||||
|
||||
foreach my $key (('global')) {
|
||||
foreach (keys %{$maps_counters->{$key}}) {
|
||||
my ($id, $name) = split /_/;
|
||||
if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) {
|
||||
$options{options}->add_options(arguments => {
|
||||
'warning-' . $name . ':s' => { name => 'warning-' . $name },
|
||||
'critical-' . $name . ':s' => { name => 'critical-' . $name },
|
||||
});
|
||||
}
|
||||
$maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output},
|
||||
perfdata => $self->{perfdata},
|
||||
label => $name);
|
||||
$maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}});
|
||||
}
|
||||
}
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
foreach my $key (('global')) {
|
||||
foreach (keys %{$maps_counters->{$key}}) {
|
||||
$maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{sql} = $options{sql};
|
||||
|
||||
$self->manage_selection();
|
||||
|
||||
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
|
||||
my @exits;
|
||||
|
||||
foreach (sort keys %{$maps_counters->{global}}) {
|
||||
my $obj = $maps_counters->{global}->{$_}->{obj};
|
||||
|
||||
$obj->set(instance => 'firebird');
|
||||
|
||||
my ($value_check) = $obj->execute(values => $self->{firebird});
|
||||
|
||||
if ($value_check != 0) {
|
||||
$long_msg .= $long_msg_append . $obj->output_error();
|
||||
$long_msg_append = ', ';
|
||||
next;
|
||||
}
|
||||
my $exit2 = $obj->threshold_check();
|
||||
push @exits, $exit2;
|
||||
|
||||
my $output = $obj->output();
|
||||
$long_msg .= $long_msg_append . $output;
|
||||
$long_msg_append = ', ';
|
||||
|
||||
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
|
||||
$short_msg .= $short_msg_append . $output;
|
||||
$short_msg_append = ', ';
|
||||
}
|
||||
|
||||
$obj->perfdata();
|
||||
}
|
||||
|
||||
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
|
||||
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => "Memory $short_msg"
|
||||
);
|
||||
} else {
|
||||
$self->{output}->output_add(short_msg => "Memory $long_msg");
|
||||
}
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{sql}->connect();
|
||||
$self->{sql}->query(query => q{SELECT MON$STAT_GROUP as MYGROUP, MON$MEMORY_ALLOCATED AS MYTOTAL, MON$MEMORY_USED AS MYUSED FROM MON$MEMORY_USAGE});
|
||||
$options{sql}->connect();
|
||||
$options{sql}->query(query => q{SELECT MON$STAT_GROUP as MYGROUP, MON$MEMORY_ALLOCATED AS MYTOTAL, MON$MEMORY_USED AS MYUSED FROM MON$MEMORY_USAGE});
|
||||
|
||||
my %map_group = (0 => 'database', 1 => 'attachment', 2 => 'transaction', 3 => 'statement', 4 => 'call');
|
||||
|
||||
$self->{firebird} = {};
|
||||
while ((my $row = $self->{sql}->fetchrow_hashref())) {
|
||||
$self->{global} = {};
|
||||
while ((my $row = $options{sql}->fetchrow_hashref())) {
|
||||
if (!defined($self->{firebird}->{$map_group{$row->{MYGROUP}} . '_used'})) {
|
||||
$self->{firebird}->{$map_group{$row->{MYGROUP}} . '_used'} = 0;
|
||||
$self->{firebird}->{$map_group{$row->{MYGROUP}} . '_allocated'} = 0;
|
||||
$self->{global}->{$map_group{$row->{MYGROUP}} . '_used'} = 0;
|
||||
$self->{global}->{$map_group{$row->{MYGROUP}} . '_allocated'} = 0;
|
||||
}
|
||||
$self->{firebird}->{$map_group{$row->{MYGROUP}} . '_used'} += $row->{MYUSED};
|
||||
$self->{firebird}->{$map_group{$row->{MYGROUP}} . '_allocated'} += $row->{MYTOTAL};
|
||||
$self->{global}->{$map_group{$row->{MYGROUP}} . '_used'} += $row->{MYUSED};
|
||||
$self->{global}->{$map_group{$row->{MYGROUP}} . '_allocated'} += $row->{MYTOTAL};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,16 +20,21 @@
|
|||
|
||||
package database::firebird::mode::pages;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::values;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
my $maps_counters = {
|
||||
global => {
|
||||
'000_reads' => { set => {
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0, cb_prefix_output => 'prefix_output' }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'reads', set => {
|
||||
key_values => [ { name => 'reads', diff => 1 } ],
|
||||
per_second => 1,
|
||||
output_template => 'Reads : %.2f',
|
||||
|
@ -39,7 +44,7 @@ my $maps_counters = {
|
|||
],
|
||||
}
|
||||
},
|
||||
'001_writes' => { set => {
|
||||
{ label => 'writes', set => {
|
||||
key_values => [ { name => 'writes', diff => 1 } ],
|
||||
per_second => 1,
|
||||
output_template => 'Writes : %.2f',
|
||||
|
@ -49,7 +54,7 @@ my $maps_counters = {
|
|||
],
|
||||
}
|
||||
},
|
||||
'002_fetches' => { set => {
|
||||
{ label => 'fetches', set => {
|
||||
key_values => [ { name => 'fetches', diff => 1 } ],
|
||||
per_second => 1,
|
||||
output_template => 'Fetches : %.2f',
|
||||
|
@ -59,7 +64,7 @@ my $maps_counters = {
|
|||
],
|
||||
}
|
||||
},
|
||||
'003_statement' => { set => {
|
||||
{ label => 'statement', set => {
|
||||
key_values => [ { name => 'marks', diff => 1 } ],
|
||||
per_second => 1,
|
||||
output_template => 'Marks : %.2f',
|
||||
|
@ -69,120 +74,44 @@ my $maps_counters = {
|
|||
],
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
];
|
||||
}
|
||||
|
||||
sub prefix_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Page ";
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
});
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
|
||||
foreach my $key (('global')) {
|
||||
foreach (keys %{$maps_counters->{$key}}) {
|
||||
my ($id, $name) = split /_/;
|
||||
if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) {
|
||||
$options{options}->add_options(arguments => {
|
||||
'warning-' . $name . ':s' => { name => 'warning-' . $name },
|
||||
'critical-' . $name . ':s' => { name => 'critical-' . $name },
|
||||
});
|
||||
}
|
||||
$maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(statefile => $self->{statefile_value},
|
||||
output => $self->{output}, perfdata => $self->{perfdata},
|
||||
label => $name);
|
||||
$maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
foreach my $key (('global')) {
|
||||
foreach (keys %{$maps_counters->{$key}}) {
|
||||
$maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results});
|
||||
}
|
||||
}
|
||||
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{sql} = $options{sql};
|
||||
|
||||
$self->manage_selection();
|
||||
|
||||
$self->{new_datas} = {};
|
||||
$self->{statefile_value}->read(statefile => 'firebird_' . $self->{mode} . '_' . $self->{sql}->get_unique_id4save());
|
||||
$self->{new_datas}->{last_timestamp} = time();
|
||||
|
||||
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
|
||||
my @exits;
|
||||
|
||||
foreach (sort keys %{$maps_counters->{global}}) {
|
||||
my $obj = $maps_counters->{global}->{$_}->{obj};
|
||||
|
||||
$obj->set(instance => 'firebird');
|
||||
|
||||
my ($value_check) = $obj->execute(values => $self->{firebird},
|
||||
new_datas => $self->{new_datas});
|
||||
|
||||
if ($value_check != 0) {
|
||||
$long_msg .= $long_msg_append . $obj->output_error();
|
||||
$long_msg_append = ', ';
|
||||
next;
|
||||
}
|
||||
my $exit2 = $obj->threshold_check();
|
||||
push @exits, $exit2;
|
||||
|
||||
my $output = $obj->output();
|
||||
$long_msg .= $long_msg_append . $output;
|
||||
$long_msg_append = ', ';
|
||||
|
||||
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
|
||||
$short_msg .= $short_msg_append . $output;
|
||||
$short_msg_append = ', ';
|
||||
}
|
||||
|
||||
$obj->perfdata();
|
||||
}
|
||||
|
||||
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
|
||||
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => "Page $short_msg"
|
||||
);
|
||||
} else {
|
||||
$self->{output}->output_add(short_msg => "Page $long_msg");
|
||||
}
|
||||
|
||||
$self->{statefile_value}->write(data => $self->{new_datas});
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{sql}->connect();
|
||||
$self->{sql}->query(query => q{SELECT MON$PAGE_READS as PAGE_READS, MON$PAGE_WRITES as PAGE_WRITES, MON$PAGE_FETCHES as PAGE_FETCHES, MON$PAGE_MARKS as PAGE_MARKS FROM MON$IO_STATS mi WHERE mi.MON$STAT_GROUP = 0});
|
||||
$options{sql}->connect();
|
||||
$options{sql}->query(query => q{SELECT MON$PAGE_READS as PAGE_READS, MON$PAGE_WRITES as PAGE_WRITES, MON$PAGE_FETCHES as PAGE_FETCHES, MON$PAGE_MARKS as PAGE_MARKS FROM MON$IO_STATS mi WHERE mi.MON$STAT_GROUP = 0});
|
||||
my $row = $self->{sql}->fetchrow_hashref();
|
||||
if (!defined($row)) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot get page informations");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{firebird} = { reads => $row->{PAGE_READS}, writes => $row->{PAGE_WRITES},
|
||||
$self->{global} = { reads => $row->{PAGE_READS}, writes => $row->{PAGE_WRITES},
|
||||
fetches => $row->{PAGE_FETCHES}, marks => $row->{PAGE_MARKS} };
|
||||
|
||||
$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'));
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -20,16 +20,21 @@
|
|||
|
||||
package database::firebird::mode::queries;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::values;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
my $maps_counters = {
|
||||
global => {
|
||||
'000_total' => { set => {
|
||||
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 => {
|
||||
key_values => [ { name => 'total', diff => 1 } ],
|
||||
per_second => 1,
|
||||
output_template => 'Total : %d',
|
||||
|
@ -39,7 +44,7 @@ my $maps_counters = {
|
|||
],
|
||||
}
|
||||
},
|
||||
'001_seq-reads' => { set => {
|
||||
{ label => 'seq-reads', set => {
|
||||
key_values => [ { name => 'seq_reads', diff => 1 } ],
|
||||
per_second => 1,
|
||||
output_template => 'Seq Reads : %d',
|
||||
|
@ -49,7 +54,7 @@ my $maps_counters = {
|
|||
],
|
||||
}
|
||||
},
|
||||
'002_inserts' => { set => {
|
||||
{ label => 'inserts', set => {
|
||||
key_values => [ { name => 'inserts', diff => 1 } ],
|
||||
per_second => 1,
|
||||
output_template => 'Inserts : %d',
|
||||
|
@ -59,7 +64,7 @@ my $maps_counters = {
|
|||
],
|
||||
}
|
||||
},
|
||||
'003_updates' => { set => {
|
||||
{ label => 'updates', set => {
|
||||
key_values => [ { name => 'updates', diff => 1 } ],
|
||||
per_second => 1,
|
||||
output_template => 'Updates : %d',
|
||||
|
@ -69,8 +74,8 @@ my $maps_counters = {
|
|||
],
|
||||
}
|
||||
},
|
||||
'004_deletes' => { set => {
|
||||
key_values => [ { name => 'deletes', diff => 1 } ],
|
||||
{ label => 'deletes', set => {
|
||||
key_values => [ { name => 'deletes', diff => 1 } ],
|
||||
per_second => 1,
|
||||
output_template => 'Deletes : %d',
|
||||
perfdatas => [
|
||||
|
@ -79,7 +84,7 @@ my $maps_counters = {
|
|||
],
|
||||
}
|
||||
},
|
||||
'005_backouts' => { set => {
|
||||
{ label => 'backouts', set => {
|
||||
key_values => [ { name => 'backouts', diff => 1 } ],
|
||||
per_second => 1,
|
||||
output_template => 'Backouts : %d',
|
||||
|
@ -89,7 +94,7 @@ my $maps_counters = {
|
|||
],
|
||||
}
|
||||
},
|
||||
'006_purges' => { set => {
|
||||
{ label => 'purges', set => {
|
||||
key_values => [ { name => 'purges', diff => 1 } ],
|
||||
per_second => 1,
|
||||
output_template => 'Purges : %d',
|
||||
|
@ -99,7 +104,7 @@ my $maps_counters = {
|
|||
],
|
||||
}
|
||||
},
|
||||
'007_expunges' => { set => {
|
||||
{ label => 'expunges', set => {
|
||||
key_values => [ { name => 'expunges', diff => 1 } ],
|
||||
per_second => 1,
|
||||
output_template => 'Expunges : %d',
|
||||
|
@ -109,126 +114,50 @@ my $maps_counters = {
|
|||
],
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
];
|
||||
}
|
||||
|
||||
sub prefix_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Records ";
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
});
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
|
||||
foreach my $key (('global')) {
|
||||
foreach (keys %{$maps_counters->{$key}}) {
|
||||
my ($id, $name) = split /_/;
|
||||
if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) {
|
||||
$options{options}->add_options(arguments => {
|
||||
'warning-' . $name . ':s' => { name => 'warning-' . $name },
|
||||
'critical-' . $name . ':s' => { name => 'critical-' . $name },
|
||||
});
|
||||
}
|
||||
$maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(statefile => $self->{statefile_value},
|
||||
output => $self->{output}, perfdata => $self->{perfdata},
|
||||
label => $name);
|
||||
$maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
foreach my $key (('global')) {
|
||||
foreach (keys %{$maps_counters->{$key}}) {
|
||||
$maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results});
|
||||
}
|
||||
}
|
||||
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{sql} = $options{sql};
|
||||
|
||||
$self->manage_selection();
|
||||
|
||||
$self->{new_datas} = {};
|
||||
$self->{statefile_value}->read(statefile => 'firebird_' . $self->{mode} . '_' . $self->{sql}->get_unique_id4save());
|
||||
$self->{new_datas}->{last_timestamp} = time();
|
||||
|
||||
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
|
||||
my @exits;
|
||||
|
||||
foreach (sort keys %{$maps_counters->{global}}) {
|
||||
my $obj = $maps_counters->{global}->{$_}->{obj};
|
||||
|
||||
$obj->set(instance => 'firebird');
|
||||
|
||||
my ($value_check) = $obj->execute(values => $self->{firebird},
|
||||
new_datas => $self->{new_datas});
|
||||
|
||||
if ($value_check != 0) {
|
||||
$long_msg .= $long_msg_append . $obj->output_error();
|
||||
$long_msg_append = ', ';
|
||||
next;
|
||||
}
|
||||
my $exit2 = $obj->threshold_check();
|
||||
push @exits, $exit2;
|
||||
|
||||
my $output = $obj->output();
|
||||
$long_msg .= $long_msg_append . $output;
|
||||
$long_msg_append = ', ';
|
||||
|
||||
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
|
||||
$short_msg .= $short_msg_append . $output;
|
||||
$short_msg_append = ', ';
|
||||
}
|
||||
|
||||
$obj->perfdata();
|
||||
}
|
||||
|
||||
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
|
||||
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => "Records $short_msg"
|
||||
);
|
||||
} else {
|
||||
$self->{output}->output_add(short_msg => "Records $long_msg");
|
||||
}
|
||||
|
||||
$self->{statefile_value}->write(data => $self->{new_datas});
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{sql}->connect();
|
||||
$self->{sql}->query(query => q{SELECT MON$RECORD_SEQ_READS as MYREADS,MON$RECORD_INSERTS as MYINSERTS,
|
||||
$options{sql}->connect();
|
||||
$options{sql}->query(query => q{SELECT MON$RECORD_SEQ_READS as MYREADS,MON$RECORD_INSERTS as MYINSERTS,
|
||||
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'});
|
||||
my $row = $self->{sql}->fetchrow_hashref();
|
||||
my $row = $options{sql}->fetchrow_hashref();
|
||||
if (!defined($row)) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot get query informations");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{firebird} = { seq_reads => $row->{MYREADS}, inserts => $row->{MYINSERTS},
|
||||
$self->{global} = { seq_reads => $row->{MYREADS}, inserts => $row->{MYINSERTS},
|
||||
updates => $row->{MYUPDATES}, deletes => $row->{MYDELETES},
|
||||
backouts => $row->{MYBACKOUTS}, purges => $row->{MYPURGES}, expunges => $row->{MYEXPUNGES} };
|
||||
$self->{firebird}->{total} = $row->{MYREADS} + $row->{MYINSERTS} + $row->{MYUPDATES} +
|
||||
$self->{global}->{total} = $row->{MYREADS} + $row->{MYINSERTS} + $row->{MYUPDATES} +
|
||||
$row->{MYDELETES} + $row->{MYBACKOUTS} + $row->{MYPURGES} + $row->{MYEXPUNGES};
|
||||
|
||||
$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'));
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
Loading…
Reference in New Issue