How to Capture Per‑API Response Times in Load Tests with Groovy Scripts
This article explains how to extend a performance testing framework to record and visualize individual HTTP interface latencies by parsing consolidated logs, grouping timings by URL, and using a Groovy script with StatisticsUtil to generate response‑time charts.
Idea
The existing performance testing framework only reports overall latency and QPS, lacking per‑API response‑time statistics; this guide shows how to extract, aggregate, and chart each endpoint’s latency from log files.
Log Information
Sample log lines contain the request URI, latency in milliseconds, and a requestId. All logs must be merged into a single file and log4j2 should be configured for the expected volume.
WARN-> 创建订单号:f1615455162cXCQX
INFO-> 请求uri:https://.../api/public/v1/order/refund,耗时:1181 ms, requestId:Fun20210311173240XNwf
INFO-> 请求uri:https://.../api/public/v1/order/create,耗时:1336 ms, requestId:Fun20210311173240NBiR
...Groovy Script
The Groovy script reads the log, extracts the latency for the “create order” and “refund” APIs, stores them in separate lists, and calls StatisticsUtil.statistics to produce charts; the thread count (200) is supplied as a parameter for the chart title.
def lines = RWUtil.readTxtFileByLine(getLongFile("link.log"), "public/v1/order", true)
def create = []
def refund = []
lines.each {
def first = (Regex.findFirst(it, /\d+ ms/) - " ms") as int
if (it.contains(OrderApi.CREATE)) create << first
else if (it.contains(OrderApi.REFUND)) refund << first
else println it
}
println StatisticsUtil.statistics(create, "创建订单接口", 200)
println StatisticsUtil.statistics(refund, "退款", 200)Console Output
The script outputs statistical charts; screenshots of the generated graphs are shown below.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
