Debian Codegraph @

src/cloud/azure/web/appserviceplan/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 cloud::azure::web::appserviceplan::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 'memorypercentage' => {
33 'output' => 'Memory Percentage',
34 'label' => 'memory-percentage',
35 'nlabel' => 'appserviceplan.memory.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 my $resource = $self->{option_results}->{resource};
68 my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : '';
69 if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Web\/serverFarms\/(.*)$/) {
70 $resource_group = $1;
71 $resource = $2;
72 }
73
74 $self->{az_resource} = $resource;
75 $self->{az_resource_group} = $resource_group;
76 $self->{az_resource_type} = 'serverFarms';
77 $self->{az_resource_namespace} = 'Microsoft.Web';
78 $self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900;
79 $self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M';
80 $self->{az_aggregations} = ['Average'];
81 if (defined($self->{option_results}->{aggregation})) {
82 $self->{az_aggregations} = [];
83 foreach my $stat (@{$self->{option_results}->{aggregation}}) {
84 if ($stat ne '') {
85 push @{$self->{az_aggregations}}, ucfirst(lc($stat));
86 }
87 }
88 }
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 Azure App Service Plan memory statistics.
104
105 Example:
106
107 Using resource name:
108
109 perl centreon_plugins.pl --plugin=cloud::azure::web::appserviceplan::plugin --mode=memory --custommode=api
110 --resource=<appsvcplan_id> --resource-group=<resourcegroup_id> --aggregation='average'
111 --warning-memory-percentage='80' --critical-memory-percentage='90'
112
113 Using resource ID:
114
115 perl centreon_plugins.pl --plugin=cloud::azure::web::appserviceplan::plugin --mode=memory --custommode=api
116 --resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.Web/serverFarms/<appsvcplan_id>'
117 --aggregation='average' --warning-memory-percentage='80' --critical-memory-percentage='90'
118
119 Default aggregation: 'average' / 'total', 'minimum' and 'maximum' are valid.
120
121 =over 8
122
123 =item B<--resource>
124
125 Set resource name or ID (required).
126
127 =item B<--resource-group>
128
129 Set resource group (required if resource's name is used).
130
131 =item B<--warning-memory-percentage>
132
133 Warning threshold.
134
135 =item B<--critical-memory-percentage>
136
137 Critical threshold.
138
139 =back
140
141 =cut