| 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::dell::powerstore::restapi::mode::clusters; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub cluster_long_output { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
return sprintf( |
| 32 |
"checking cluster '%s'", |
| 33 |
$options{instance} |
| 34 |
); |
| 35 |
} |
| 36 |
|
| 37 |
sub prefix_cluster_output { |
| 38 |
my ($self, %options) = @_; |
| 39 |
|
| 40 |
return sprintf( |
| 41 |
"cluster '%s' ", |
| 42 |
$options{instance} |
| 43 |
); |
| 44 |
} |
| 45 |
|
| 46 |
sub prefix_global_output { |
| 47 |
my ($self, %options) = @_; |
| 48 |
|
| 49 |
return 'Number of clusters '; |
| 50 |
} |
| 51 |
|
| 52 |
sub prefix_read_latency_output { |
| 53 |
my ($self, %options) = @_; |
| 54 |
|
| 55 |
return 'read latency '; |
| 56 |
} |
| 57 |
|
| 58 |
sub prefix_write_latency_output { |
| 59 |
my ($self, %options) = @_; |
| 60 |
|
| 61 |
return 'write latency '; |
| 62 |
} |
| 63 |
|
| 64 |
sub prefix_read_iops_output { |
| 65 |
my ($self, %options) = @_; |
| 66 |
|
| 67 |
return 'read iops '; |
| 68 |
} |
| 69 |
|
| 70 |
sub prefix_write_iops_output { |
| 71 |
my ($self, %options) = @_; |
| 72 |
|
| 73 |
return 'write iops '; |
| 74 |
} |
| 75 |
|
| 76 |
sub prefix_read_bandwidth_output { |
| 77 |
my ($self, %options) = @_; |
| 78 |
|
| 79 |
return 'read bandwidth '; |
| 80 |
} |
| 81 |
|
| 82 |
sub prefix_write_bandwidth_output { |
| 83 |
my ($self, %options) = @_; |
| 84 |
|
| 85 |
return 'write bandwidth '; |
| 86 |
} |
| 87 |
|
| 88 |
sub set_counters { |
| 89 |
my ($self, %options) = @_; |
| 90 |
|
| 91 |
$self->{maps_counters_type} = [ |
| 92 |
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }, |
| 93 |
{ |
| 94 |
name => 'clusters', type => 3, cb_prefix_output => 'prefix_cluster_output', cb_long_output => 'cluster_long_output', indent_long_output => ' ', message_multiple => 'All clusters are ok', |
| 95 |
group => [ |
| 96 |
{ name => 'read_latency', type => 0, cb_prefix_output => 'prefix_read_latency_output' }, |
| 97 |
{ name => 'write_latency', type => 0, cb_prefix_output => 'prefix_write_latency_output' }, |
| 98 |
{ name => 'read_iops', type => 0, cb_prefix_output => 'prefix_read_iops_output' }, |
| 99 |
{ name => 'write_iops', type => 0, cb_prefix_output => 'prefix_write_iops_output' }, |
| 100 |
{ name => 'read_bandwidth', type => 0, cb_prefix_output => 'prefix_read_bandwidth_output' }, |
| 101 |
{ name => 'write_bandwidth', type => 0, cb_prefix_output => 'prefix_write_bandwidth_output' } |
| 102 |
] |
| 103 |
} |
| 104 |
]; |
| 105 |
|
| 106 |
$self->{maps_counters}->{global} = [ |
| 107 |
{ label => 'clusters-detected', display_ok => 0, nlabel => 'clusters.detected.count', set => { |
| 108 |
key_values => [ { name => 'detected' } ], |
| 109 |
output_template => 'detected: %s', |
| 110 |
perfdatas => [ |
| 111 |
{ template => '%s', min => 0 } |
| 112 |
] |
| 113 |
} |
| 114 |
} |
| 115 |
]; |
| 116 |
|
| 117 |
foreach ('read', 'write') { |
| 118 |
$self->{maps_counters}->{$_ . '_latency'} = []; |
| 119 |
foreach my $sampling ('5m', '30m', '1h', '24h') { |
| 120 |
push @{$self->{maps_counters}->{$_ . '_latency'}}, { |
| 121 |
label => $_ . '-latency-' . $sampling, nlabel => 'cluster.io.'. $_ . '.latency.' . $sampling . '.milliseconds', set => { |
| 122 |
key_values => [ { name => $sampling } ], |
| 123 |
output_template => '%.3f ms (' . $sampling . ')', |
| 124 |
perfdatas => [ |
| 125 |
{ template => '%.3f', unit => 'ms', min => 0, label_extra_instance => 1 } |
| 126 |
] |
| 127 |
} |
| 128 |
}; |
| 129 |
} |
| 130 |
|
| 131 |
foreach my $sampling ('5m', '30m', '1h', '24h') { |
| 132 |
push @{$self->{maps_counters}->{$_ . '_iops'}}, { |
| 133 |
label => $_ . '-iops-' . $sampling, nlabel => 'cluster.io.'. $_ . '.' . $sampling . '.iops', set => { |
| 134 |
key_values => [ { name => $sampling } ], |
| 135 |
output_template => '%d (' . $sampling . ')', |
| 136 |
perfdatas => [ |
| 137 |
{ template => '%d', unit => 'iops', min => 0, label_extra_instance => 1 } |
| 138 |
] |
| 139 |
} |
| 140 |
}; |
| 141 |
} |
| 142 |
|
| 143 |
foreach my $sampling ('5m', '30m', '1h', '24h') { |
| 144 |
push @{$self->{maps_counters}->{$_ . '_bandwidth'}}, { |
| 145 |
label => $_ . '-bandwidth-' . $sampling, nlabel => 'cluster.io.'. $_ . '.bandwidth.' . $sampling . '.bytespersecond', set => { |
| 146 |
key_values => [ { name => $sampling } ], |
| 147 |
output_template => '%.2f%s/s (' . $sampling . ')', |
| 148 |
output_change_bytes => 1, |
| 149 |
perfdatas => [ |
| 150 |
{ template => '%.2f', unit => 'B/s', min => 0, label_extra_instance => 1 } |
| 151 |
] |
| 152 |
} |
| 153 |
}; |
| 154 |
} |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
sub new { |
| 159 |
my ($class, %options) = @_; |
| 160 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 161 |
bless $self, $class; |
| 162 |
|
| 163 |
$options{options}->add_options(arguments => { |
| 164 |
'filter-id:s' => { name => 'filter_id' } |
| 165 |
}); |
| 166 |
|
| 167 |
return $self; |
| 168 |
} |
| 169 |
|
| 170 |
sub manage_selection { |
| 171 |
my ($self, %options) = @_; |
| 172 |
|
| 173 |
my $clusters = $options{custom}->get_performance_metrics_by_clusters(); |
| 174 |
|
| 175 |
$self->{global} = { detected => 0 }; |
| 176 |
$self->{clusters} = {}; |
| 177 |
|
| 178 |
foreach my $cluster_id (keys %$clusters) { |
| 179 |
next if (defined($self->{option_results}->{filter_id}) && $self->{option_results}->{filter_id} ne '' && |
| 180 |
$cluster_id !~ /$self->{option_results}->{filter_id}/); |
| 181 |
|
| 182 |
$self->{global}->{detected}++; |
| 183 |
|
| 184 |
$self->{clusters}->{ $cluster_id } = { |
| 185 |
latency => {}, |
| 186 |
iops => {}, |
| 187 |
bandwidth => {} |
| 188 |
}; |
| 189 |
|
| 190 |
foreach my $sampling ('5m', '30m', '1h', '24h') { |
| 191 |
foreach my $metric ('read_latency', 'write_latency', 'read_iops', 'write_iops', 'read_bandwidth', 'write_bandwidth') { |
| 192 |
$self->{clusters}->{ $cluster_id }->{$metric}->{$sampling} = 0; |
| 193 |
$self->{clusters}->{ $cluster_id }->{$metric}->{'num_' . $sampling} = 0; |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
my $i = 0; |
| 198 |
while (my $entry = pop(@{$clusters->{$cluster_id}})) { |
| 199 |
foreach ('latency', 'iops', 'bandwidth') { |
| 200 |
if ($i == 0) { |
| 201 |
$self->{clusters}->{ $cluster_id }->{'read_' . $_}->{'5m'} += $entry->{'avg_read_' . $_}; |
| 202 |
$self->{clusters}->{ $cluster_id }->{'write_' . $_}->{'5m'} += $entry->{'avg_write_' . $_}; |
| 203 |
} |
| 204 |
if ($i < 5) { |
| 205 |
$self->{clusters}->{ $cluster_id }->{'read_' . $_}->{'30m'} += $entry->{'avg_read_' . $_}; |
| 206 |
$self->{clusters}->{ $cluster_id }->{'write_' . $_}->{'30m'} += $entry->{'avg_write_' . $_}; |
| 207 |
$self->{clusters}->{ $cluster_id }->{'read_' . $_}->{num_30m}++; |
| 208 |
$self->{clusters}->{ $cluster_id }->{'write_' . $_}->{num_30m}++; |
| 209 |
} |
| 210 |
if ($i < 10) { |
| 211 |
$self->{clusters}->{ $cluster_id }->{'read_' . $_}->{'1h'} += $entry->{'avg_read_' . $_}; |
| 212 |
$self->{clusters}->{ $cluster_id }->{'write_' . $_}->{'1h'} += $entry->{'avg_write_' . $_}; |
| 213 |
$self->{clusters}->{ $cluster_id }->{'read_' . $_}->{num_1h}++; |
| 214 |
$self->{clusters}->{ $cluster_id }->{'write_' . $_}->{num_1h}++; |
| 215 |
} |
| 216 |
$self->{clusters}->{ $cluster_id }->{'read_' . $_}->{'24h'} += $entry->{'avg_read_' . $_}; |
| 217 |
$self->{clusters}->{ $cluster_id }->{'write_' . $_}->{'24h'} += $entry->{'avg_write_' . $_}; |
| 218 |
$self->{clusters}->{ $cluster_id }->{'read_' . $_}->{num_24h}++; |
| 219 |
$self->{clusters}->{ $cluster_id }->{'write_' . $_}->{num_24h}++; |
| 220 |
} |
| 221 |
|
| 222 |
$i++; |
| 223 |
} |
| 224 |
|
| 225 |
foreach ('latency', 'iops', 'bandwidth') { |
| 226 |
if ($_ eq 'latency') { |
| 227 |
$self->{clusters}->{ $cluster_id }->{'read_' . $_}->{'5m'} = $self->{clusters}->{ $cluster_id }->{'read_' . $_}->{'5m'} / 1000; |
| 228 |
$self->{clusters}->{ $cluster_id }->{'write_' . $_}->{'5m'} = $self->{clusters}->{ $cluster_id }->{'write_' . $_}->{'5m'} / 1000; |
| 229 |
$self->{clusters}->{ $cluster_id }->{'read_' . $_}->{'30m'} = |
| 230 |
$self->{clusters}->{ $cluster_id }->{'read_' . $_}->{'30m'} / $self->{clusters}->{ $cluster_id }->{'read_' . $_}->{num_30m} / 1000; |
| 231 |
$self->{clusters}->{ $cluster_id }->{'write_' . $_}->{'30m'} = |
| 232 |
$self->{clusters}->{ $cluster_id }->{'write_' . $_}->{'30m'} / $self->{clusters}->{ $cluster_id }->{'write_' . $_}->{num_30m} / 1000; |
| 233 |
$self->{clusters}->{ $cluster_id }->{'read_' . $_}->{'1h'} = |
| 234 |
$self->{clusters}->{ $cluster_id }->{'read_' . $_}->{'1h'} / $self->{clusters}->{ $cluster_id }->{'read_' . $_}->{num_1h} / 1000; |
| 235 |
$self->{clusters}->{ $cluster_id }->{'write_' . $_}->{'1h'} = |
| 236 |
$self->{clusters}->{ $cluster_id }->{'write_' . $_}->{'1h'} / $self->{clusters}->{ $cluster_id }->{'write_' . $_}->{num_1h} / 1000; |
| 237 |
$self->{clusters}->{ $cluster_id }->{'read_' . $_}->{'24h'} = |
| 238 |
$self->{clusters}->{ $cluster_id }->{'read_' . $_}->{'24h'} / $self->{clusters}->{ $cluster_id }->{'read_' . $_}->{num_24h} / 1000; |
| 239 |
$self->{clusters}->{ $cluster_id }->{'write_' . $_}->{'24h'} = |
| 240 |
$self->{clusters}->{ $cluster_id }->{'write_' . $_}->{'24h'} / $self->{clusters}->{ $cluster_id }->{'write_' . $_}->{num_24h} / 1000; |
| 241 |
} else { |
| 242 |
$self->{clusters}->{ $cluster_id }->{'read_' . $_}->{'30m'} /= $self->{clusters}->{ $cluster_id }->{'read_' . $_}->{num_30m}; |
| 243 |
$self->{clusters}->{ $cluster_id }->{'write_' . $_}->{'30m'} /= $self->{clusters}->{ $cluster_id }->{'write_' . $_}->{num_30m}; |
| 244 |
$self->{clusters}->{ $cluster_id }->{'read_' . $_}->{'1h'} /= $self->{clusters}->{ $cluster_id }->{'read_' . $_}->{num_1h}; |
| 245 |
$self->{clusters}->{ $cluster_id }->{'write_' . $_}->{'1h'} /= $self->{clusters}->{ $cluster_id }->{'write_' . $_}->{num_1h}; |
| 246 |
$self->{clusters}->{ $cluster_id }->{'read_' . $_}->{'24h'} /= $self->{clusters}->{ $cluster_id }->{'read_' . $_}->{num_24h}; |
| 247 |
$self->{clusters}->{ $cluster_id }->{'write_' . $_}->{'24h'} /= $self->{clusters}->{ $cluster_id }->{'write_' . $_}->{num_24h}; |
| 248 |
} |
| 249 |
} |
| 250 |
} |
| 251 |
} |
| 252 |
|
| 253 |
1; |
| 254 |
|
| 255 |
__END__ |
| 256 |
|
| 257 |
=head1 MODE |
| 258 |
|
| 259 |
Check clusters. |
| 260 |
|
| 261 |
=over 8 |
| 262 |
|
| 263 |
=item B<--filter-id> |
| 264 |
|
| 265 |
Filter clusters by id. |
| 266 |
|
| 267 |
=item B<--warning-*> B<--critical-*> |
| 268 |
|
| 269 |
Thresholds. |
| 270 |
Can be: 'clusters-detected', |
| 271 |
'read-iops-5m', 'read-iops-30m', 'read-iops-1h', 'read-iops-24h', |
| 272 |
'write-iops-5m', 'write-iops-30m', 'write-iops-1h', 'write-iops-24h', |
| 273 |
'read-latency-5m', 'read-latency-30m', 'read-latency-1h', 'read-latency-24h', |
| 274 |
'write-latency-5m', 'write-latency-30m', 'write-latency-1h', 'write-latency-24h', |
| 275 |
'read-bandwidth-5m', 'read-bandwidth-30m', 'read-bandwidth-1h', 'read-bandwidth-24h', |
| 276 |
'write-bandwidth-5m', 'write-bandwidth-30m', 'write-bandwidth-1h', 'write-bandwidth-24h'. |
| 277 |
|
| 278 |
=back |
| 279 |
|
| 280 |
=cut |