summaryrefslogtreecommitdiff
path: root/computer-time-limit.php
diff options
context:
space:
mode:
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
+
+}