Merge pull request #818 from Sims24/oracle-enhan

Oracle enhancement
This commit is contained in:
qgarnier 2017-12-07 17:38:29 +01:00 committed by GitHub
commit b5047d9b39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 496 additions and 13 deletions

View File

@ -30,10 +30,22 @@ sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'event', type => 1, cb_prefix_output => 'prefix_event_output', message_multiple => 'All event waits are OK' },
{ name => 'event_count', type => 0 },
{ name => 'event', type => 1, cb_prefix_output => 'prefix_event_output', message_multiple => 'All event waits are OK', skipped_code => { 11 => -1 }},
];
$self->{maps_counters}->{event} = [
$self->{maps_counters}->{event_count} = [
{ label => 'event-count', set => {
key_values => [ { name => 'count' } ],
output_template => 'Event Wait Count : %d events' , output_use => 'count_absolute',
perfdatas => [
{ label => 'event_wait_count', value => 'count_absolute', template => '%d', min => 0 }
],
}
},
];
$self->{maps_counters}->{event} = [
{ label => 'total-waits-sec', set => {
key_values => [ { name => 'total_waits', diff => 1 }, { name => 'display' } ],
per_second => 1,
@ -55,7 +67,7 @@ sub set_counters {
],
}
},
];
],
}
sub custom_usage_calc {
@ -64,7 +76,18 @@ sub custom_usage_calc {
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
my $delta_total = $options{new_datas}->{$self->{instance} . '_time_waited_micro'} - $options{old_datas}->{$self->{instance} . '_time_waited_micro'};
$self->{result_values}->{prct_wait} = 100 * ($delta_total / 1000000) / $options{delta_time};
return 0;
}
sub custom_count_calc {
my ($self, %options) = @_;
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
my $delta_total = $options{new_datas}->{$self->{instance} . '_time_waited_micro'} - $options{old_datas}->{$self->{instance} . '_time_waited_micro'};
$self->{result_values}->{prct_wait} = 100 * ($delta_total / 1000000) / $options{delta_time};
return 0;
}
@ -77,6 +100,8 @@ sub new {
$options{options}->add_options(arguments =>
{
"filter-name:s" => { name => 'filter_name' },
"wait-time-min:s" => { name => 'wait_time_min', default => 1000 },
"show-details" => { name => 'show_details' }
});
return $self;
}
@ -93,20 +118,20 @@ sub manage_selection {
$self->{sql}->connect();
my $query = q{
SELECT e.event#, e.name,
SELECT e.event#, e.name,
NVL(s.total_waits, 0), NVL(s.total_timeouts, 0), NVL(s.time_waited, 0),
NVL(s.time_waited_micro, 0), NVL(s.average_wait, 0)
FROM v$event_name e LEFT JOIN sys.v_$system_event s ON e.name = s.event
};
};
if ($self->{sql}->is_version_minimum(version => '10')) {
$query = q{
SELECT e.event_id, e.name,
SELECT e.event_id, e.name,
NVL(s.total_waits, 0), NVL(s.total_timeouts, 0), NVL(s.time_waited, 0),
NVL(s.time_waited_micro, 0), NVL(s.average_wait, 0)
FROM v$event_name e LEFT JOIN sys.v_$system_event s ON e.name = s.event
};
}
$self->{sql}->query(query => $query);
my $result = $self->{sql}->fetchall_arrayref();
@ -126,15 +151,52 @@ sub manage_selection {
time_waited_micro => $time_waited_micro
};
}
my $query_count = "SELECT count(*) as NB
FROM v\$session
WHERE WAIT_TIME_MICRO>" . $self->{option_results}->{wait_time_min} . "
AND status='ACTIVE' and WAIT_CLASS <>'Idle'";
$self->{sql}->query(query => $query_count);
$result = $self->{sql}->fetchrow_hashref();
$self->{event_count}->{count} = $result->{NB};
if (defined($self->{option_results}->{show_details})) {
my $query_details = "SELECT
a.username USERNAME,
a.program PROGRAM,
a.event EVENT,
round(a.WAIT_TIME_MICRO/1000000,0) SEC_WAIT,
d.sql_text SQL_TEXT
FROM
v\$session a,
v\$sqlstats d
WHERE
a.sql_id = d.sql_id
and a.status='ACTIVE'
and a.wait_class <> 'Idle'
and WAIT_TIME_MICRO>" . $self->{option_results}->{wait_time_min} . "
and a.sid not in (SELECT SID FROM V\$SESSION WHERE audsid = userenv('SESSIONID'))
ORDER BY
a.WAIT_TIME_MICRO desc";
$self->{sql}->query(query => $query_details );
while (my $result = $self->{sql}->fetchrow_hashref()) {
$self->{output}->output_add(long_msg => sprintf("Username: '%s', Program: '%s' Event: '%s', Second wait: '%s's, Details: '%s'\n",
$result->{USERNAME}, $result->{PROGRAM}, $result->{EVENT}, $result->{SEC_WAIT}, $result->{SQL_TEXT}));
}
}
if (scalar(keys %{$self->{event}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No event found.");
$self->{output}->option_exit();
}
$self->{cache_name} = "oracle_" . $self->{mode} . '_' . $self->{sql}->get_unique_id4save() . '_' .
$self->{cache_name} = "oracle_" . $self->{mode} . '_' . $self->{sql}->get_unique_id4save() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
}
1;
@ -150,17 +212,25 @@ Check Oracle event wait usage.
=item B<--warning-*>
Threshold warning.
Can be: 'total-waits-sec', 'total-waits-time'.
Can be: 'total-waits-sec', 'total-waits-time', 'count'.
=item B<--critical-*>
Threshold critical.
Can be: 'total-waits-sec', 'total-waits-time'.
Can be: 'total-waits-sec', 'total-waits-time', 'count'.
=item B<--filter-name>
Filter by event name. Can be a regex.
=item B<--wait-time-min>
Time in ms above which we count an event as waiting
=item B<--show-details>
Print details of waiting events (user, query, ...) in long output
=back
=cut

View File

@ -0,0 +1,202 @@
#
# Copyright 2017 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::oracle::mode::temptablespace;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
my $instance_mode;
sub custom_usage_perfdata {
my ($self, %options) = @_;
my $label = 'used';
my $value_perf = $self->{result_values}->{used};
if (defined($instance_mode->{option_results}->{free})) {
$label = 'free';
$value_perf = $self->{result_values}->{free};
}
my %total_options = ();
if ($instance_mode->{option_results}->{units} eq '%') {
$total_options{total} = $self->{result_values}->{total};
$total_options{cast_int} = 1;
}
$self->{output}->perfdata_add(label => $label,
value => $value_perf, unit => 'B',
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
min => 0, max => $self->{result_values}->{total});
}
sub custom_usage_threshold {
my ($self, %options) = @_;
my ($exit, $threshold_value);
$threshold_value = $self->{result_values}->{used};
$threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free}));
if ($instance_mode->{option_results}->{units} eq '%') {
$threshold_value = $self->{result_values}->{prct_used};
$threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free}));
}
$exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
return $exit;
}
sub custom_usage_output {
my ($self, %options) = @_;
my $msg = sprintf("Total: %s%s Used: %s%s (%.2f%%) Free: %s%s (%.2f%%)",
$self->{perfdata}->change_bytes(value => $self->{result_values}->{total}),
$self->{perfdata}->change_bytes(value => $self->{result_values}->{used}), $self->{result_values}->{prct_used},
$self->{perfdata}->change_bytes(value => $self->{result_values}->{free}), $self->{result_values}->{prct_free});
return $msg;
}
sub custom_usage_calc {
my ($self, %options) = @_;
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'};
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
$self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
$self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'tmptablespace', type => 1, cb_prefix_output => 'prefix_tablespace_output', message_multiple => 'All temporary tablespaces are OK' },
];
$self->{maps_counters}->{tmptablespace} = [
{ label => 'usage', set => {
key_values => [ { name => 'used' }, { name => 'total' }, { name => 'display' } ],
closure_custom_calc => \&custom_usage_calc,
closure_custom_output => \&custom_usage_output,
closure_custom_perfdata => \&custom_usage_perfdata,
closure_custom_threshold_check => \&custom_usage_threshold,
}
},
];
}
sub prefix_tablespace_output {
my ($self, %options) = @_;
return "Temp Tablespace '" . $options{instance_value}->{display} . "' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 0);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"units:s" => { name => 'units', default => '%' },
"free" => { name => 'free' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$instance_mode = $self;
}
sub manage_selection {
my ($self, %options) = @_;
$self->{sql} = $options{sql};
$self->{sql}->connect();
my $query = q{
WITH
TMP as
(
SELECT
B.name,
C.block_size,
SUM (C.bytes) b_total
FROM
v$tablespace B join
v$tempfile C
using ( ts#)
GROUP BY
B.name, C.block_size
)
SELECT
A.tablespace_name tablespace, TMP.b_total,
SUM (A.used_blocks * TMP.block_size) b_used,
TMP.b_total - SUM (A.used_blocks * TMP.block_size) / 1024 b_free
FROM
v$sort_segment A join TMP on A.tablespace_name = TMP.name
GROUP by
A.tablespace_name, TMP.b_total
};
$self->{sql}->query(query => $query);
while (my $result = $self->{sql}->fetchrow_hashref()) {
$self->{tmptablespace}->{$result->{TABLESPACE}} = { used => $result->{B_USED}, total => $result->{B_TOTAL}, display => lc $result->{TABLESPACE} };
}
}
1;
__END__
=head1 MODE
Check Oracle TEMP tablespaces
=over 8
=item B<--units>
Unit of thresholds (Can be : '%' (default) or 'B')
=item B<--free>
Threshold are on free space left
=item B<--warning-usage>
Threshold warning.
=item B<--critical-usage>
Threshold critical.
=back
=cut

View File

@ -0,0 +1,209 @@
#
# Copyright 2017 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::oracle::mode::undotablespace;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
my $instance_mode;
sub custom_usage_perfdata {
my ($self, %options) = @_;
my $label = 'used';
my $value_perf = $self->{result_values}->{used};
if (defined($instance_mode->{option_results}->{free})) {
$label = 'free';
$value_perf = $self->{result_values}->{free};
}
my %total_options = ();
if ($instance_mode->{option_results}->{units} eq '%') {
$total_options{total} = $self->{result_values}->{total};
$total_options{cast_int} = 1;
}
$self->{output}->perfdata_add(label => $label,
value => $value_perf, unit => 'B',
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
min => 0, max => $self->{result_values}->{total});
}
sub custom_usage_threshold {
my ($self, %options) = @_;
my ($exit, $threshold_value);
$threshold_value = $self->{result_values}->{used};
$threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free}));
if ($instance_mode->{option_results}->{units} eq '%') {
$threshold_value = $self->{result_values}->{prct_used};
$threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free}));
}
$exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
return $exit;
}
sub custom_usage_output {
my ($self, %options) = @_;
my $msg = sprintf("Total: %s%s Used: %s%s (%.2f%%) Free: %s%s (%.2f%%)",
$self->{perfdata}->change_bytes(value => $self->{result_values}->{total}),
$self->{perfdata}->change_bytes(value => $self->{result_values}->{used}), $self->{result_values}->{prct_used},
$self->{perfdata}->change_bytes(value => $self->{result_values}->{free}), $self->{result_values}->{prct_free});
return $msg;
}
sub custom_usage_calc {
my ($self, %options) = @_;
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'};
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
$self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
$self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'undotablespace', type => 1, cb_prefix_output => 'prefix_tablespace_output', message_multiple => 'All undo tablespaces are OK' },
];
$self->{maps_counters}->{undotablespace} = [
{ label => 'usage', set => {
key_values => [ { name => 'used' }, { name => 'total' }, { name => 'display' } ],
closure_custom_calc => \&custom_usage_calc,
closure_custom_output => \&custom_usage_output,
closure_custom_perfdata => \&custom_usage_perfdata,
closure_custom_threshold_check => \&custom_usage_threshold,
}
},
];
}
sub prefix_tablespace_output {
my ($self, %options) = @_;
return "Undo Tablespace '" . $options{instance_value}->{display} . "' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 0);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"units:s" => { name => 'units', default => '%' },
"free" => { name => 'free' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$instance_mode = $self;
}
sub manage_selection {
my ($self, %options) = @_;
$self->{sql} = $options{sql};
$self->{sql}->connect();
my $query = q{
WITH
UND as
(
SELECT
a.tablespace_name,
nvl(sum(bytes),0) used_bytes
FROM
dba_undo_extents a
WHERE
tablespace_name in (select upper(value) from gv$parameter where name='undo_tablespace') and status in ('ACTIVE','UNEXPIRED')
group by a.tablespace_name
),
DF as
(
SELECT
b.tablespace_name,
round(SUM(decode(B.maxbytes, 0, B.BYTES/(1024*1024), B.maxbytes))) total_bytes
FROM
dba_data_files b
WHERE
tablespace_name in (select upper(value) from gv$parameter where name='undo_tablespace') group by b.tablespace_name
)
SELECT
UND.tablespace_name,
UND.used_bytes,
DF.total_bytes
FROM UND left outer join DF
on (UND.tablespace_name=DF.tablespace_name)
order by DF.tablespace_name
};
$self->{sql}->query(query => $query);
while (my $result = $self->{sql}->fetchrow_hashref()) {
$self->{undotablespace}->{$result->{TABLESPACE_NAME}} = { used => $result->{USED_BYTES}, total => $result->{TOTAL_BYTES}, display => lc $result->{TABLESPACE_NAME} };
}
}
1;
__END__
=head1 MODE
Check Oracle UNDO tablespaces
=over 8
=item B<--units>
Unit of threshold (Can be : '%' (default) or 'B')
=item B<--free>
Threshold are on free space left
=item B<--warning-usage>
Threshold warning.
=item B<--critical-usage>
Threshold critical.
=back
=cut

View File

@ -47,6 +47,8 @@ sub new {
'rman-online-backup-age' => 'database::oracle::mode::rmanonlinebackupage',
'rollback-segment-usage' => 'database::oracle::mode::rollbacksegmentusage',
'tablespace-usage' => 'database::oracle::mode::tablespaceusage',
'temp-usage' => 'database::oracle::mode::temptablespace',
'undo-usage' => 'database::oracle::mode::undotablespace',
'session-usage' => 'database::oracle::mode::sessionusage',
'sql' => 'centreon::common::protocols::sql::mode::sql',
'sql-string' => 'centreon::common::protocols::sql::mode::sqlstring',