blade server
后台启动 blade,会暴露出 web 服务,上层可通过 http 调用

介绍

在 server 模式下,blade 程序会对外暴露 web 服务,上层可通过 http 请求调用,请求格式是 chaosblade?cmd=具体命令,例如执行 CPU 满载,则请求是 chaosblade?cmd=create%20cpu%20fullload

命令

1
start 启动 server 模式, 暴露 web 服务
2
stop 停止 server 模式, 关闭 web 服务
Copied!

start 命令参数

1
-p, --port string 服务端口号,默认是 9526
Copied!

案例

1
# 启动 server 模式,服务端口是 8080
2
blade server start --port 8080
3
success, listening on 8080
4
5
# 触发 CPU 负载 50% 场景
6
curl "http://xxx.xxx.xxx.xxx:8080/chaosblade?cmd=create%20cpu%20load%20--cpu-percent%2050"
7
8
{"code":200,"success":true,"result":"e08a64a9af02c393"}
9
10
# 销毁实验场景
11
curl "http://xxx.xxx.xxx.xxx:8080/chaosblade?cmd=destroy%20e08a64a9af02c393"
12
13
# 停止 blade server
14
blade server stop
15
16
{"code":200,"success":true,"result":"pid is 12619"}
Copied!

实现原理

待补充

常见问题

Q: {"code":605,"success":false,"error":"the chaosblade has been started. If you want to stop it, you can execute blade server stop command"} A:服务已经启动
Q: {"code":500,"success":false,"error":"time="2019-09-25T11:36:28.321495762+08:00" level=error msg="start blade server error, listen tcp :8080: bind: address already in use"\n"} A:端口已被占用
Last modified 4d ago