From 267d2180f8bf2ad44e4cb316c1d5b0386a32cd9f Mon Sep 17 00:00:00 2001 From: ghost Date: Sun, 13 Aug 2023 00:23:37 +0300 Subject: [PATCH] implement dashboard --- src/public/index.php | 363 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 363 insertions(+) create mode 100644 src/public/index.php diff --git a/src/public/index.php b/src/public/index.php new file mode 100644 index 0000000..98bb7b8 --- /dev/null +++ b/src/public/index.php @@ -0,0 +1,363 @@ + 1 ? (int) $_GET['page'] : 1; +$requestCalendar = !empty($_GET['calendar']) && in_array($_GET['calendar'], ['peers', 'traffic']) ? $_GET['calendar'] : 'peers'; + +// app begin +$calendar = new Yggverse\Graph\Calendar\Month($requestTime); + +foreach ($calendar->getNodes() as $day => $node) { + + switch ($requestCalendar) { + + case 'peers': + + $timeFrom = strtotime(sprintf('%s-%s-%s 00:00', date('Y', $requestTime), date('n', $requestTime), $day)); + $timeTo = strtotime('+1 day', strtotime(sprintf('%s-%s-%s 00:00', date('Y', $requestTime), date('n', $requestTime), $day))); + + $dbPeerTotalByTimeUpdated = $memory->getByMethodCallback( + $db, 'findPeerTotalByTimeUpdated', [$timeFrom, $timeTo] + ); + + $dbPeerTotalByTimeAdded = $memory->getByMethodCallback( + $db, 'findPeerTotalByTimeAdded', [$timeFrom, $timeTo] + ); + + // Add daily stats + $calendar->addNode($day, $dbPeerTotalByTimeUpdated, sprintf(_('online %s'), $dbPeerTotalByTimeUpdated), 'green', 0); + $calendar->addNode($day, $dbPeerTotalByTimeAdded, sprintf(_('new %s'), $dbPeerTotalByTimeAdded), 'blue', 0); + + // Add hourly stats + for ($hour = 0; $hour < 24; $hour++) { + + $timeFrom = strtotime(sprintf('%s-%s-%s %s:00', date('Y', $requestTime), date('n', $requestTime), $day, $hour)); + $timeTo = strtotime(sprintf('%s-%s-%s %s:00', date('Y', $requestTime), date('n', $requestTime), $day, $hour + 1)); + + $dbPeerTotalByTimeUpdated = $memory->getByMethodCallback( + $db, 'findPeerTotalByTimeUpdated', [$timeFrom, $timeTo] + ); + + $dbPeerTotalByTimeAdded = $memory->getByMethodCallback( + $db, 'findPeerTotalByTimeAdded', [$timeFrom, $timeTo] + ); + + $calendar->addNode($day, $dbPeerTotalByTimeUpdated, sprintf(_('%s:00-%s:00 online %s'), $hour, $hour + 1, $dbPeerTotalByTimeUpdated), 'green', 1); + $calendar->addNode($day, $dbPeerTotalByTimeAdded, sprintf(_('%s:00-%s:00 new %s'), $hour, $hour + 1, $dbPeerTotalByTimeAdded), 'blue', 1); + } + + break; + case 'traffic': + + $timeFrom = strtotime(sprintf('%s-%s-%s 00:00', date('Y', $requestTime), date('n', $requestTime), $day)); + $timeTo = strtotime('+1 day', strtotime(sprintf('%s-%s-%s 00:00', date('Y', $requestTime), date('n', $requestTime), $day))); + + $dbPeerSessionSentSumByTimeUpdated = $memory->getByMethodCallback( + $db, 'findPeerSessionSentSumByTimeUpdated', [$timeFrom, $timeTo] + ); + + $dbPeerSessionReceivedSumByTimeUpdated = $memory->getByMethodCallback( + $db, 'findPeerSessionReceivedSumByTimeUpdated', [$timeFrom, $timeTo] + ); + + // Add daily stats + $calendar->addNode($day, $dbPeerSessionSentSumByTimeUpdated, sprintf(_('↑ %s'), number_format($dbPeerSessionSentSumByTimeUpdated / 1000000, 3)), 'red', 0); + $calendar->addNode($day, $dbPeerSessionReceivedSumByTimeUpdated, sprintf(_('↓ %s'), number_format($dbPeerSessionReceivedSumByTimeUpdated / 1000000, 3)), 'green', 0); + + // Add hourly stats + for ($hour = 0; $hour < 24; $hour++) { + + $timeFrom = strtotime(sprintf('%s-%s-%s %s:00', date('Y', $requestTime), date('n', $requestTime), $day, $hour)); + $timeTo = strtotime(sprintf('%s-%s-%s %s:00', date('Y', $requestTime), date('n', $requestTime), $day, $hour + 1)); + + $dbPeerSessionSentSumByTimeUpdated = $memory->getByMethodCallback( + $db, 'findPeerSessionSentSumByTimeUpdated', [$timeFrom, $timeTo] + ); + + $dbPeerSessionReceivedSumByTimeUpdated = $memory->getByMethodCallback( + $db, 'findPeerSessionReceivedSumByTimeUpdated', [$timeFrom, $timeTo] + ); + + $calendar->addNode($day, $dbPeerSessionSentSumByTimeUpdated, sprintf(_('%s:00-%s:00 ↑ %s'), $hour, $hour + 1, number_format($dbPeerSessionSentSumByTimeUpdated / 1000000, 3)), 'red', 1); + $calendar->addNode($day, $dbPeerSessionReceivedSumByTimeUpdated, sprintf(_('%s:00-%s:00 ↓ %s'), $hour, $hour + 1, number_format($dbPeerSessionReceivedSumByTimeUpdated / 1000000, 3)), 'green', 1); + } + + break; + } +} + +$peers = $memory->getByMethodCallback( + $db, + 'findPeers', + [ + ($requestPage - 1) * WEBSITE_PEER_REMOTE_PAGINATION_LIMIT, + $requestPage + WEBSITE_PEER_REMOTE_PAGINATION_LIMIT, + $requestSort, + $requestOrder, + ] +); + +?> + + + + + + + + + <?php echo sprintf(_('%s - Yggdrasil network explorer since %s'), WEBSITE_NAME, date('Y', $memory->getByMethodCallback($db, 'getPeerFirstByTimeAdded')->timeAdded)) ?> + + + + + + +
+
+ +
+
+
+
+
+
+
+

+
+
+
+
+
+
+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + address ?> + + uptimeAvg ? round($peer->uptimeAvg / 60 / 60, 2) : 0 ?>sentSum ? number_format($peer->sentSum / 1000000, 3) : 0 ?>receivedSum ? number_format($peer->receivedSum / 1000000, 3) : 0 ?> + + • + +
+ 1) { ?> + + + + +
+
+
+
+
+

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
getByMethodCallback($db, 'findPeerTotalByTimeUpdated', [time() - WEBSITE_PEER_REMOTE_TIME_ONLINE_TIMEOUT, + strtotime('+1 month', strtotime(sprintf('%s-%s-%s 00:00', date('Y'), date('n'), 1)))]) ?>
getByMethodCallback($db, 'findPeerTotalByTimeAdded', [strtotime(sprintf('%s-%s-%s 00:00', date('Y'), date('n'), 1)), + strtotime('+1 month', strtotime(sprintf('%s-%s-%s 00:00', date('Y'), date('n'), 1)))]) ?>
getByMethodCallback($db, 'findPeerTotalByTimeUpdated', [strtotime(sprintf('%s-%s-%s 00:00', date('Y'), date('n'), 1)), + strtotime('+1 month', strtotime(sprintf('%s-%s-%s 00:00', date('Y'), date('n'), 1)))]) ?>
getByMethodCallback($db, 'getPeersTotal') ?>
+
+
+
+ + + + + + + + + + + + + + + + + + + + +
getByMethodCallback($db, 'getPeerSessionSentSum') / 1000000, 3) ?>
getByMethodCallback($db, 'getPeerSessionReceivedSum') / 1000000, 3) ?>
getByMethodCallback($db, 'getPeerSessionSentSum') + + $memory->getByMethodCallback($db, 'getPeerSessionReceivedSum')) / 1000000, 3) ?>
+
+
+
+

+ + | + + | + +
+ +
+

+
+ getNodes() as $day => $node) { ?> +
+
+ +
+ + $layers) { ?> +
+
+ +
label ?>
+ +
+ +
+ +
+ + +
+ +
+
+
+
+
+
+ + + \ No newline at end of file