public
Created

Hacked up graph for bandwidth monitoring gist

  • Download Gist
gistfile1.aw
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 55 56 57
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["annotatedtimeline"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('date', 'Time');
data.addColumn('number', 'Bytes/Second');
<?php
$row = 1;
 
if (($handle = fopen("/home/mwheeler/bandwidth.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
$row++;
for ($c=0; $c < $num; $c++) {
if ($c==0){
$timestamp = $data[$c];
} else if ($c==2) {
$a = str_replace(" KB", "", $data[$c]);
if ($a>0) {
$speed = $a*1024;
}
 
}
if ($speed & $timestamp){
$speeds[$timestamp] = $speed ;
}
}
}
fclose($handle);
}
echo "data.addRows([";
$first = false;
foreach ($speeds as $k => $v) {
if ($first == false){
echo "[new Date(".$k."*1000),".$v."]\n";
$first = true;
}
else {
echo ",[new Date(".$k."*1000),".$v."]\n";
}
}
echo "]);\n";
?>
var chart = new google.visualization.AnnotatedTimeLine(document.getElementById('chart_div'));
chart.draw(data, {dateFormat: 'HH:mm MMMM dd, yyyy'});
}
</script>
</head>
 
<body>
<div id='chart_div' style='width: 1000px; height: 400px;'></div>
</body>
</html>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.