enh(protocol/http): response mode - add extra time stats (#2847)

This commit is contained in:
qgarnier 2021-06-03 10:38:53 +02:00 committed by GitHub
parent ec0aa833fe
commit de5bcb13cd
4 changed files with 99 additions and 15 deletions

View File

@ -38,7 +38,7 @@ sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0 }
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }
];
$self->{maps_counters}->{global} = [
@ -55,7 +55,7 @@ sub set_counters {
},
{ label => 'time', nlabel => 'http.response.time.seconds', set => {
key_values => [ { name => 'time' } ],
output_template => 'Response time %.3fs',
output_template => 'response time %.3fs',
perfdatas => [
{ label => 'time', template => '%.3f', min => 0, unit => 's' }
]
@ -63,12 +63,52 @@ sub set_counters {
},
{ label => 'size', nlabel => 'http.response.size.count', display_ok => 0, set => {
key_values => [ { name => 'size' } ],
output_template => 'Content size : %s',
output_template => 'content size: %s',
perfdatas => [
{ label => 'size', template => '%s', min => 0, unit => 'B' }
]
}
}
},
{ label => 'resolve', nlabel => 'http.response.resolve.time.milliseconds', display_ok => 0, set => {
key_values => [ { name => 'resolve' } ],
output_template => 'resolve: %.3f ms',
perfdatas => [
{ label => 'resolve', template => '%.3f', min => 0, unit => 'ms' }
]
}
},
{ label => 'connect', nlabel => 'http.response.connect.time.milliseconds', display_ok => 0, set => {
key_values => [ { name => 'resolve' } ],
output_template => 'connect: %.3f ms',
perfdatas => [
{ label => 'connect', template => '%.3f', min => 0, unit => 'ms' }
]
}
},
{ label => 'tls', nlabel => 'http.response.tls.time.milliseconds', display_ok => 0, set => {
key_values => [ { name => 'tls' } ],
output_template => 'tls: %.3f ms',
perfdatas => [
{ label => 'tls', template => '%.3f', min => 0, unit => 'ms' }
]
}
},
{ label => 'processing', nlabel => 'http.response.processing.time.milliseconds', display_ok => 0, set => {
key_values => [ { name => 'processing' } ],
output_template => 'processing: %.3f ms',
perfdatas => [
{ label => 'processing', template => '%.3f', min => 0, unit => 'ms' }
]
}
},
{ label => 'transfer', nlabel => 'http.response.transfer.time.milliseconds', display_ok => 0, set => {
key_values => [ { name => 'resolve' } ],
output_template => 'transfer: %.3f ms',
perfdatas => [
{ label => 'transfer', template => '%.3f', min => 0, unit => 'ms' }
]
}
},
];
}
@ -95,12 +135,13 @@ sub new {
'cacert-file:s' => { name => 'cacert_file' },
'cert-pwd:s' => { name => 'cert_pwd' },
'cert-pkcs12' => { name => 'cert_pkcs12' },
'header:s@' => { name => 'header' },
'get-param:s@' => { name => 'get_param' },
'post-param:s@' => { name => 'post_param' },
'cookies-file:s' => { name => 'cookies_file' },
'warning:s' => { name => 'warning' },
'critical:s' => { name => 'critical' }
'header:s@' => { name => 'header' },
'get-param:s@' => { name => 'get_param' },
'post-param:s@' => { name => 'post_param' },
'cookies-file:s' => { name => 'cookies_file' },
'warning:s' => { name => 'warning' },
'critical:s' => { name => 'critical' },
'extra-stats' => { name => 'extra_stats' }
});
$self->{http} = centreon::plugins::http->new(%options);
@ -140,6 +181,11 @@ sub manage_selection {
$self->{global}->{size} = bytes::length($webcontent);
}
if (defined($self->{option_results}->{extra_stats})) {
my $times = $self->{http}->get_times();
$self->{global} = { %$times, %{$self->{global}} };
}
}
1;
@ -252,13 +298,15 @@ Threshold warning for http response code
Threshold critical for http response code (Default: '%{http_code} < 200 or %{http_code} >= 300')
=item B<--warning-time>
=item B<--extra-stats>
Threshold warning in seconds (Webpage response time)
Add detailed time statistics (only with curl backend).
=item B<--critical-time>
=item B<--warning-*> B<--critical-*>
Threshold critical in seconds (Webpage response time)
Thresholds. Can be:
'time', 'size',
'resolve', 'connect', 'tls', 'processing', 'transfer'.
=back

View File

@ -481,6 +481,30 @@ sub get_certificate {
return ('pem', $certs->[0]->{Cert});
}
sub get_times {
my ($self, %options) = @_;
# TIME_T = 7.61.0
my $resolve = $self->{curl_easy}->getinfo($self->{constant_cb}->(name => 'CURLINFO_NAMELOOKUP_TIME'));
my $connect = $self->{curl_easy}->getinfo($self->{constant_cb}->(name => 'CURLINFO_CONNECT_TIME'));
my $appconnect = $self->{curl_easy}->getinfo($self->{constant_cb}->(name => 'CURLINFO_APPCONNECT_TIME'));
my $start = $self->{curl_easy}->getinfo($self->{constant_cb}->(name => 'CURLINFO_STARTTRANSFER_TIME'));
my $total = $self->{curl_easy}->getinfo($self->{constant_cb}->(name => 'CURLINFO_TOTAL_TIME'));
my $times = {
resolve => $resolve * 1000,
connect => ($connect - $resolve) * 1000,
transfer => ($total - $start) * 1000
};
if ($appconnect > 0) {
$times->{tls} = ($appconnect - $connect) * 1000;
$times->{processing} = ($start - $appconnect) * 1000;
} else {
$times->{processing} = ($start - $connect) * 1000;
}
return $times;
}
1;
__END__

View File

@ -348,6 +348,12 @@ sub get_certificate {
return ('socket', $con);
}
sub get_time {
my ($self, %options) = @_;
return undef;
}
1;
__END__

View File

@ -34,7 +34,7 @@ sub new {
'proxyurl:s' => { name => 'proxyurl' },
'proxypac:s' => { name => 'proxypac' },
'insecure' => { name => 'insecure' },
'http-backend:s' => { name => 'http_backend', default => 'lwp' },
'http-backend:s' => { name => 'http_backend', default => 'lwp' }
});
$options{options}->add_help(package => __PACKAGE__, sections => 'HTTP GLOBAL OPTIONS');
}
@ -226,6 +226,12 @@ sub get_certificate {
return $self->{'backend_' . $self->{http_backend}}->get_certificate();
}
sub get_times {
my ($self, %options) = @_;
return $self->{'backend_' . $self->{http_backend}}->get_times();
}
1;
__END__