Debian Codegraph @

src/cloud/azure/compute/aks/mode/memory.pm

raw
1 #
2 # Copyright 2022 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 cloud::azure::compute::aks::mode::memory;
22
23 use base qw(cloud::azure::custom::mode);
24
25 use strict;
26 use warnings;
27
28 sub get_metrics_mapping {
29 my ($self, %options) = @_;
30
31 my $metrics_mapping = {
32 'node_memory_rss_bytes' => {
33 'output' => 'memory RSS Usage',
34 'label' => 'memory-rss-usage',
35 'nlabel' => 'aks.node.memory.rss.bytes',
36 'unit' => 'B',
37 'min' => '0'
38 },
39 'node_memory_rss_percentage' => {
40 'output' => 'Memory RSS Percent',
41 'label' => 'memory-rss-percent',
42 'nlabel' => 'aks.node.memory.rss.percentage',
43 'unit' => '%',
44 'min' => '0',
45 'max' => '100'
46 },
47 'node_memory_working_set_bytes' => {
48 'output' => 'memory Usage',
49 'label' => 'memory-usage',
50 'nlabel' => 'aks.node.memory.working.set.bytes',
51 'unit' => 'B',
52 'min' => '0'
53 },
54 'node_memory_working_set_percentage' => {
55 'output' => 'Memory Percent',
56 'label' => 'memory-percent',
57 'nlabel' => 'aks.node.memory.working.set.percentage',
58 'unit' => '%',
59 'min' => '0',
60 'max' => '100'
61 }
62
63 };
64
65 return $metrics_mapping;
66 }
67
68 sub new {
69 my ($class, %options) = @_;
70 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
71 bless $self, $class;
72
73 $options{options}->add_options(arguments => {
74 'filter-metric:s' => { name => 'filter_metric' },
75 'resource:s' => { name => 'resource' },
76 'resource-group:s' => { name => 'resource_group' }
77 });
78
79 return $self;
80 }
81
82 sub check_options {
83 my ($self, %options) = @_;
84 $self->SUPER::check_options(%options);
85
86 if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') {
87 $self->{output}->add_option_msg(short_msg => 'Need to specify either --resource <name> with --resource-group option or --resource <id>.');
88 $self->{output}->option_exit();
89 }
90
91 my $resource = $self->{option_results}->{resource};
92 my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : '';
93 my $resource_type = $self->{option_results}->{resource_type};
94 if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.ContainerService\/managedClusters\/(.*)$/) {
95 $resource_group = $1;
96 $resource = $2;
97 }
98
99 $self->{az_resource} = $resource;
100 $self->{az_resource_group} = $resource_group;
101 $self->{az_resource_type} = 'managedClusters';
102 $self->{az_resource_namespace} = 'Microsoft.ContainerService';
103 $self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900;
104 $self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M';
105 $self->{az_aggregations} = ['Average'];
106
107 foreach my $metric (keys %{$self->{metrics_mapping}}) {
108 next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne ''
109 && $metric !~ /$self->{option_results}->{filter_metric}/);
110 push @{$self->{az_metrics}}, $metric;
111 }
112 }
113
114 1;
115
116 __END__
117
118 =head1 MODE
119
120 Check Memory usage on Azure Kubernetes Cluster.
121
122 Example:
123
124 Using resource name:
125
126 perl centreon_plugins.pl --plugin=cloud::azure::compute::aks::plugin --mode=memory --custommode=api
127 --resource=<cluster_id> --resource-group=<resourcegroup_id> --warning-memory-percent='90' --critical-memory-percent='95'
128
129 Using resource ID:
130
131 perl centreon_plugins.pl --plugin=cloud::azure::compute::aks::plugin --mode=storage --custommode=api
132 --resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.ContainerService/managedClusters/<cluster_id>'
133 --warning-memory-percent='90' --critical-memory-percent='95'
134
135 =over 8
136
137 =item B<--resource>
138
139 Set resource name or ID (required).
140
141 =item B<--resource-group>
142
143 Set resource group (required if resource's name is used).
144
145 =item B<--warning-memory-usage>
146
147 Warning threshold in Bytes.
148
149 =item B<--critical-memory-usage>
150
151 Critical threshold in Bytes.
152
153 =item B<--warning-memory-percent>
154
155 Warning threshold in percent.
156
157 =item B<--critical-memory-percent>
158
159 Critical threshold in percent.
160
161 =item B<--warning-rss-memory-usage>
162
163 Warning threshold in Bytes.
164
165 =item B<--critical-rss-memory-usage>
166
167 Critical threshold in Bytes.
168
169 =item B<--warning-rss-memory-percent>
170
171 Warning threshold in percent.
172
173 =item B<--critical-rss-memory-percent>
174
175 Critical threshold in percent.
176
177 =back
178
179 =cut