Cheatsheet: k6
Last updated 2026-10-06
Minimal Test
Minimal script: one GET request per iteration
Run a script
CLI Flags
Run with a fixed number of virtual users and duration
Run a fixed number of iterations instead of a duration
Pass an environment variable into the script (read via __ENV)
Export results to a JSON file
Stream results to an InfluxDB or Prometheus remote write endpoint
Quiet mode: suppress progress bars (useful in CI logs)
Validate a script without running a full load test
Load Profile (Stages)
Ramp up, hold, then ramp down
Thresholds
Fail the run if latency or error rate is too high
Scope a threshold to requests tagged with a name
Checks (Assertions)
Assert response status and body
HTTP Requests
POST a JSON payload with headers
Send multiple requests in parallel with http.batch
Scenarios & Executors
Constant arrival rate: fixed request rate regardless of response time
Executor types at a glance
Metrics Reference
http_req_duration -- total time for the request (DNS + connect + TLS + send + wait + receive)
http_req_waiting -- time waiting for the response (a.k.a. TTFB)
http_req_failed -- rate of requests considered failed
http_reqs -- total number of HTTP requests made
iterations -- total number of times the default function ran
vus / vus_max -- current and configured maximum virtual users
data_sent / data_received -- total bytes sent and received
Custom Metrics
Track a custom timing with Trend
Other custom metric types
Lifecycle
setup / default / teardown
Init code vs VU code
Quick Recipes
Reuse an auth token fetched once in setup()
Group related requests for clearer summary output
Add think time between requests
Load CSV test data once and share it across VUs with SharedArray
Run k6 in a GitHub Actions step