Debian Codegraph @

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