Skip to content

Instantly share code, notes, and snippets.

@lodi-g
Last active May 26, 2017 10:37
Show Gist options
  • Save lodi-g/cbefdea2032644270672636752caee3c to your computer and use it in GitHub Desktop.
Save lodi-g/cbefdea2032644270672636752caee3c to your computer and use it in GitHub Desktop.
Just a script to plot your download speed. Useful when you want to call your ISP and shit on them. Oh, and data is always sorted by timestamp.
#!/usr/bin/env node
/*
* How to:
* Have a working UNIX environment
* Download speedtest-cli
* -- in bash
* for i in {0..100}; do speedtest --no-upload --json >> dlspeed.json; done
* ./speedTestPlot.js dlspeed.json
* -- comments
* You can edit the for to have more / less tests.
* You can specify --server to go a little bit faster.
*/
const fs = require('fs');
const path = require('path');
const childProc = require('child_process');
if (!process.argv[2]) {
const n = path.basename(process.argv[0]);
const p = path.basename(process.argv[1]);
console.error(`Usage: ${n} ${p} FILE`);
process.exit(1);
}
const data = [];
fs.readFileSync(process.argv[2], { encoding: 'utf-8' }).split('\n')
.forEach((line, index) => {
try {
data.push(JSON.parse(line));
} catch (e) {
console.error(`[warning] line ${index} was not parsed correctly.`);
}
});
data.sort((a, b) => {
const ad = new Date(a.timestamp).getTime();
const bd = new Date(b.timestamp).getTime();
return ad > bd ? 1 : -1;
});
const gnuplotProc = 'gnuplot';
const gnuplotArgs = ['-p', '-e', 'plot "-"'];
const child = childProc.spawn(gnuplotProc, gnuplotArgs, {
stdio: [ 'pipe', 1, 2 ]
});
data.forEach((f) => {
child.stdin.write(`${f.download}\n`);
});
child.stdin.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment