summaryrefslogtreecommitdiffstats
path: root/modules-available/dnbd3/page.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2022-05-17 16:34:06 +0200
committerSimon Rettberg2022-05-17 16:34:06 +0200
commitb573ff04e6aefcb9050da330408e757410ede53b (patch)
tree1b8ad093b920cd2a261c2f1bb83538b8afba6921 /modules-available/dnbd3/page.inc.php
parent[statistics] Make sure hwname and devpath get valid ASCII only (diff)
downloadslx-admin-b573ff04e6aefcb9050da330408e757410ede53b.tar.gz
slx-admin-b573ff04e6aefcb9050da330408e757410ede53b.tar.xz
slx-admin-b573ff04e6aefcb9050da330408e757410ede53b.zip
[dnbd3] Show upload speed and client count in realtime
Diffstat (limited to 'modules-available/dnbd3/page.inc.php')
-rw-r--r--modules-available/dnbd3/page.inc.php37
1 files changed, 16 insertions, 21 deletions
diff --git a/modules-available/dnbd3/page.inc.php b/modules-available/dnbd3/page.inc.php
index a58f6fcc..e90eff0f 100644
--- a/modules-available/dnbd3/page.inc.php
+++ b/modules-available/dnbd3/page.inc.php
@@ -492,6 +492,8 @@ class Page_Dnbd3 extends Page
$this->ajaxReboot();
} elseif ($action === 'cachemap') {
$this->ajaxCacheMap();
+ } elseif ($action === 'stats') {
+ $this->ajaxStats();
} else {
die($action . '???');
}
@@ -616,30 +618,23 @@ class Page_Dnbd3 extends Page
die($data);
}
- private function genChunk($acc)
+ private function ajaxStats()
{
- static $last = -1;
- static $count = 0;
- if ($acc !== false) {
- if ($acc > 15) {
- $acc = 15;
- }
- $acc = round($acc);
- if ($last === $acc) {
- $count++;
- return '';
- }
+ $res = Database::simpleQuery('SELECT s.serverid, m.clientip, s.fixedip
+ FROM dnbd3_server s
+ LEFT JOIN machine m ON (s.machineuuid = m.machineuuid)
+ WHERE s.lastseen > :cutoff', ['cutoff' => time() - 310]);
+ $lookup = [];
+ foreach ($res as $row) {
+ $lookup[$row['fixedip'] ?? $row['clientip'] ?? ''] = $row['serverid'];
}
- if ($last !== -1) {
- if ($count === 1)
- return '<b style="background:#0' . dechex($acc) . '0"></b>';
- $line = '<b style="background:#0' . dechex($last) . '0;flex-grow:' . $count . '"></b>';
- } else {
- $line = '';
+ $result = Dnbd3Rpc::getStatsMulti(array_keys($lookup));
+ $return = [];
+ foreach ($result as $ip => $data) {
+ $return[$lookup[$ip]] = $data;
}
- $last = $acc;
- $count = 1;
- return $line;
+ Header('Content-Type: application/json; charset=utf-8');
+ die(json_encode($return));
}
}