Add handling for HTTP response time metric using GuzzleHttp.

This commit is contained in:
Jeroen De Meerleer 2024-06-03 19:48:39 +02:00
parent d0fa8a6a99
commit a726fa024c
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6

View File

@ -13,6 +13,13 @@ if($_SERVER["REQUEST_URI"] == '/metrics') {
$client = new GuzzleHttp\Client(); $client = new GuzzleHttp\Client();
$res = $client->get($c['httpurl']); $res = $client->get($c['httpurl']);
$output = $res->getBody()->getContents(); $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'])) { if(isset($c['jsonelem'])) {
$c['value'] = getArrayValue($c['jsonelem'], json_decode($output, true)); $c['value'] = getArrayValue($c['jsonelem'], json_decode($output, true));