Debian Codegraph @

src/cloud/azure/common/appservice/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::common::appservice::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 'averagememoryworkingset' => {
33 'output' => 'Average memory working set',
34 'label' => 'app-average-memory',
35 'nlabel' => 'appservice.memory.average.usage.bytes',
36 'unit' => 'B',
37 'min' => '0',
38 'max' => '',
39 },
40 'memoryworkingset' => {
41 'output' => 'Memory working set',
42 'label' => 'app-memory',
43 'nlabel' => 'appservice.memory.usage.bytes',
44 'unit' => 'B',
45 'min' => '0',
46 'max' => '',
47 }
48 };
49
50 return $metrics_mapping;
51 }
52
53 sub new {
54 my ($class, %options) = @_;
55 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
56 bless $self, $class;
57
58 $options{options}->add_options(arguments => {
59 'filter-metric:s' => { name => 'filter_metric' },
60 'resource:s' => { name => 'resource' },
61 'resource-group:s' => { name => 'resource_group' }
62 });
63 return $self;
64 }
65
66 sub check_options {
67 my ($self, %options) = @_;
68 $self->SUPER::check_options(%options);
69
70 if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') {
71 $self->{output}->add_option_msg(short_msg => 'Need to specify either --resource <name> with --resource-group option or --resource <id>.');
72 $self->{output}->option_exit();
73 }
74 my $resource = $self->{option_results}->{resource};
75 my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : '';
76 if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Web\/sites\/(.*)$/) {
77 $resource_group = $1;
78 $resource = $2;
79 }
80
81 $self->{az_resource} = $resource;
82 $self->{az_resource_group} = $resource_group;
83 $self->{az_resource_type} = 'sites';
84 $self->{az_resource_namespace} = 'Microsoft.Web';
85 $self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900;
86 $self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M';
87 $self->{az_aggregations} = ['Average'];
88 if (defined($self->{option_results}->{aggregation})) {
89 $self->{az_aggregations} = [];
90 foreach my $stat (@{$self->{option_results}->{aggregation}}) {
91 if ($stat ne '') {
92 push @{$self->{az_aggregations}}, ucfirst(lc($stat));
93 }
94 }
95 }
96
97 foreach my $metric (keys %{$self->{metrics_mapping}}) {
98 next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne ''
99 && $metric !~ /$self->{option_results}->{filter_metric}/);
100 push @{$self->{az_metrics}}, $metric;
101 }
102 }
103
104 1;
105
106 __END__
107
108 =head1 MODE
109
110 Check Azure App Service app memory usage.
111
112 Example:
113
114 Using resource name:
115
116 perl centreon_plugins.pl --plugin=cloud::azure::common::appservice::plugin --mode=memory --custommode=api
117 --resource=<sites_id> --resource-group=<resourcegroup_id> --aggregation='average'
118 --warning-app-memory='80' --critical-app-memory='90'
119
120 Using resource ID:
121
122 perl centreon_plugins.pl --plugin=cloud::azure::common::appservice::plugin --mode=memory --custommode=api
123 --resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.Web/sites/<sites_id>'
124 --aggregation='average' --warning-app-memory='80' --critical-app-memory='90'
125
126 Default aggregation: 'average' / 'minimum', 'maximum' and 'total' are valid.
127
128 =over 8
129
130 =item B<--resource>
131
132 Set resource name or ID (required).
133
134 =item B<--resource-group>
135
136 Set resource group (required if resource's name is used).
137
138 =item B<--warning-*>
139
140 Warning threshold where '*' can be:
141 'app-average-memory', 'app-memory'.
142
143 =item B<--critical-*>
144
145 Critical threshold where '*' can be:.
146 'app-average-memory', 'app-memory'.
147
148 =back
149
150 =cut