summaryrefslogtreecommitdiff
path: root/computer-time-limit.php
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2024-11-04 17:58:57 +0100
committerErich Eckner <git@eckner.net>2024-11-04 17:58:57 +0100
commit242e9fd798b1ed7623f4f004f738d70cb888b15c (patch)
tree459735906e5b9087950efff7b914191a5b86cdd4 /computer-time-limit.php
parentef045b683c2705555d2c8c34273309f1181878b5 (diff)
downloadcomputer-time-limit-242e9fd798b1ed7623f4f004f738d70cb888b15c.tar.xz
add openmetrics format
Diffstat (limited to 'computer-time-limit.php')
-rw-r--r--computer-time-limit.php30
1 files 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 {
+
?><html><body><table>
<?php
+}
+
while ($row = $result->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;
+ }
?> <tr><td><?php print($row['name']); ?></td><td><?php
@@ -130,4 +152,8 @@ while ($row = $result->fetchArray()) {
<?php
}
-?></table></body></html>
+if (!$is_openmetrics) {
+
+?></table></body></html><?php
+
+}