grafana K6压测

打印 上一主题 下一主题

主题 967|帖子 967|积分 2901

https://grafana.com/docs/k6/latest/get-started
install and run


  • install
  1. # mac
  2. brew install k6
复制代码

  • 当前目录下生成压测脚本
  1. # create file script.js
  2. k6 new [filename]     # create file ‘script.js’ in the current directory
复制代码
3 run
  1. k6 run script.js
复制代码

  • reports
    默认环境下,k6 将总结结果打印到 stdout 。
script.js

  1. import http from 'k6/http';
  2. import { check, sleep } from 'k6';
  3. export const options = {
  4.   vus: 10,
  5.   duration: '30s',
  6. };
  7. export default function () {
  8.   const res = http.get('http://test.k6.io');
  9.   check(res, { 'status was 200': (r) => r.status == 200 });
  10.   sleep(1);
  11. }
复制代码
options

https://grafana.com/docs/k6/latest/using-k6/k6-options/reference/


  • vus
    虚拟用户数
  • duration
    连续时间
  • rps
    每秒哀求数量
   哀求总数 = vus * rps * durance(s)
  1. import http from 'k6/http';
  2. import { check, sleep } from 'k6';
  3. export const options = {
  4.   maxRedirects: 4,
  5.   duration: '300s',
  6.   vus: 10,
  7.   rps: 300
  8. };
  9. // stages : 逐步提升/降低
  10. export const options = {
  11.   stages: [
  12.     { target: 200, duration: '30s' },
  13.     { target: 0, duration: '30s' },
  14.   ],
  15. };
  16. export const options = {
  17.   stages: [
  18.     { duration: '10s', target: 100 },
  19.     { duration: '5m', target: 100 },
  20.     { duration: '10s', target: 0 },
  21.   ],
  22.   rps: 100,
  23. };
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

笑看天下无敌手

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表