Debian Codegraph @

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