Debian Codegraph @

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