Add handling for HTTP response time metric using GuzzleHttp.

This commit is contained in:
Jeroen De Meerleer 2024-06-03 13:03:31 +02:00
parent 226ec5c6a1
commit bcb0d0b23d
No known key found for this signature in database
GPG Key ID: 3B23D1B3498D7641

View File

@ -13,6 +13,13 @@ if($_SERVER["REQUEST_URI"] == '/metrics') {
$client = new GuzzleHttp\Client();
$res = $client->get($c['httpurl']);
$output = $res->getBody()->getContents();
} elseif(isset($c['httpresponsetime'])) {
$client = new GuzzleHttp\Client();
$output = NULL;
$res = $client->request('GET', $c['httpresponsetime'], [
'on_stats' => function (GuzzleHttp\TransferStats $stats) use (&$output) {
$output = $stats->getTransferTime();
}]);
}
if(isset($c['jsonelem'])) {
$c['value'] = getArrayValue($c['jsonelem'], json_decode($output, true));