Debian Codegraph @

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