| 1 |
# |
| 2 |
# Copyright 2024 Centreon (http://www.centreon.com/) |
| 3 |
# |
| 4 |
# Centreon is a full-fledged industry-strength solution that meets |
| 5 |
# the needs in IT infrastructure and application monitoring for |
| 6 |
# service performance. |
| 7 |
# |
| 8 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 |
# you may not use this file except in compliance with the License. |
| 10 |
# You may obtain a copy of the License at |
| 11 |
# |
| 12 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
# |
| 14 |
# Unless required by applicable law or agreed to in writing, software |
| 15 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
# See the License for the specific language governing permissions and |
| 18 |
# limitations under the License. |
| 19 |
# |
| 20 |
|
| 21 |
package database::sap::hana::mode::hostcpu; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use Digest::MD5 qw(md5_hex); |
| 28 |
|
| 29 |
sub set_counters { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
$self->{maps_counters_type} = [ |
| 33 |
{ name => 'cpu', type => 1, cb_prefix_output => 'prefix_cpu_output', message_multiple => 'All cpu usages are ok' }, |
| 34 |
]; |
| 35 |
$self->{maps_counters}->{cpu} = [ |
| 36 |
{ label => 'user', nlabel => 'host.cpu.user.utilization.percentage', set => { |
| 37 |
key_values => [ { name => 'total', diff => 1 }, { name => 'user', diff => 1 }, { name => 'display' } ], |
| 38 |
closure_custom_calc => $self->can('custom_data_calc'), closure_custom_calc_extra_options => { label_ref => 'user' }, |
| 39 |
output_template => 'User %.2f %%', output_use => 'user_prct', threshold_use => 'user_prct', |
| 40 |
perfdatas => [ |
| 41 |
{ label => 'user', value => 'user_prct', template => '%.2f', min => 0, max => 100, unit => '%', |
| 42 |
label_extra_instance => 1, instance_use => 'display' }, |
| 43 |
], |
| 44 |
} |
| 45 |
}, |
| 46 |
{ label => 'sys', nlabel => 'host.cpu.system.utilization.percentage', set => { |
| 47 |
key_values => [ { name => 'total', diff => 1 }, { name => 'sys', diff => 1 }, { name => 'display' } ], |
| 48 |
closure_custom_calc => $self->can('custom_data_calc'), closure_custom_calc_extra_options => { label_ref => 'sys' }, |
| 49 |
output_template => 'System %.2f %%', output_use => 'sys_prct', threshold_use => 'sys_prct', |
| 50 |
perfdatas => [ |
| 51 |
{ label => 'sys', value => 'sys_prct', template => '%.2f', min => 0, max => 100, unit => '%', |
| 52 |
label_extra_instance => 1, instance_use => 'display' }, |
| 53 |
], |
| 54 |
} |
| 55 |
}, |
| 56 |
{ label => 'wait', nlabel => 'host.cpu.wait.utilization.percentage', set => { |
| 57 |
key_values => [ { name => 'total', diff => 1 }, { name => 'wait', diff => 1 }, { name => 'display' } ], |
| 58 |
closure_custom_calc => $self->can('custom_data_calc'), closure_custom_calc_extra_options => { label_ref => 'wait' }, |
| 59 |
output_template => 'Wait %.2f %%', output_use => 'wait_prct', threshold_use => 'wait_prct', |
| 60 |
perfdatas => [ |
| 61 |
{ label => 'wait', value => 'wait_prct', template => '%.2f', min => 0, max => 100, unit => '%', |
| 62 |
label_extra_instance => 1, instance_use => 'display' }, |
| 63 |
], |
| 64 |
} |
| 65 |
}, |
| 66 |
{ label => 'idle', nlabel => 'host.cpu.idle.utilization.percentage', set => { |
| 67 |
key_values => [ { name => 'total', diff => 1 }, { name => 'idle', diff => 1 }, { name => 'display' } ], |
| 68 |
closure_custom_calc => $self->can('custom_data_calc'), closure_custom_calc_extra_options => { label_ref => 'idle' }, |
| 69 |
output_template => 'Idle %.2f %%', output_use => 'idle_prct', threshold_use => 'idle_prct', |
| 70 |
perfdatas => [ |
| 71 |
{ label => 'idle', value => 'idle_prct', template => '%.2f', min => 0, max => 100, unit => '%', |
| 72 |
label_extra_instance => 1, instance_use => 'display' }, |
| 73 |
], |
| 74 |
} |
| 75 |
}, |
| 76 |
]; |
| 77 |
} |
| 78 |
|
| 79 |
sub custom_data_calc { |
| 80 |
my ($self, %options) = @_; |
| 81 |
|
| 82 |
my $label = $options{extra_options}->{label_ref}; |
| 83 |
my $delta_value = $options{new_datas}->{$self->{instance} . '_' . $label} - $options{old_datas}->{$self->{instance} . '_' . $label}; |
| 84 |
my $delta_total = $options{new_datas}->{$self->{instance} . '_total'} - $options{old_datas}->{$self->{instance} . '_total'}; |
| 85 |
|
| 86 |
$self->{result_values}->{$label . '_prct'} = 0; |
| 87 |
if ($delta_total > 0) { |
| 88 |
$self->{result_values}->{$label . '_prct'} = $delta_value * 100 / $delta_total; |
| 89 |
} |
| 90 |
return 0; |
| 91 |
} |
| 92 |
|
| 93 |
sub prefix_cpu_output { |
| 94 |
my ($self, %options) = @_; |
| 95 |
|
| 96 |
return "CPU '" . $options{instance_value}->{display} . "' Usage : "; |
| 97 |
} |
| 98 |
|
| 99 |
sub new { |
| 100 |
my ($class, %options) = @_; |
| 101 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); |
| 102 |
bless $self, $class; |
| 103 |
|
| 104 |
$options{options}->add_options(arguments => {}); |
| 105 |
|
| 106 |
return $self; |
| 107 |
} |
| 108 |
|
| 109 |
sub manage_selection { |
| 110 |
my ($self, %options) = @_; |
| 111 |
$options{sql}->connect(); |
| 112 |
|
| 113 |
my $query = q{ |
| 114 |
SELECT * FROM SYS.M_HOST_RESOURCE_UTILIZATION |
| 115 |
}; |
| 116 |
$options{sql}->query(query => $query); |
| 117 |
|
| 118 |
$self->{cache_name} = "sap_hana_db_" . $self->{mode} . '_' . $options{sql}->get_unique_id4save() . '_' . |
| 119 |
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); |
| 120 |
|
| 121 |
$self->{cpu} = {}; |
| 122 |
while ((my $row = $options{sql}->fetchrow_hashref())) { |
| 123 |
my $name = $row->{HOST}; |
| 124 |
|
| 125 |
$self->{cpu}->{$name} = { |
| 126 |
display => $name, |
| 127 |
total => $row->{TOTAL_CPU_SYSTEM_TIME} + $row->{TOTAL_CPU_USER_TIME} + $row->{TOTAL_CPU_IDLE_TIME} + $row->{TOTAL_CPU_WIO_TIME}, |
| 128 |
sys => $row->{TOTAL_CPU_SYSTEM_TIME}, |
| 129 |
user => $row->{TOTAL_CPU_USER_TIME}, |
| 130 |
idle => $row->{TOTAL_CPU_IDLE_TIME}, |
| 131 |
wait => $row->{TOTAL_CPU_WIO_TIME}, |
| 132 |
}; |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
1; |
| 137 |
|
| 138 |
__END__ |
| 139 |
|
| 140 |
=head1 MODE |
| 141 |
|
| 142 |
Check system CPUs. |
| 143 |
|
| 144 |
=over 8 |
| 145 |
|
| 146 |
=item B<--filter-counters> |
| 147 |
|
| 148 |
Only display some counters (regexp can be used). |
| 149 |
Example : --filter-counters='^idle$' |
| 150 |
|
| 151 |
=item B<--warning-*> |
| 152 |
|
| 153 |
Warning threshold. |
| 154 |
Can be: 'user', 'sys', 'idle', 'wait'. |
| 155 |
|
| 156 |
=item B<--critical-*> |
| 157 |
|
| 158 |
Critical threshold. |
| 159 |
Can be: 'user', 'sys', 'idle', 'wait'. |
| 160 |
|
| 161 |
=back |
| 162 |
|
| 163 |
=cut |