K6 CHEAT SHEET

Modern Load Testing for Developers
v1.0
Installation
  • macOSbrew install k6
  • Windowschoco install k6
  • Linuxsnap install k6
  • Dockerdocker pull grafana/k6
  • npmnpm i -g @grafana/k6
Basic Script Structure
import http from 'k6/http'; import { check, sleep } from 'k6'; export const options = { vus: 10, // Virtual Users duration: '30s', // Test duration }; export default function() { const res = http.get('https://test-api.k6.io'); check(res, { 'status is 200': (r) => r.status === 200 }); sleep(1); }
CLI Commands
  • k6 runExecute test script
  • k6 cloudRun on k6 Cloud
  • k6 inspectInspect script
  • k6 versionShow version
  • --vusVirtual users
  • --durationTest duration
HTTP Methods
  • http.get()GET request
  • http.post()POST request
  • http.put()PUT request
  • http.del()DELETE request
  • http.patch()PATCH request
  • http.batch()Parallel requests
Test Options
  • vusVirtual users count
  • durationTest duration
  • iterationsTotal iterations
  • stagesRamp up/down
  • thresholdsPass/fail criteria
Checks & Assertions
check(res, { 'status 200': (r) => r.status === 200, 'body size': (r) => r.body.length > 0, 'duration': (r) => r.timings.duration < 500, 'has header': (r) => r.headers['Content-Type'], });
Load Stages (Ramp Up/Down)
export const options = { stages: [ { duration: '2m', target: 100 }, // Ramp up to 100 users { duration: '5m', target: 100 }, // Stay at 100 users { duration: '2m', target: 0 }, // Ramp down to 0 ], };
Thresholds (Pass/Fail Criteria)
export const options = { thresholds: { http_req_duration: ['p(95)<500'], // 95% under 500ms http_req_failed: ['rate<0.01'], // Error rate under 1% checks: ['rate>0.99'], // 99% checks pass http_reqs: ['rate>100'], // Min 100 req/s }, };
Built-in Metrics
  • http_reqsTotal requests
  • http_req_durationResponse time
  • http_req_failedFailed requests
  • iterationsCompleted iterations
  • vusActive VUs
  • data_receivedData downloaded
POST JSON Data
const payload = JSON.stringify({ username: 'test', password: 'secret' }); const params = { headers: { 'Content-Type': 'application/json' } }; http.post(url, payload, params);
Output & Reporting
# Output to JSON k6 run --out json=results.json script.js # Output to InfluxDB k6 run --out influxdb=http://localhost:8086/k6 script.js # Output to CSV k6 run --out csv=results.csv script.js # Multiple outputs k6 run --out json=out.json --out influxdb=http://localhost:8086/k6 script.js

Convert a script — free, in your browser

JMeter, k6 and Gatling, any direction. Nothing is uploaded.

All 51 cheat sheets

Free to read and free to print — no signup. Want them as A4 PDFs you can print? Get all 51 as a PDF bundle for £14.99.
A Martkos IT reference sheet · Blog · Free tools