mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-30 00:55:18 +02:00
enh(protocol/http): response mode - add extra time stats (#2847)
This commit is contained in:
parent
a35bd671db
commit
b4c1d5f900
@ -38,7 +38,7 @@ sub set_counters {
|
|||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{maps_counters_type} = [
|
$self->{maps_counters_type} = [
|
||||||
{ name => 'global', type => 0 }
|
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }
|
||||||
];
|
];
|
||||||
|
|
||||||
$self->{maps_counters}->{global} = [
|
$self->{maps_counters}->{global} = [
|
||||||
@ -55,7 +55,7 @@ sub set_counters {
|
|||||||
},
|
},
|
||||||
{ label => 'time', nlabel => 'http.response.time.seconds', set => {
|
{ label => 'time', nlabel => 'http.response.time.seconds', set => {
|
||||||
key_values => [ { name => 'time' } ],
|
key_values => [ { name => 'time' } ],
|
||||||
output_template => 'Response time %.3fs',
|
output_template => 'response time %.3fs',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ label => 'time', template => '%.3f', min => 0, unit => 's' }
|
{ 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 => {
|
{ label => 'size', nlabel => 'http.response.size.count', display_ok => 0, set => {
|
||||||
key_values => [ { name => 'size' } ],
|
key_values => [ { name => 'size' } ],
|
||||||
output_template => 'Content size : %s',
|
output_template => 'content size: %s',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ label => 'size', template => '%s', min => 0, unit => 'B' }
|
{ 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' },
|
'cacert-file:s' => { name => 'cacert_file' },
|
||||||
'cert-pwd:s' => { name => 'cert_pwd' },
|
'cert-pwd:s' => { name => 'cert_pwd' },
|
||||||
'cert-pkcs12' => { name => 'cert_pkcs12' },
|
'cert-pkcs12' => { name => 'cert_pkcs12' },
|
||||||
'header:s@' => { name => 'header' },
|
'header:s@' => { name => 'header' },
|
||||||
'get-param:s@' => { name => 'get_param' },
|
'get-param:s@' => { name => 'get_param' },
|
||||||
'post-param:s@' => { name => 'post_param' },
|
'post-param:s@' => { name => 'post_param' },
|
||||||
'cookies-file:s' => { name => 'cookies_file' },
|
'cookies-file:s' => { name => 'cookies_file' },
|
||||||
'warning:s' => { name => 'warning' },
|
'warning:s' => { name => 'warning' },
|
||||||
'critical:s' => { name => 'critical' }
|
'critical:s' => { name => 'critical' },
|
||||||
|
'extra-stats' => { name => 'extra_stats' }
|
||||||
});
|
});
|
||||||
|
|
||||||
$self->{http} = centreon::plugins::http->new(%options);
|
$self->{http} = centreon::plugins::http->new(%options);
|
||||||
@ -140,6 +181,11 @@ sub manage_selection {
|
|||||||
|
|
||||||
$self->{global}->{size} = bytes::length($webcontent);
|
$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;
|
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')
|
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
|
=back
|
||||||
|
|
||||||
|
@ -481,6 +481,30 @@ sub get_certificate {
|
|||||||
return ('pem', $certs->[0]->{Cert});
|
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;
|
1;
|
||||||
|
|
||||||
__END__
|
__END__
|
||||||
|
@ -348,6 +348,12 @@ sub get_certificate {
|
|||||||
return ('socket', $con);
|
return ('socket', $con);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub get_time {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
__END__
|
__END__
|
||||||
|
@ -34,7 +34,7 @@ sub new {
|
|||||||
'proxyurl:s' => { name => 'proxyurl' },
|
'proxyurl:s' => { name => 'proxyurl' },
|
||||||
'proxypac:s' => { name => 'proxypac' },
|
'proxypac:s' => { name => 'proxypac' },
|
||||||
'insecure' => { name => 'insecure' },
|
'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');
|
$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();
|
return $self->{'backend_' . $self->{http_backend}}->get_certificate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub get_times {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
return $self->{'backend_' . $self->{http_backend}}->get_times();
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
__END__
|
__END__
|
||||||
|
Loading…
x
Reference in New Issue
Block a user