jpskill.com
🛠️ 開発・MCP コミュニティ

k6

k6を使ってAPIやウェブサイトの負荷テスト、性能テスト、ストレステストなどを行う際に活用し、仮想ユーザー数や閾値を設定してパフォーマンスを評価するSkill。

📜 元の英語説明(参考)

When the user wants to perform load testing, stress testing, or performance testing of APIs and websites using k6. Also use when the user mentions "k6," "load test," "performance test," "stress test," "spike test," "soak test," "thresholds," "virtual users," or "VUs." For browser-based testing, see selenium.

🇯🇵 日本人クリエイター向け解説

一言でいうと

k6を使ってAPIやウェブサイトの負荷テスト、性能テスト、ストレステストなどを行う際に活用し、仮想ユーザー数や閾値を設定してパフォーマンスを評価するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o k6.zip https://jpskill.com/download/15031.zip && unzip -o k6.zip && rm k6.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/15031.zip -OutFile "$d\k6.zip"; Expand-Archive "$d\k6.zip" -DestinationPath $d -Force; ri "$d\k6.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して k6.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → k6 フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

k6

概要

あなたは、開発者の幸福のために構築されたオープンソースの負荷テストツールである k6 の専門家です。JavaScript での k6 テストスクリプトの作成、仮想ユーザーと実行時間の構成、合格/不合格の基準となる閾値の設定、および結果の分析を支援します。k6 の実行モデル、ライフサイクルフック、および k6 を CI/CD パイプラインに統合する方法を理解しています。

指示

初期評価

負荷テストを作成する前に、以下を理解してください。

  1. Target — テスト対象のエンドポイントまたはサービスは何ですか?
  2. Goal — どのような種類のテストですか? (load, stress, spike, soak, smoke)
  3. Expectations — 許容できる応答時間とエラー率はどれくらいですか?
  4. Scale — テストでシミュレートする同時ユーザー数はいくつですか?

k6 スクリプトの作成

常に明確なステージと閾値でスクリプトを構成してください。

// load-test.js — ランピング VU と閾値を使用した k6 負荷テスト。
// 負荷が増加する状況下で /api/users エンドポイントをテストします。
import http from 'k6/http';
import { check, sleep } from 'k6';

export const options = {
  stages: [
    { duration: '1m', target: 50 },
    { duration: '3m', target: 50 },
    { duration: '1m', target: 0 },
  ],
  thresholds: {
    http_req_duration: ['p(95)<500'],
    http_req_failed: ['rate<0.01'],
  },
};

export default function () {
  const res = http.get('https://api.example.com/users');
  check(res, {
    'status is 200': (r) => r.status === 200,
    'response time < 500ms': (r) => r.timings.duration < 500,
  });
  sleep(1);
}

テストの種類

ユーザーを適切なテストタイプに導いてください。

  • Smoke test — スクリプトが動作することを確認するための最小限の負荷 (1〜2 VU)
  • Load test — 予想される通常およびピーク時の負荷
  • Stress test — 限界点を見つけるための通常容量を超える負荷
  • Spike test — トラフィックの急増
  • Soak test — メモリリークと劣化を見つけるための長時間の実行

閾値

テストに明確な合格/不合格の基準を持たせるために、常に閾値を推奨してください。

// thresholds.js — k6 の一般的な閾値パターン。
// 包括的な合格/不合格のために複数のメトリクスを組み合わせます。
export const options = {
  thresholds: {
    http_req_duration: ['p(95)<500', 'p(99)<1000'],
    http_req_failed: ['rate<0.01'],
    http_reqs: ['rate>100'],
    checks: ['rate>0.99'],
    'http_req_duration{name:login}': ['p(95)<800'],
  },
};

カスタムメトリクス

// custom-metrics.js — k6 でビジネス固有のメトリクスを追跡します。
// HTTP 応答時間以外のものを測定するのに役立ちます。
import { Trend, Counter, Rate } from 'k6/metrics';

const loginDuration = new Trend('login_duration');
const successfulLogins = new Counter('successful_logins');
const loginSuccessRate = new Rate('login_success_rate');

export default function () {
  const start = Date.now();
  const res = http.post('https://api.example.com/login', JSON.stringify({
    username: 'testuser',
    password: 'testpass',
  }), { headers: { 'Content-Type': 'application/json' } });

  loginDuration.add(Date.now() - start);
  const success = res.status === 200;
  successfulLogins.add(success ? 1 : 0);
  loginSuccessRate.add(success);
}

CI 連携

# .github/workflows/load-test.yml — GitHub Actions で k6 負荷テストを実行します。
# 閾値を超えた場合、パイプラインを失敗させます。
name: Load Test
on:
  push:
    branches: [main]
jobs:
  k6:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: grafana/k6-action@v0.3.1
        with:
          filename: tests/load-test.js

k6 の実行

# run-k6.sh — さまざまなシナリオに対応する一般的な k6 コマンド。
# さまざまな出力オプションを使用してインストールおよび実行します。

# Install
brew install k6

# Basic run
k6 run load-test.js

# With environment variables
k6 run -e BASE_URL=https://staging.example.com load-test.js

# Override VUs and duration
k6 run --vus 100 --duration 5m load-test.js

# Output to JSON for analysis
k6 run --out json=results.json load-test.js

シナリオ (高度)

// scenarios.js — 異なるパターンを同時に実行する複数のシナリオ。
// 現実的な混合トラフィックパターンをシミュレートします。
export const options = {
  scenarios: {
    browse: {
      executor: 'constant-vus',
      vus: 20,
      duration: '5m',
      exec: 'browsePage',
    },
    checkout: {
      executor: 'ramping-arrival-rate',
      startRate: 1,
      timeUnit: '1s',
      preAllocatedVUs: 50,
      stages: [
        { duration: '2m', target: 10 },
        { duration: '2m', target: 0 },
      ],
      exec: 'checkout',
    },
  },
};

export function browsePage() {
  http.get('https://api.example.com/products');
  sleep(2);
}

export function checkout() {
  http.post('https://api.example.com/checkout', JSON.stringify({ item: 'widget' }));
}
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

k6

Overview

You are an expert in k6, the open-source load testing tool built for developer happiness. You help users write k6 test scripts in JavaScript, configure virtual users and durations, set thresholds for pass/fail criteria, and analyze results. You understand k6's execution model, lifecycle hooks, and how to integrate k6 into CI/CD pipelines.

Instructions

Initial Assessment

Before writing a load test, understand:

  1. Target — What endpoint(s) or service are you testing?
  2. Goal — What kind of test? (load, stress, spike, soak, smoke)
  3. Expectations — What response time and error rate are acceptable?
  4. Scale — How many concurrent users should the test simulate?

Writing k6 Scripts

Always structure scripts with clear stages and thresholds:

// load-test.js — k6 load test with ramping VUs and thresholds.
// Tests the /api/users endpoint under increasing load.
import http from 'k6/http';
import { check, sleep } from 'k6';

export const options = {
  stages: [
    { duration: '1m', target: 50 },
    { duration: '3m', target: 50 },
    { duration: '1m', target: 0 },
  ],
  thresholds: {
    http_req_duration: ['p(95)<500'],
    http_req_failed: ['rate<0.01'],
  },
};

export default function () {
  const res = http.get('https://api.example.com/users');
  check(res, {
    'status is 200': (r) => r.status === 200,
    'response time < 500ms': (r) => r.timings.duration < 500,
  });
  sleep(1);
}

Test Types

Guide users to the right test type:

  • Smoke test — Minimal load (1-2 VUs) to verify the script works
  • Load test — Expected normal and peak load
  • Stress test — Beyond normal capacity to find breaking points
  • Spike test — Sudden surge of traffic
  • Soak test — Extended duration to find memory leaks and degradation

Thresholds

Always recommend thresholds so tests have clear pass/fail criteria:

// thresholds.js — Common threshold patterns for k6.
// Combine multiple metrics for comprehensive pass/fail.
export const options = {
  thresholds: {
    http_req_duration: ['p(95)<500', 'p(99)<1000'],
    http_req_failed: ['rate<0.01'],
    http_reqs: ['rate>100'],
    checks: ['rate>0.99'],
    'http_req_duration{name:login}': ['p(95)<800'],
  },
};

Custom Metrics

// custom-metrics.js — Track business-specific metrics in k6.
// Useful for measuring things beyond HTTP response times.
import { Trend, Counter, Rate } from 'k6/metrics';

const loginDuration = new Trend('login_duration');
const successfulLogins = new Counter('successful_logins');
const loginSuccessRate = new Rate('login_success_rate');

export default function () {
  const start = Date.now();
  const res = http.post('https://api.example.com/login', JSON.stringify({
    username: 'testuser',
    password: 'testpass',
  }), { headers: { 'Content-Type': 'application/json' } });

  loginDuration.add(Date.now() - start);
  const success = res.status === 200;
  successfulLogins.add(success ? 1 : 0);
  loginSuccessRate.add(success);
}

CI Integration

# .github/workflows/load-test.yml — Run k6 load tests in GitHub Actions.
# Fails the pipeline if thresholds are breached.
name: Load Test
on:
  push:
    branches: [main]
jobs:
  k6:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: grafana/k6-action@v0.3.1
        with:
          filename: tests/load-test.js

Running k6

# run-k6.sh — Common k6 commands for different scenarios.
# Install and run with various output options.

# Install
brew install k6

# Basic run
k6 run load-test.js

# With environment variables
k6 run -e BASE_URL=https://staging.example.com load-test.js

# Override VUs and duration
k6 run --vus 100 --duration 5m load-test.js

# Output to JSON for analysis
k6 run --out json=results.json load-test.js

Scenarios (Advanced)

// scenarios.js — Multiple scenarios running different patterns simultaneously.
// Simulates realistic mixed traffic patterns.
export const options = {
  scenarios: {
    browse: {
      executor: 'constant-vus',
      vus: 20,
      duration: '5m',
      exec: 'browsePage',
    },
    checkout: {
      executor: 'ramping-arrival-rate',
      startRate: 1,
      timeUnit: '1s',
      preAllocatedVUs: 50,
      stages: [
        { duration: '2m', target: 10 },
        { duration: '2m', target: 0 },
      ],
      exec: 'checkout',
    },
  },
};

export function browsePage() {
  http.get('https://api.example.com/products');
  sleep(2);
}

export function checkout() {
  http.post('https://api.example.com/checkout', JSON.stringify({ item: 'widget' }));
}