Load testing scripts and examples written with Grafana k6. Covers practical examples from basic concepts to scenario-based tests, custom metrics, and threshold definitions.
- k6 must be installed
# macOS (Homebrew)
brew install k6
# Linux (deb/rpm)
# https://k6.io/docs/get-started/installation/| File / Folder | Description |
|---|---|
first-script.js |
Getting started: simple GET request and VU/duration options |
load-test.js |
Staged load test example |
stress-test.js |
Stress test |
soak-test.js |
Soak (endurance) test |
spike-test.js |
Spike test |
smoke-test.js |
Smoke test |
breakpoint-test.js |
Breakpoint test |
lifecycle.js |
setup / teardown and VU lifecycle |
scenarious.js |
Scenarios and threshold examples |
assertions.js |
Using assertions with check() |
definingThresholdsGroups.js |
Threshold groups |
settingThresholds.js |
Defining thresholds |
customMetrics.js / custom-metrics.js |
Custom metrics |
customTags.js / tags.js |
Tag usage |
validationResponses.js |
Response validation |
organizRequestGroups.js |
Request groups |
requests/ |
HTTP method examples (GET, POST, PUT, PATCH, DELETE) |
Run a simple script:
k6 run first-script.jsStaged load test:
k6 run load-test.jsStress test:
k6 run stress-test.jsTo inspect HTTP requests in detail:
# Basic debug
k6 run --http-debug requests/getRequests.js
# Include response body
k6 run --http-debug="full" requests/getRequests.js- VUs and duration:
options.vus,options.duration - Stages: Gradual load ramp-up and ramp-down
- Thresholds:
http_req_duration,http_req_failed,checks, etc. - Checks: Validating status codes and response content with
check() - Setup/Teardown: Pre- and post-test logic
- Custom metrics:
Trend,Counter,Rateexamples - Tags: Tagging requests and metrics
This repository contains example scripts for learning and reference.