Debian Codegraph @

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