From bcb0d0b23da8f45b075e8b1cff50fba6e162c803 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Mon, 3 Jun 2024 13:03:31 +0200 Subject: [PATCH] Add handling for HTTP response time metric using GuzzleHttp. --- index.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/index.php b/index.php index 1fa3baf..6a0b74d 100644 --- a/index.php +++ b/index.php @@ -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));