From 242e9fd798b1ed7623f4f004f738d70cb888b15c Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Mon, 4 Nov 2024 17:58:57 +0100 Subject: add openmetrics format --- computer-time-limit.php | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/computer-time-limit.php b/computer-time-limit.php index 3fc73e4..3297f67 100644 --- a/computer-time-limit.php +++ b/computer-time-limit.php @@ -107,17 +107,39 @@ if (array_key_exists('msg', $_POST) && array_key_exists('sig', $_POST)) { $result = $db->query('select * from `computer_time`'); +$is_openmetrics = array_key_exists('openmetrics', $_GET); + +if ($is_openmetrics) { + print('#HELP computer_time_left Available computer time in seconds.' . "\n"); + print('#TYPE computer_time_left gauge' . "\n"); +} else { + ?>fetchArray()) { $bis = strtotime($row['bis']); $von = strtotime($row['von']); - if (!is_null($row['host'])) { + + $bis = $bis + 30*60*(floor($now/60/60/24) - floor($von/60/60/24)); + if (!is_null($host)) { $von = $now; } $noch = $bis - $von; + if ($noch < 0) { + $noch = 0; + } + if ($noch > 4*60*60) { + $noch = 4*60*60; + } + + if ($is_openmetrics) { + print('computer_time_left{who="' . $row['name'] . '"} ' . $noch . "\n"); + continue; + } ?>
fetchArray()) {
+if (!$is_openmetrics) { + +?>