Created
October 3, 2023 22:38
-
-
Save myobie/4ecb4d4972db8f84cacdb284147561ca to your computer and use it in GitHub Desktop.
wrk lua script to output the count of response http status codes
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
local threads = {} | |
function setup(thread) | |
-- track each thread | |
table.insert(threads, thread) | |
end | |
function init(args) | |
-- thread local statuses table | |
statuses = {["100"] = 0} | |
end | |
function response(status, headers, body) | |
local key = string.format("%d", status) | |
if statuses[key] == nil then | |
statuses[key] = 1 | |
else | |
statuses[key] = statuses[key] + 1 | |
end | |
end | |
function done(summary, latency, requests) | |
io.write("Status counts:\n") | |
local statuses = {["100"] = 0} | |
-- reduce each thread's status counts into the final table | |
for i, thread in ipairs(threads) do | |
local tstatuses = thread:get("statuses") | |
for key, value in pairs(tstatuses) do | |
if statuses[key] == nil then | |
statuses[key] = value | |
else | |
statuses[key] = statuses[key] + value | |
end | |
end | |
end | |
-- output the sum table | |
for status, count in pairs(statuses) do | |
if count > 0 then | |
io.write(string.format("%s: %d\n", status, count)) | |
end | |
end | |
io.write("==========================\n") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment