Debian Codegraph @

src/cloud/azure/compute/aks/mode/allocatableresources.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 cloud::azure::compute::aks::mode::allocatableresources;
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 'kube_node_status_allocatable_cpu_cores' => {
33 'output' => 'Allocatable CPU Cores',
34 'label' => 'allocatable-cpu-cores',
35 'nlabel' => 'aks.node.allocatable.cpu.cores',
36 'unit' => '',
37 'min' => '0',
38 },
39 'kube_node_status_allocatable_memory_bytes' => {
40 'output' => 'Allocatable Memory Bytes',
41 'label' => 'allocatable-memory-bytes',
42 'nlabel' => 'aks.node.allocatable.memory.bytes',
43 'unit' => 'B',
44 'min' => '0',
45 }
46 };
47
48 return $metrics_mapping;
49 }
50
51 sub new {
52 my ($class, %options) = @_;
53 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
54 bless $self, $class;
55
56 $options{options}->add_options(arguments => {
57 'filter-metric:s' => { name => 'filter_metric' },
58 'resource:s' => { name => 'resource' },
59 'resource-group:s' => { name => 'resource_group' }
60 });
61
62 return $self;
63 }
64
65 sub check_options {
66 my ($self, %options) = @_;
67 $self->SUPER::check_options(%options);
68
69 if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') {
70 $self->{output}->add_option_msg(short_msg => 'Need to specify either --resource <name> with --resource-group option or --resource <id>.');
71 $self->{output}->option_exit();
72 }
73
74 my $resource = $self->{option_results}->{resource};
75 my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : '';
76 my $resource_type = $self->{option_results}->{resource_type};
77 if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.ContainerService\/managedClusters\/(.*)$/) {
78 $resource_group = $1;
79 $resource = $2;
80 }
81
82 $self->{az_resource} = $resource;
83 $self->{az_resource_group} = $resource_group;
84 $self->{az_resource_type} = 'managedClusters';
85 $self->{az_resource_namespace} = 'Microsoft.ContainerService';
86 $self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900;
87 $self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M';
88 $self->{az_aggregations} = ['Average'];
89
90 foreach my $metric (keys %{$self->{metrics_mapping}}) {
91 next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne ''
92 && $metric !~ /$self->{option_results}->{filter_metric}/);
93 push @{$self->{az_metrics}}, $metric;
94 }
95 }
96
97 1;
98
99 __END__
100
101 =head1 MODE
102
103 Check remaining Azure Kubernetes Cluster Allocatable CPU Cores and Memory in Bytes.
104
105 Example:
106
107 Using resource name:
108
109 perl centreon_plugins.pl --plugin=cloud::azure::compute::aks::plugin --mode=allocatable-resources --custommode=api
110 --resource=<cluster_id> --resource-group=<resourcegroup_id> --warning-allocatable-memory-bytes=16GB: --critical-allocatable-memory-bytes=8GB:
111
112 Using resource ID:
113
114 perl centreon_plugins.pl --plugin=cloud::azure::compute::aks::plugin --mode=allocatable-resources --custommode=api
115 --resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.ContainerService/managedClusters/<cluster_id>'
116 --warning-allocatable-memory-bytes=16GB: --critical-allocatable-memory-bytes=8GB:
117
118 =over 8
119
120 =item B<--resource>
121
122 Set resource name or ID (required).
123
124 =item B<--resource-group>
125
126 Set resource group (required if resource's name is used).
127
128 =item B<--warning-allocatable-memory-bytes>
129
130 Set warning threshold for remaining allocatable memory in bytes.
131 It is a range, set 16GB: to get WARNING if there are less than 16GB allocatable left.
132
133 =item B<--critical-allocatable-memory-bytes>
134
135 Set critical threshold for remaining allocatable memory in bytes.
136 It is a range, set 8GB: to get CRITICAL if there are less than 8GB allocatable left.
137
138 =item B<--warning-allocatable-cpu-cores>
139
140 Set warning threshold for number of remaining allocatable CPU Cores.
141 It is a range, set 10: to get WARNING if there are less than 10 CPU cores allocatable remaining.
142
143 =item B<--critical-allocatable-cpu-cores>
144
145 Set critical threshold for number of remaining allocatable CPU Cores.
146 It is a range, set 5: to get CRITICAL if there are less than 5 CPU cores allocatable remaining.
147
148 =back
149
150 =cut