Skip to content

Instantly share code, notes, and snippets.

@TheSkorm
Created September 30, 2011 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheSkorm/1253647 to your computer and use it in GitHub Desktop.
Save TheSkorm/1253647 to your computer and use it in GitHub Desktop.
Hacked up graph for bandwidth monitoring gist
<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