Last active
May 13, 2020 23:18
-
-
Save misakwa/ab09af42a0c453f2458ad3930cc917c4 to your computer and use it in GitHub Desktop.
Lua script to count request, responses, and status codes from wrk/wrk2 tests
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
#!/usr/bin/env lua | |
local thread_id = 1 | |
local threads = {} | |
setup = function(thread) | |
thread:set("id", thread_id) | |
table.insert(threads, thread) | |
end | |
init = function(args) | |
resp_1xx = 0 | |
resp_2xx = 0 | |
resp_3xx = 0 | |
resp_4xx = 0 | |
resp_5xx = 0 | |
total_requests = 0 | |
total_responses = 0 | |
end | |
request = function() | |
total_requests = total_requests + 1 | |
return wrk.request() | |
end | |
response = function(status, header, body) | |
if status < 200 then | |
resp_1xx = resp_1xx + 1 | |
elseif status < 300 then | |
resp_2xx = resp_2xx + 1 | |
elseif status < 400 then | |
resp_3xx = resp_3xx + 1 | |
elseif status < 500 then | |
resp_4xx = resp_4xx + 1 | |
else | |
resp_5xx = resp_5xx + 1 | |
end | |
total_responses = total_responses + 1 | |
-- print("[StatusCode]-> " .. status) | |
-- print("[Body]-> " .. body) | |
end | |
done = function(summary, latency, requests) | |
local resp_1xx = 0 | |
local resp_2xx = 0 | |
local resp_3xx = 0 | |
local resp_4xx = 0 | |
local resp_5xx = 0 | |
local total_requests = 0 | |
local total_responses = 0 | |
local msg = "status [%dXX] = [%d] responses" | |
for index, thread in ipairs(threads) do | |
resp_1xx = resp_1xx + thread:get("resp_1xx") | |
resp_2xx = resp_2xx + thread:get("resp_2xx") | |
resp_3xx = resp_3xx + thread:get("resp_3xx") | |
resp_4xx = resp_4xx + thread:get("resp_4xx") | |
resp_5xx = resp_5xx + thread:get("resp_5xx") | |
total_requests = total_requests + thread:get("total_requests") | |
total_responses = total_responses + thread:get("total_responses") | |
end | |
print("[>Status code summary<]") | |
print(msg:format(1, resp_1xx)) | |
print(msg:format(2, resp_2xx)) | |
print(msg:format(3, resp_3xx)) | |
print(msg:format(4, resp_4xx)) | |
print(msg:format(5, resp_5xx)) | |
print("Total Requests: " .. total_requests) | |
print("Total Responses: " .. total_responses) | |
print("[>End Status code summary<]") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment