Skip to content

Instantly share code, notes, and snippets.

@simonespa
Created December 11, 2024 11:53
Show Gist options
  • Save simonespa/232ccc2e4987a995eabbc5c7cde7d4a9 to your computer and use it in GitHub Desktop.
Save simonespa/232ccc2e4987a995eabbc5c7cde7d4a9 to your computer and use it in GitHub Desktop.
K6 Load Testing
import http from "k6/http";
import { check } from "k6";
const URL = "https://example.com"; // Target URL
export let options = {
// If a cert is required to access the endpoint
//
// tlsAuth:
// [
// { domains: ['example.com'],
// cert: open('/etc/pki/tls/certs/client.crt'),
// key: open('/etc/pki/tls/private/client.key'),
// },
// ],
stages: [
{ duration: "30s", target: 256 },
{ duration: "120s", target: 256 },
],
maxRedirects: 0,
userAgent: "K6_Load_Testing_Script",
discardResponseBodies: true,
rps: 1000,
hosts: {
"example.com": "18.185.228.9" // Update the IP here, with a dns lookup on the appropriate OSIM url
}
};
export default function() {
const res = http.get(URL);
check(res, {
"Status was 200": (r) => {
return r.status === 200
}
});
};
k6 run --summary-trend-stats "min,avg,med,max,p(99),p(95),p(50)" ./loadtest.js; date
# Read https://grafana.com/docs/k6/latest/results-output/web-dashboard/
K6_WEB_DASHBOARD=true K6_WEB_DASHBOARD_EXPORT=html-report.html k6 run --summary-trend-stats "min,avg,med,max,p(99),p(95),p(50)" ./loadtest.js; date
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment