Debian Codegraph @

src/cloud/azure/management/applicationinsights/mode/requests.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::management::applicationinsights::mode::requests;
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 'requests/count' => {
33 'output' => 'Server requests',
34 'label' => 'requests-count',
35 'nlabel' => 'appinsights.requests.total.count',
36 'unit' => '',
37 'min' => '0',
38 'max' => ''
39 },
40 'requests/duration' => {
41 'output' => 'Server response time',
42 'label' => 'requests-duration',
43 'nlabel' => 'appinsights.requests.duration.milliseconds',
44 'unit' => 'ms',
45 'min' => '0',
46 'max' => ''
47 },
48 'requests/failed' => {
49 'output' => 'Failed requests',
50 'label' => 'requests-failed',
51 'nlabel' => 'appinsights.requests.failed.count',
52 'unit' => '',
53 'min' => '0',
54 'max' => ''
55 },
56 'requests/rate' => {
57 'output' => 'Server request rate',
58 'label' => 'requests-rate',
59 'nlabel' => 'appinsights.requests.perseconds',
60 'unit' => 'requests/s',
61 'min' => '0',
62 'max' => ''
63 },
64 'performancecounters/requestexecutiontime' => {
65 'output' => 'HTTP request execution time',
66 'label' => 'requests-execution-time',
67 'nlabel' => 'appinsights.requests.execution.time.milliseconds',
68 'unit' => 'ms',
69 'min' => '0',
70 'max' => ''
71 },
72 'performancecounters/requestsinqueue' => {
73 'output' => 'HTTP requests in application queue',
74 'label' => 'requests-queued',
75 'nlabel' => 'appinsights.requests.failed.count',
76 'unit' => '',
77 'min' => '0',
78 'max' => ''
79 },
80 'performancecounters/requestspersecond' => {
81 'output' => 'HTTP request rate',
82 'label' => 'requests-http-rate',
83 'nlabel' => 'appinsights.requests.http.perseconds',
84 'unit' => 'requests/s',
85 'min' => '0',
86 'max' => ''
87 }
88 };
89
90 return $metrics_mapping;
91 }
92
93 sub new {
94 my ($class, %options) = @_;
95 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
96 bless $self, $class;
97
98 $options{options}->add_options(arguments => {
99 'filter-metric:s' => { name => 'filter_metric' },
100 'resource:s' => { name => 'resource' },
101 'resource-group:s' => { name => 'resource_group' }
102 });
103
104 return $self;
105 }
106
107 sub check_options {
108 my ($self, %options) = @_;
109 $self->SUPER::check_options(%options);
110
111 if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') {
112 $self->{output}->add_option_msg(short_msg => 'Need to specify either --resource <name> with --resource-group option or --resource <id>.');
113 $self->{output}->option_exit();
114 }
115 my $resource = $self->{option_results}->{resource};
116 my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : '';
117 if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Insights\/components\/(.*)$/) {
118 $resource_group = $1;
119 $resource = $2;
120 }
121
122 $self->{az_resource} = $resource;
123 $self->{az_resource_group} = $resource_group;
124 $self->{az_resource_type} = 'Components';
125 $self->{az_resource_namespace} = 'Microsoft.Insights';
126 $self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900;
127 $self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M';
128 $self->{az_aggregations} = ['Total'];
129 if (defined($self->{option_results}->{aggregation})) {
130 $self->{az_aggregations} = [];
131 foreach my $stat (@{$self->{option_results}->{aggregation}}) {
132 if ($stat ne '') {
133 push @{$self->{az_aggregations}}, ucfirst(lc($stat));
134 }
135 }
136 }
137
138 foreach my $metric (keys %{$self->{metrics_mapping}}) {
139 next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne ''
140 && $metric !~ /$self->{option_results}->{filter_metric}/);
141 push @{$self->{az_metrics}}, $metric;
142 }
143 }
144
145 1;
146
147 __END__
148
149 =head1 MODE
150
151 Check Azure Application Insights HTTP request statistics.
152
153 Example:
154
155 Using resource name:
156
157 perl centreon_plugins.pl --plugin=cloud::azure::management::applicationinsights::plugin --mode=http-requests --custommode=api
158 --resource=<component_id> --resource-group=<resourcegroup_id> --aggregation='total'
159 --warning-requests-count='800' --critical-requests-count='900'
160
161 Using resource ID:
162
163 perl centreon_plugins.pl --plugin=cloud::azure::integration::servicebus::plugin --mode=http-requests --custommode=api
164 --resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.Insights/Components/<component_id>'
165 --aggregation='total' --warning-requests-count='800' --critical-requests-count='900'
166
167 Default aggregation: 'total' / 'average', 'minimum' and 'maximum' are valid.
168
169 =over 8
170
171 =item B<--resource>
172
173 Set resource name or ID (required).
174
175 =item B<--resource-group>
176
177 Set resource group (required if resource's name is used).
178
179 =item B<--warning-*>
180
181 Warning threshold where '*' can be:
182 'requests-count', 'requests-duration', 'requests-failed', 'requests-rate',
183 'requests-execution-time', 'requests-queued', 'requests-http-rate'.
184
185 =item B<--critical-*>
186
187 Critical threshold where '*' can be:
188 'requests-count', 'requests-duration', 'requests-failed', 'requests-rate',
189 'requests-execution-time', 'requests-queued', 'requests-http-rate'.
190
191 =back
192
193 =cut