k6 + InfluxDB + Grafana 를 활용한 부하 테스트 및 시각화
참고: https://k6.io/docs/results-visualization/influxdb-+-grafana
- k6 활용
- 설치, 실행 등 세부 사항은 https://k6.io/docs/ 참고
brew install k6
POST 요청 부하 테스트 용 js 파일 작성
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
vus: 100, // Virtual Users (동시 사용자)
duration: '10s',
};
const randomStrGen = () => Math.random().toString(36).substring(2);
const randomPhoneNumGet = () => {
const phoneNum = Math.floor(1000000000 + Math.random() * 9000000000).toString();
return phoneNum.substring(0, 3) + '-' + phoneNum.substring(3, 6) + '-' + phoneNum.substring(6)
}
export default function() {
const url = 'http://localhost:8080/v1/sellers';
const body = JSON.stringify({
"name": randomStrGen(),
"email": `${randomStrGen()}@test.com`,
"phone": `${randomPhoneNumGet()}`,
"loginId": randomStrGen(),
"password": randomStrGen()
});
const params = {
headers: {
'Content-Type': 'application/json',
},
};
const res = http.post(url, body, params);
check(res, {
'status was 200': r => r.status === 200,
'tx time OK': r => r.timings.duration < 500 // 값을 변경하면서 테스트 해보면 재미있긔~
});
}
k6 run k6-post.js
- application.yml 에서
server.tomcat.max-threads
값을 변경하면서 테스트 해보면 재미있긔~
사설 인증서를 사용하는 개발환경에서는 다음과 같은 에러가 발생한다.
x509: certificate is not valid for any names, but wanted to match localhost"
또는
x509: cannot validate certificate for 127.0.0.1 because it doesn't contain any IP SANs"
또는
x509: certificate signed by unknown authority"
이때는 --insecure-skip-tls-verify
옵션을 사용해서 인증서 유효성 검증 과정을 건너뛰게 하면 된다.
k6 run --insecure-skip-tls-verify k6-post.js
brew install influxdb
influxd -config /usr/local/etc/influxdb.conf
종료는 그냥 CTRL+C
brew install grafana
brew services start grafana
localhost:3000
- default username/password: admin/admin
-
커스텀 대시보드를 만들 수도 있지만 k6 문서에서 추천한 Preconfigured Grafana Dashboard 중에서 k m 사용
-
테스트 실행 결과를 influxdb로 전송
k6 run --out influxdb=http://localhost:8086/myk6db k6-post.js
-
대시보드 refresh
brew services stop grafana