Created
September 30, 2011 12:49
-
-
Save TheSkorm/1253647 to your computer and use it in GitHub Desktop.
Hacked up graph for bandwidth monitoring gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment