Last active
January 31, 2016 15:45
-
-
Save polarblau/0e60b2c54f7742654280 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
body { | |
font: 10px sans-serif; | |
} | |
.axis path, | |
.axis line { | |
fill: none; | |
stroke: #000; | |
shape-rendering: crispEdges; | |
} | |
.x.axis path { | |
display: none; | |
} | |
.line { | |
fill: none; | |
stroke: steelblue; | |
stroke-width: 1.5px; | |
} | |
</style> | |
<body> | |
<script src="d3.js"></script> | |
<script> | |
var MAX_SPEED = 50; | |
var margin = {top: 20, right: 100, bottom: 30, left: 50}, | |
width = 960 - margin.left - margin.right, | |
height = 500 - margin.top - margin.bottom; | |
var color = d3.scale.category10(); | |
var formatDate = d3.time.format("%Y-%m-%dT%H:%M:%SZ"); | |
var x = d3.time.scale() | |
.range([0, width]); | |
var y = d3.scale.linear() | |
.range([height, 0]); | |
var xAxis = d3.svg.axis() | |
.scale(x) | |
.orient("bottom"); | |
var yAxis = d3.svg.axis() | |
.scale(y) | |
.orient("left"); | |
var line = d3.svg.line() | |
.x(function(d) { return x(d.timestamp); }) | |
.y(function(d) { return y(d.speed); }); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width + margin.left + margin.right) | |
.attr("height", height + margin.top + margin.bottom) | |
.append("g") | |
.attr("transform", "translate(" + margin.left + "," + margin.top + ")"); | |
d3.csv("log.csv", type, function(error, data) { | |
if (error) throw error; | |
x.domain(d3.extent(data, function(d) { return d.timestamp; })); | |
y.domain([0, MAX_SPEED]); | |
color.domain(['download', 'upload']); | |
var speeds = color.domain().map(function(name) { | |
return { | |
name: name, | |
values: data.map(function(d) { | |
return { timestamp: d.timestamp, speed: +d[name] }; | |
}) | |
}; | |
}); | |
svg.append("g") | |
.attr("class", "x axis") | |
.attr("transform", "translate(0," + height + ")") | |
.call(xAxis); | |
svg.append("g") | |
.attr("class", "y axis") | |
.call(yAxis) | |
.append("text") | |
.attr("transform", "rotate(-90)") | |
.attr("y", 6) | |
.attr("dy", ".71em") | |
.style("text-anchor", "end") | |
.text("Mbit/Second"); | |
var speed = svg.selectAll(".speed") | |
.data(speeds) | |
.enter().append("g") | |
.attr("class", "speed"); | |
speed.append("path") | |
.attr("class", "line") | |
.attr("d", function(d) { return line(d.values); }) | |
.style("stroke", function(d) { return color(d.name); }); | |
speed.append("text") | |
.datum(function(d) { return {name: d.name, value: d.values[d.values.length - 1]}; }) | |
.attr("transform", function(d) { | |
return "translate(" + x(d.value.timestamp) + "," + y(d.value.speed) + ")"; | |
}) | |
.attr("x", 3) | |
.attr("dy", ".35em") | |
.text(function(d) { | |
return d.name.charAt(0).toUpperCase() + d.name.slice(1);; | |
}); | |
}); | |
function type(d) { | |
d.timestamp = formatDate.parse(d.timestamp); | |
return d; | |
} | |
</script> |
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
timestamp | ping | download | upload |
---|
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
while true | |
do | |
./speedtest_cli/speedtest_cli.py --simple | # Run speed test | |
egrep -o "([0-9]*\.[0-9]+|[0-9]+)" | # Extract durations | |
(date -u +"%Y-%m-%dT%H:%M:%SZ" && cat) | # Prepend timestamp as ISO 8601 | |
tr '\n' ',' | # Join lines with commas | |
sed 's/,$//' >> ./log.csv # Remove trailing comma and append to log | |
sleep 60 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment