Last active
May 13, 2017 16:27
-
-
Save botto/4a0c8d87f1c630def2cddd5006717337 to your computer and use it in GitHub Desktop.
Simple script to generate iperf report CSV
This file contains hidden or 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
#!/usr/bin/env bash | |
N_PARALLEL=10 | |
N_DONE=0 | |
TARGET=$1 | |
DATESTAMP=`date +%Y%m%d%H%M%S` | |
TARGET_NAME=`echo $1 | tr . _` | |
LOG_TOP_DEST=logs | |
LOG_FILES_DEST=${LOG_TOP_DEST}/${TARGET_NAME}/${DATESTAMP} | |
SCRIPT_ROOT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
mkdir -p $LOG_FILES_DEST; | |
while [ "${N_DONE}" -lt "${N_PARALLEL}" ]; do | |
let N_DONE=N_DONE+1 | |
iperf3 -P ${N_DONE} --json -c $1 --logfile ${LOG_FILES_DEST}/${N_DONE}.json | |
sleep 5 | |
done | |
node prepLogs.js -p ${N_DONE} -l ${LOG_FILES_DEST} |
This file contains hidden or 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
const program = require('commander'); | |
const fs = require('fs'); | |
program | |
.version('0.0.1') | |
.option('-l --logs <logfiles_path>') | |
.option('-p --parallel <parallel>') | |
.parse(process.argv); | |
const out = []; | |
let reading = 0; | |
const semaphore = -1; | |
if (program.logs && program.parallel && program.parallel > 0) { | |
fs.access(program.logs, fs.constants.R_OK, (err) => { | |
if (err) { | |
console.log(err); | |
} | |
else { | |
for (let i = 1; i <= program.parallel; i++) { | |
fs.readFile(program.logs + '/' + i + '.json', 'utf8', (err, data) => { | |
reading++; | |
if (err) { | |
console.log(err); | |
} | |
else { | |
const json = JSON.parse(data); | |
out.push({ | |
parallel: i, | |
sent: json.end.sum_sent.bits_per_second / 8, | |
recv: json.end.sum_received.bits_per_second / 8 | |
}); | |
out.sort((a, b) => { | |
if (a.parallel < b.parallel) return -1; | |
if (a.parallel > b.parallel) return 0; | |
return 0; | |
}); | |
if (reading == program.parallel) { | |
process.stdout.write(JSON.stringify(out)); | |
} | |
} | |
}) | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment