Debian Codegraph @

src/storage/dell/powerstore/restapi/mode/memory.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::dell::powerstore::restapi::mode::memory;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub custom_usage_output {
29 my ($self, %options) = @_;
30
31 return sprintf(
32 'memory total: %s %s used: %s %s (%.2f%%) free: %s %s (%.2f%%)',
33 $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}),
34 $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}),
35 $self->{result_values}->{prct_used},
36 $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}),
37 $self->{result_values}->{prct_free}
38 );
39 }
40
41 sub prefix_appliance_output {
42 my ($self, %options) = @_;
43
44 return "Appliance '" . $options{instance} . "' ";
45 }
46
47 sub set_counters {
48 my ($self, %options) = @_;
49
50 $self->{maps_counters_type} = [
51 { name => 'memory', type => 1, cb_prefix_output => 'prefix_appliance_output', message_multiple => 'All appliances memory usage are ok' },
52 ];
53
54 $self->{maps_counters}->{memory} = [
55 { label => 'usage', nlabel => 'memory.usage.bytes', set => {
56 key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
57 closure_custom_output => $self->can('custom_usage_output'),
58 perfdatas => [
59 { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1 }
60 ]
61 }
62 },
63 { label => 'usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => {
64 key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
65 closure_custom_output => $self->can('custom_usage_output'),
66 perfdatas => [
67 { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1 }
68 ]
69 }
70 },
71 { label => 'usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => {
72 key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'prct_free' }, { name => 'total' } ],
73 closure_custom_output => $self->can('custom_usage_output'),
74 perfdatas => [
75 { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
76 ]
77 }
78 }
79 ];
80 }
81
82 sub new {
83 my ($class, %options) = @_;
84 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
85 bless $self, $class;
86
87 $options{options}->add_options(arguments => {
88 'filter-appliance-id:s' => { name => 'filter_appliance_id' }
89 });
90
91 return $self;
92 }
93
94 sub manage_selection {
95 my ($self, %options) = @_;
96
97 my $appliances = $options{custom}->get_space_metrics_by_appliance();
98
99 $self->{memory} = {};
100 foreach my $appliance_id (keys %$appliances) {
101 next if (defined($self->{option_results}->{filter_appliance_id}) && $self->{option_results}->{filter_appliance_id} ne '' &&
102 $appliance_id !~ /$self->{option_results}->{filter_appliance_id}/);
103
104 my $total = defined($appliances->{$appliance_id}->[-1]->{last_physical_total}) ? $appliances->{$appliance_id}->[-1]->{last_physical_total} : $appliances->{$appliance_id}->[-1]->{physical_total};
105 my $used = defined($appliances->{$appliance_id}->[-1]->{last_physical_used}) ? $appliances->{$appliance_id}->[-1]->{last_physical_used} : $appliances->{$appliance_id}->[-1]->{physical_used};
106 my $free = $total - $used;
107 $self->{memory}->{ $appliance_id } = {
108 total => $total,
109 used => $used,
110 free => $free,
111 prct_used => $used * 100 / $total,
112 prct_free => $free * 100 / $total
113 };
114 }
115 }
116
117 1;
118
119 __END__
120
121 =head1 MODE
122
123 Check appliances memory usage.
124
125 =over 8
126
127 =item B<--filter-appliance-id>
128
129 Filter appliance ID.
130
131 =item B<--warning-*> B<--critical-*>
132
133 Thresholds.
134 Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%).
135
136 =back
137
138 =cut