Debian Codegraph @

src/storage/fujitsu/eternus/dx/ssh/mode/cpu.pm

raw
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 storage::fujitsu::eternus::dx::ssh::mode::cpu;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::misc;
28
29 sub prefix_cpu_output {
30 my ($self, %options) = @_;
31
32 return "CPU '" . $options{instance_value}->{display} . "' ";
33 }
34
35 sub set_counters {
36 my ($self, %options) = @_;
37
38 $self->{maps_counters_type} = [
39 { name => 'cpu', type => 1, cb_prefix_output => 'prefix_cpu_output', message_multiple => 'All CPUs are ok' }
40 ];
41
42 $self->{maps_counters}->{cpu} = [
43 { label => 'usage', nlabel => 'cpu.utilization.percentage', set => {
44 key_values => [ { name => 'usage' }, { name => 'display' } ],
45 output_template => 'Usage : %d %%',
46 perfdatas => [
47 { label => 'cpu', template => '%d',
48 unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }
49 ]
50 }
51 }
52 ];
53 }
54
55 sub new {
56 my ($class, %options) = @_;
57 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
58 bless $self, $class;
59
60 $options{options}->add_options(arguments => {
61 'filter-name:s' => { name => 'filter_name' }
62 });
63
64 return $self;
65 }
66
67 sub manage_selection {
68 my ($self, %options) = @_;
69
70 my ($stdout) = $options{custom}->execute_command(
71 command => 'show',
72 command_options => "performance -type cm\n",
73 ssh_pipe => 1
74 );
75
76 # Can have 4 columns also.
77
78 #Location Busy Rate(%) Copy Residual Quantity(MB)
79 #--------------------- ------------ --------------------------
80 #CM#0 56 55191552
81 #CM#0 CPU Core#0 66 -
82 #CM#0 CPU Core#1 46 -
83 #CM#1 52 55191552
84 #CM#1 CPU Core#0 62 -
85 #CM#1 CPU Core#1 42 -
86
87 $self->{cpu} = {};
88 foreach (split /\n/, $stdout) {
89 next if ($_ !~ /^(CM.*?)\s{2,}(\d+)\s+\S+/);
90 my ($cpu_name, $cpu_value) = ($1, $2);
91
92 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
93 $cpu_name !~ /$self->{option_results}->{filter_name}/) {
94 $self->{output}->output_add(long_msg => "skipping '" . $cpu_name . "': no matching filter name.");
95 next;
96 }
97
98 $self->{cpu}->{$cpu_name} = { display => $cpu_name, usage => $cpu_value };
99 }
100
101 if (scalar(keys %{$self->{cpu}}) <= 0) {
102 $self->{output}->add_option_msg(short_msg => "No component found.");
103 $self->{output}->option_exit();
104 }
105 }
106
107 1;
108
109 __END__
110
111 =head1 MODE
112
113 Check CPUs usage.
114
115 Command used: show performance -type cm
116
117 =over 8
118
119 =item B<--filter-name>
120
121 Filter by name (regexp can be used).
122
123 =item B<--warning-usage>
124
125 Warning threshold (in percent).
126
127 =item B<--critical-usage>
128
129 Critical threshold (in percent).
130
131 =back
132
133 =cut