tips:系统提前搭建好Docker平台,参考CentOS 7 搭建Docker平台
docker run -d --name influxdb -p 8086:8086 \
-e INFLUXDB_DB=db0 \ # 初始数据库,可以自定义名字
-e INFLUXDB_ADMIN_USER=admin -e INFLUXDB_ADMIN_PASSWORD=Ghost=123! \ #管理用户和密码
-e INFLUXDB_USER=telegraf -e INFLUXDB_USER_PASSWORD=Ghost=123 \ # 普通用户和密码
-v /opt/influxdb/:/var/lib/influxdb \ # 数据库文件持久化
influxdb
更多docker环境配置选项见DockerHub页面:https://hub.docker.com/_/influxdb
如果需要修改配置文件,可以拷贝配置到物理机进行修改后,再挂载到influxdb容器中
# 拷贝配置文件到/opt/influxdb/conf/influxdb.conf
docker cp influxdb:/etc/influxdb/influxdb.conf /opt/influxdb/conf/influxdb.conf
或者进入容器进行修改
docker exec -it influxdb /bin/bash # 进入容器
vi /etc/influxdb/influxdb.conf # 打开配置文件进行修改
tips:教程参考官网https://k6.io/docs/results-visualization/influxdb-±grafana
docker run -d \
--name=grafana \
-p 3000:3000 \
-v /opt/grafana/data:/var/lib/grafana \ # grafana数据持久化
-v /opt/grafana/conf:/etc/grafana \ # grafana配置文件目录
-v /opt/grafana/logs:/var/log/grafana \ # 日志文件目录
grafana/grafana
浏览器访问:http:// IP:3000进入grafana界面,切记是http不是https
输入用户名:admin,密码:admin进入主界面
模板地址参考grafana官方网站:https://grafana.com/grafana/dashboards/2587
参考官方文档:https://k6.io/docs/getting-started/installation
docker平台无需安装直接运行命令即可自动下载运行
docker run -i loadimpact/k6 run - <script.js
# script.js 为测试代码
Windows平台直接下载安装后在命令行运行(没有界面)
Windows软件下载:https://dl.bintray.com/loadimpact/windows/k6-v0.30.0-amd64.msi
此处在Windows平台演示测试
import http from 'k6/http';
import { sleep } from 'k6';
export default function () {
http.get('http://test.k6.io');
sleep(1);
}
更多测试代码请参考k6文档:https://k6.io/docs/using-k6/http-requests
命令行运行测试代码:
k6 run --out influxdb=http://localhost:8086/grafana script.js
# grafana为数据库地址
/\ |‾‾| /‾‾/ /‾‾/
/\ / \ | |/ / / /
/ \/ \ | ( / ‾‾\
/ \ | |\ \ | (‾) |
/ __________ \ |__| \__\ \_____/ .io
execution: local
script: 1、http请求\1_get.js
output: -
scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
* default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)
running (00m00.3s), 0/1 VUs, 1 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs 00m00.3s/10m0s 1/1 iters, 1 per VU
data_received..............: 16 kB 54 kB/s
data_sent..................: 527 B 1.8 kB/s
http_req_blocked...........: avg=165.26ms min=165.26ms med=165.26ms max=165.26ms p(90)=165.26ms p(95)=165.26ms
http_req_connecting........: avg=34.9ms min=34.9ms med=34.9ms max=34.9ms p(90)=34.9ms p(95)=34.9ms
http_req_duration..........: avg=93.52ms min=93.52ms med=93.52ms max=93.52ms p(90)=93.52ms p(95)=93.52ms
http_req_receiving.........: avg=25.93ms min=25.93ms med=25.93ms max=25.93ms p(90)=25.93ms p(95)=25.93ms
http_req_sending...........: avg=0s min=0s med=0s max=0s p(90)=0s p(95)=0s
http_req_tls_handshaking...: avg=120.38ms min=120.38ms med=120.38ms max=120.38ms p(90)=120.38ms p(95)=120.38ms
http_req_waiting...........: avg=67.59ms min=67.59ms med=67.59ms max=67.59ms p(90)=67.59ms p(95)=67.59ms
http_reqs..................: 1 3.40419/s
iteration_duration.........: avg=277.66ms min=277.66ms med=277.66ms max=277.66ms p(90)=277.66ms p(95)=277.66ms
iterations.................: 1 3.40419/s