k6의 사용자 지정 메트릭 및 추세
k6에서 직접 Counter, Gauge, Rate, Trend 메트릭을 정의하여 고급 시나리오에서 중요한 항목을 정확히 측정합니다.
k6의 사용자 지정 메트릭 및 추세은(는) CoddyKit의 무료 Load Testing & Performance Benchmarking (JMeter & k6) 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Load Testing & Performance Benchmarking (JMeter & k6) 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Load Testing & Performance Benchmarking (JMeter & k6) 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Beyond Built-in Metrics
k6 ships with built-in metrics like http_req_duration, but advanced tests often need to measure domain-specific values: items in a cart, business transaction time, or a custom error rate. k6 lets you create custom metrics.
The Four Metric Types
k6 offers four custom metric types from k6/metrics:
- Counter — cumulative sum.
- Gauge — last recorded value.
- Rate — percentage of non-zero/true values.
- Trend — statistics like min, max, avg, p95.
Importing Metric Constructors
Import the constructors you need and create the metric objects in module scope so they are shared across iterations.
import { Counter, Trend, Rate, Gauge } from 'k6/metrics';A Counter Example
A Counter accumulates a value over the whole test. Here we count how many orders were created.
const ordersCreated = new Counter('orders_created');
export default function () {
ordersCreated.add(1);
}A Trend for Timing
A Trend collects a series of numbers and reports statistics. It is ideal for timing custom logic.
import http from 'k6/http';
const loginTime = new Trend('login_time');
export default function () {
const res = http.post('https://test.k6.io/login');
loginTime.add(res.timings.duration);
}A Rate for Success Ratio
A Rate tracks how often a condition is true. Add true or false and k6 reports the percentage of trues.
const successRate = new Rate('success_rate');
successRate.add(res.status === 200);A Gauge for Last Value
A Gauge keeps only the most recent value you add. Use it for things like the current queue length reported by an endpoint.
const queueDepth = new Gauge('queue_depth');
queueDepth.add(42);Tagging Custom Metrics
Just like built-in metrics, you can attach tags when adding a value. This lets you slice your custom metric by endpoint or feature.
loginTime.add(res.timings.duration, { region: 'eu' });Thresholds on Custom Metrics
Custom metrics integrate fully with thresholds. You can fail a run if your business metric crosses a limit.
export const options = {
thresholds: {
login_time: ['p(95)<500'],
success_rate: ['rate>0.98'],
},
};Reading Custom Metrics in Summary
At the end of a run, custom metrics appear in the end-of-test summary alongside built-in ones, showing the appropriate statistics for their type.
k6 run scenario.jsChoosing the Right Type
Picking the correct metric type matters: use a Trend for durations, a Rate for success ratios, a Counter for totals, and a Gauge for snapshot values. The wrong type gives misleading summaries.
Quick Check
Pick the right metric type for the job.
Recap
You can now extend k6 with custom metrics.
Countersums,Gaugekeeps the last value,Ratetracks ratios,Trendreports stats.- Add tags and thresholds to custom metrics for targeted SLOs.
- They appear in the summary and any output backend.
AI 튜터와 함께 Load Testing & Performance Benchmarking (JMeter & k6)을(를) 배우세요 — 무료
브라우저에서 실제 코드를 작성하고 실행하며, 24/7 AI 튜터로부터 즉각적인 도움을 받고, 웹이나 앱에서 중단한 부분부터 계속 학습하세요.
- 코스
- 12
- 레슨
- 48
자주 묻는 질문
“k6의 사용자 지정 메트릭 및 추세” 강의는 무료인가요?
네 — “k6의 사용자 지정 메트릭 및 추세” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Load Testing & Performance Benchmarking (JMeter & k6) 강의 전체를 잠금 해제할 수 있습니다. Load Testing & Performance Benchmarking (JMeter & k6) 강의에는 총 4개의 강의가 포함되어 있습니다.
“k6의 사용자 지정 메트릭 및 추세”에서 뭘 배우나요?
k6에서 직접 Counter, Gauge, Rate, Trend 메트릭을 정의하여 고급 시나리오에서 중요한 항목을 정확히 측정합니다. 브라우저에서 직접 실행하는 실습 코드로 Load Testing & Performance Benchmarking (JMeter & k6)을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Load Testing & Performance Benchmarking (JMeter & k6)을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Load Testing & Performance Benchmarking (JMeter & k6)은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.
“k6의 사용자 지정 메트릭 및 추세” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Load Testing & Performance Benchmarking (JMeter & k6) 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Load Testing & Performance Benchmarking (JMeter & k6) 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- 가상 사용자 시나리오(VU)
- k6에서의 데이터 매개변수화
- k6를 활용한 클라우드 실행
- k6의 사용자 지정 메트릭 및 추세