From b573ff04e6aefcb9050da330408e757410ede53b Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 17 May 2022 16:34:06 +0200 Subject: [dnbd3] Show upload speed and client count in realtime --- modules-available/dnbd3/page.inc.php | 37 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 21 deletions(-) (limited to 'modules-available/dnbd3/page.inc.php') 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 ''; - $line = ''; - } 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)); } } -- cgit v1.2.3-55-g7522