-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbw-rates.php
54 lines (40 loc) · 1.33 KB
/
bw-rates.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
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/*
PA: This is a massive pile of yuck, but it works
*/
header('Content-type: text/javascript');
?>
<?php
//This is the only variable you might need to change.
$dir = "/var/www/mrtg";
$logfile = ($_REQUEST['log']) ? $_REQUEST['log'] : 'router_10.log';
$logfile = $dir .'/'. $logfile;
$callback = ($_GET['callback']) ? $_GET['callback'] : 'callback';
$extime = gmDate("D") . "," . gmDate("d M Y H:i:s") . "GMT";
if (stristr($logfile,"log") <> "" ) {
$handle = fopen($logfile, "r");
if ($handle) {
$buffer = fgetcsv($handle, 4096, ' '); // Eat the first line...
$buffer = fgetcsv($handle, 4096, ' '); // ... the latest rates are what we want
$rate['timestamp'] = $buffer[0];
/* These are tagged as "average" but are in fact sampled every 60secs,
so only the MRTG graphs will show the actual 5min average from 5 samples.
This can therefore be interpreted more as "current" speed
*/
$rate['average_in'] = (($buffer[1]*8));
$rate['average_out'] = (($buffer[2]*8));
$rate['max_in'] = (($buffer[3]*8));
$rate['max_out'] = (($buffer[4]*8));
fclose($handle);
} else {
echo "No handle?";
}
}
$json = json_encode($rate);
echo $callback . '(' . $json . ');';
/*
Max Average Current
In: 19.0 Mb/s (53.9%) 1243.7 kb/s (3.5%) 655.6 kb/s (1.9%)
Out: 3220.1 kb/s (97.7%) 359.1 kb/s (10.9%) 3082.3 kb/s (93.5%)
*/
?>