Skip to content

Instantly share code, notes, and snippets.

@wellflat
Created April 22, 2018 16:42
Show Gist options
  • Save wellflat/7c5f540e7efa3d4fa1c9b05d4499c203 to your computer and use it in GitHub Desktop.
Save wellflat/7c5f540e7efa3d4fa1c9b05d4499c203 to your computer and use it in GitHub Desktop.
-- example reporting script which demonstrates a custom
-- done() function that prints results as JSON
done = function(summary, latency, requests)
io.write("\nJSON Output:\n")
io.write("{\n")
io.write(string.format("\t\"requests\": %d,\n", summary.requests))
io.write(string.format("\t\"duration_in_microseconds\": %0.2f,\n", summary.duration))
io.write(string.format("\t\"bytes\": %d,\n", summary.bytes))
io.write(string.format("\t\"requests_per_sec\": %0.2f,\n", (summary.requests/summary.duration)*1e6))
io.write(string.format("\t\"bytes_transfer_per_sec\": %0.2f,\n", (summary.bytes/summary.duration)*1e6))
io.write("\t\"latency_distribution\": [\n")
for _, p in pairs({ 50, 75, 90, 99, 99.9, 99.99, 99.999, 100 }) do
io.write("\t\t{\n")
n = latency:percentile(p)
io.write(string.format("\t\t\t\"percentile\": %g,\n\t\t\t\"latency_in_microseconds\": %d\n", p, n))
if p == 100 then
io.write("\t\t}\n")
else
io.write("\t\t},\n")
end
end
io.write("\t]\n}\n")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment