forked from zKillboard/zKillboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyticsView.php
42 lines (38 loc) · 851 Bytes
/
analyticsView.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
require_once 'init.php';
while (true) {
$agents = [];
$uris = [];
$ips = [];
for ($i = 0; $i <= 6; ++$i) {
$ts = floor((time() - ($i * 60)) / 60);
addAll($agents, $redis->hGetAll("analytics:agent:$ts"));
addAll($uris, $redis->hGetAll("analytics:uri:$ts"));
addAll($ips, $redis->hGetAll("analytics:ip:$ts"));
}
system('clear');
show10($ips);
show10($uris);
show10($agents);
sleep(5);
}
function addAll(&$array, &$map)
{
foreach ($map as $k => $v) {
@$array[$k] += $v;
}
}
function show10(&$array)
{
arsort($array);
$i = 10;
while (sizeof($array) > 10 && $i > 0) {
reset($array);
$key = key($array);
$value = $array[$key];
array_shift($array);
echo "$value $key\n";
--$i;
}
echo "\n";
}