From 3c9e89c2efe41704e71dec6b585e936d63c43d01 Mon Sep 17 00:00:00 2001 From: Simon Bomm Date: Thu, 7 Dec 2017 17:32:59 +0100 Subject: [PATCH] + add event count and event details --- database/oracle/mode/eventwaitsusage.pm | 96 +++++++++++++++++++++---- 1 file changed, 83 insertions(+), 13 deletions(-) diff --git a/database/oracle/mode/eventwaitsusage.pm b/database/oracle/mode/eventwaitsusage.pm index 9de9db890..6f312e169 100644 --- a/database/oracle/mode/eventwaitsusage.pm +++ b/database/oracle/mode/eventwaitsusage.pm @@ -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