From 46ceccd1a0015ef55031f9cc9de4e560098963a6 Mon Sep 17 00:00:00 2001 From: Sven Luethi Date: Mon, 16 Sep 2024 17:30:16 +0200 Subject: [PATCH] modified: software/app.php modified: software/integration.php --- software/app.php | 2 +- software/integration.php | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/software/app.php b/software/app.php index b0fcf94..c954a9e 100644 --- a/software/app.php +++ b/software/app.php @@ -17,5 +17,5 @@ $router->get('/favicon.ico', function() { }); require_once('device-api.php'); -//require_once('integration.php'); +require_once('integration.php'); diff --git a/software/integration.php b/software/integration.php index 4c4568e..99252c5 100644 --- a/software/integration.php +++ b/software/integration.php @@ -1,7 +1,27 @@ get('/metrics', function($req) { +$router->get('/metrics', function($req) use($db) { + header('Content-Type: text/plain; charset=UTF-8'); + + $results = $db->getDevices(); + + // Print temperature metrics + echo "# HELP temperature_celsius Temperature readings from the device\n"; + echo "# TYPE temperature_celsius gauge\n"; + foreach ($results as $index => $row) { + $temperature = $row['temperature']; + echo "temperature_celsius{device_id=\"{$row['id']}\"} $temperature\n"; + } + + // Print humidity metrics + echo "# HELP relative_humidity_percent Humidity readings from the device\n"; + echo "# TYPE relative_humidity_percent gauge\n"; + foreach ($results as $index => $row) { + $humidity = $row['humidity']; + echo "relative_humidity_percent{device_id=\"{$row['id']}\"} $humidity\n"; + } + http_response_code(200); });