模拟压力场景
本节介绍如何在命令行模式中创建压力实验。
在创建压力实验前,可运行以下命令查看 Chaosd 支持的压力实验类型:
输出如下所示:
Usage:
chaosd attack stress [command]
Available Commands:
mem continuously stress virtual memory out
Flags:
-h, --help help for stress
Global Flags:
--log-level string the log level of chaosd, the value can be 'debug', 'info', 'warn' and 'error'
Use "chaosd attack stress [command] --help" for more information about a command.
目前 Chaosd 支持创建 CPU 压力实验和内存压力实验。
模拟 CPU 压力命令
运行以下命令可查看模拟 CPU 压力场景支持的配置:
chaosd attack stress cpu --help
continuously stress CPU out
Usage:
chaosd attack stress cpu [options] [flags]
Flags:
-h, --help help for cpu
-l, --load int Load specifies P percent loading per CPU worker. 0 is effectively a sleep (no load) and 100 is full loading. (default 10)
-o, --options strings extend stress-ng options.
-w, --workers int Workers specifies N workers to apply the stressor. (default 1)
Global Flags:
模拟 CPU 压力相关配置说明
模拟 CPU 压力示例
chaosd attack stress cpu --workers 2 --load 10
输出如下所示:
模拟内存压力命令
运行以下命令可查看模拟内存压力场景支持的配置:
chaosd attack stress mem --help
输出如下所示:
continuously stress virtual memory out
Usage:
chaosd attack stress mem [options] [flags]
Flags:
-h, --help help for mem
-o, --options strings extend stress-ng options.
-s, --size string Size specifies N bytes consumed per vm worker, default is the total available memory. One can specify the size as % of total available memory or in units of B, KB/KiB, MB/MiB, GB/GiB, TB/TiB..
Global Flags:
--log-level string the log level of chaosd, the value can be 'debug', 'info', 'warn' and 'error'
模拟内存压力相关配置说明
模拟内存压力示例
chaosd attack stress mem --workers 2 --size 100M
输出如下所示:
[2021/05/12 03:37:19.643 +00:00] [INFO] [stress.go:66] ["stressors normalize"] [arguments=" --vm 2 --vm-keep --vm-bytes 100000000"]
[2021/05/12 03:37:19.654 +00:00] [INFO] [stress.go:82] ["Start stress-ng process successfully"] [command="/usr/bin/stress-ng --vm 2 --vm-keep --vm-bytes 100000000"] [Pid=26799]
Attack stress mem successfully, uid: c2bff2f5-3aac-4ace-b7a6-322946ae6f13
使用服务模式创建压力实验
要使用服务模式创建实验,请进行以下操作:
向 Chaosd 服务的路径
/api/attack/stress
发送POST
HTTP 请求。curl -X POST 172.16.112.130:31767/api/attack/stress -H "Content-Type:application/json" -d '{fault-configuration}'
在上述命令中,你需要按照故障类型在 fault-configuration
中进行配置。有关对应的配置参数,请参考下文中各个类型故障的相关参数说明和命令示例。
注意
在运行实验时,请注意保存实验的 UID 信息。当要结束 UID 对应的实验时,需要向 Chaosd 服务的路径 /api/attack/{uid}
发送 DELETE
HTTP 请求。
模拟 CPU 压力相关参数说明
服务模式下模拟 CPU 压力示例
curl -X POST 172.16.112.130:31767/api/attack/stress -H "Content-Type:application/json" -d '{"load":10, "action":"cpu","workers":1}'
输出如下所示:
模拟内存压力相关参数说明
服务模式下模拟内存压力示例
curl -X POST 172.16.112.130:31767/api/attack/stress -H "Content-Type:application/json" -d '{"size":"100M", "action":"mem"}'