Learning Notes #72 β Metrics in K6 Load Testing
12 February 2025 at 17:15
In our previous blog on K6, we ran a script.js to test an api. As an output we received some metrics in the cli.

In this blog we are going to delve deep in to understanding metrics in K6.
1. HTTP Request Metrics
http_reqs
- Description: Total number of HTTP requests initiated during the test.
- Usage: Indicates the volume of traffic generated. A high number of requests can simulate real-world usage patterns.
http_req_duration
- Description: Time taken for a request to receive a response (in milliseconds).
- Components:
- http_req_connecting: Time spent establishing a TCP connection.
- http_req_tls_handshaking: Time for completing the TLS handshake.
- http_req_waiting (TTFB): Time spent waiting for the first byte from the server.
- http_req_sending: Time taken to send the HTTP request.
- http_req_receiving: Time spent receiving the response data.
- Usage: Identifies performance bottlenecks like slow server responses or network latency.
http_req_failed
- Description: Proportion of failed HTTP requests (ratio between 0 and 1).
- Usage: Highlights reliability issues. A high failure rate indicates problems with server stability or network errors.
2. VU (Virtual User) Metrics
vus
- Description: Number of active Virtual Users at any given time.
- Usage: Reflects concurrency level. Helps analyze how the system performs under varying loads.
vus_max
- Description: Maximum number of Virtual Users during the test.
- Usage: Defines the peak load. Useful for stress testing and capacity planning.
3. Iteration Metrics
iterations
- Description: Total number of script iterations executed.
- Usage: Measures the testβs progress and workload. Useful in endurance (soak) testing to observe long-term stability.
iteration_duration
- Description: Time taken to complete one iteration of the script.
- Usage: Helps identify performance degradation over time, especially under sustained load.
4. Data Transfer Metrics
data_sent
- Description: Total amount of data sent over the network (in bytes).
- Usage: Monitors network usage. High data volumes might indicate inefficient request payloads.
data_received
- Description: Total data received from the server (in bytes).
- Usage: Detects bandwidth usage and helps identify heavy response payloads.
5. Custom Metrics (Optional)
While K6 provides default metrics, you can define custom metrics like Counters, Gauges, Rates, and Trends for specific business logic or technical KPIs.
Example
import { Counter } from 'k6/metrics'; let myCounter = new Counter('my_custom_metric'); export default function () { myCounter.add(1); // Increment the custom metric }
Interpreting Metrics for Performance Optimization
- Low
http_req_duration
+ Highhttp_reqs
= Good scalability. - High
http_req_failed
= Investigate server errors or timeouts. - High
data_sent
/data_received
= Optimize payloads. - Increasing
iteration_duration
over time = Possible memory leaks or resource exhaustion.