【Chaos Mesh官方文档】(Physical Machine)Simulate Stress Scenarios

总目录

  1. 读我
  2. 关于CM
    CM介绍:这篇文档介绍ChaosMesh的概念,用例,核心优势和架构
    基本功能:这篇文档描述了CM的基本特性,包括错误注入,混沌工作流,可视化操作和安全保证
  3. 安装&部署
    快速开始:这篇文章介绍如何在测试或本地环境开始CM
    使用Helm安装:这篇文章讲如何在生产环境安装CM
    离线安装:这份文档讲如何离线安装CM
    卸载CM:这篇文档讲如何卸载CM,包括使用helm卸载或手工卸载
  4. 管理用户许可:这篇文章讲如何在CM中管理用户许可,包括创建不同角色的用户账号,绑定许可,管理令牌,启用或停用许可授权
  5. 配置混沌实验命名空间:这个章节带你在指定的命名空间配置混沌实验,从而避免其他没有指定的命名空间里注入错误
  6. 运行一个混沌实验
    定义混沌实验范围:这篇文档讲如何定义混沌实验的范围从而精确的控制混沌错误爆炸范围
    定义调度规则:这篇文档讲如何使用CM创建调度任务,从而在一个固定时间创建混沌实验
    运行混沌实验:这篇文档讲如何在CM中创建,运行,观察,暂停,更新和删除混沌实验
    查看混沌实验结果:这篇文档讲如何使用CM查看混沌实验的运行状态和结果
  7. 编排多个混沌实验
    创建CM工作流:
    并行&串行实验
    向工作流发送HTTP请求:类似K8s Job,CM工作流对任何任务都支持任务节点,为了让用户体验更方便,CM在web界面提供一个基于Task的模板创建HTTP请求
    检查工作流状态:
  8. 混沌实验类型
    • Kubernetes
      • Pod错误:这篇文档讲如何使用CM将错误注入pod中从而模拟pod或容器错误
      • 网络错误:这篇文章讲如何使用NetworkChaos模拟网络错误
      • 压力场景:CM提供StressChaos在容器内模拟压力场景,这篇文章将如何创建StressChaos实验和准备相应配置文件
      • 文件IO错误:这篇文档讲如何使用CM创建IO混沌
      • DNS错误:这篇文档讲如何在CM中创建DNS混沌实验从而模拟DNS错误
      • 时间错误:CM提供TimeChaos实验类型,你可以使用这个类型模拟时间偏移场景,这篇文章讲如何创建一个TimeChaos实验及相关配置文件
      • JVM应用错误:
      • Linux内核错误:这篇文章讲如何使用KernelChaos模拟内核错误,这个特性使用BPF在内核相关路径注入IO相关,内存相关错误
      • HTTP错误:这篇文章讲如何通过CM创建HTTPChaos来模拟HTTP错误
    • 物理节点
      • Chaosd介绍:Chaosd是CM提供的混沌引擎测试工具
      • 物理机错误:这篇文档讲如何通过CM制造物理机混沌来在物理机或虚拟机上模拟网络,硬盘,时间,jvm等错误
      • 进程错误:这篇文章讲如何使用chaosd模拟进程错误,这个错误使用go语言提供的杀死指令来模拟进程被杀死或停止的场景
      • 网络错误:这篇文章讲如何使用chaosd模拟网络错误,这个模拟可以使用 iptables, ipsets, tc等通过修改路由和流量控制来完成
      • 宿主机错误:这篇文章讲如何使用chaosd模拟宿主机关闭的错误
      • 压力场景:这篇文章讲如何使用chaosd模拟压力场景,这个特性使用stress-ng在宿主机上产生CPU和内存压力
      • 硬盘错误:这篇文章讲如何通过Chaosd来模拟硬盘错误,这个特性帮助你模拟硬盘读写负载(通过dd)和硬盘填充(通过dd或者fallocate)
      • JVM应用错误:chaosd使用Byteman模拟jvm错误
      • 时间错误:这篇文章描述如何使用chaosd模拟时间偏移的场景.你可以通过命令行模式或者服务模式创建该场景
      • 查找和恢复Chaosd实验:你可以通过条件来查找实验并通过Chaosd使用UID来恢复实验.这篇文档讲如何通过chaosd查找和恢复实验并提供相关例子

正文

This document describes how to use Chaosd to simulate stress scenarios. This feature generates CPU or memory stress on the host using stress-ng. You can create stress experiments either in command-line or service mode.
这篇文章讲如何使用chaosd模拟压力场景,这个特性使用stress-ng在宿主机上产生CPU和内存压力.你可以使用命令行或者服务模式创建压力实验.

Create stress experiments using the command-line mode​通过命令行创建压力实验

This section describes how to create stress experiments using the command-line mode.
这一节描述如何使用命令行模式创建压力实验
Before creating stress experiments, you can run the following command to view the stress experiment types supported by Chaosd:
在创建压力试验前,你可以通过运行下面命令查看Chaosd支持的压力试验类型

chaosd attack stress --help

The result is as follows:
结果如下

Stress attack related commands

Usage:
  chaosd attack stress [command]

Available Commands:
  cpu         continuously stress CPU out
  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.

Currently, Chaosd supports creating CPU stress experiments and memory stress experiments.
当前,Chaosd支持创建CPU压力实验和内存压力试验

Simulate CPU stress using the command-line mode​使用命令行模式模拟CPU压力

Command for simulating CPU stress​模拟CPU压力指令

To view the configuration items supported by the CPU stress simulation, run the following command:
运行下列指令来查看CPU压力模拟支持的配置项

chaosd attack stress cpu --help

The result is as follows:
结果如下:

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:
      --log-level string   the log level of chaosd, the value can be 'debug', 'info', 'warn' and 'error'
Configuration description for simulating CPU stress​模拟CPU压力的配置项描述
Configuration item配置项Abbreviation/缩写Description描述Value
load负载lSpecifies the percentage of CPU load per CPU worker. 0 means no CPU utilization, and 100 means full CPU utilization.指定每一个CPU的负载百分比,0表示没有CPU负载,100表示满负载int Range: 0 to 100; Default value: 10.整型,范围0100;默认值10
workers工作者wSpecifies the number of workers used to create CPU stress.指定用于创建CPU压力的工作者int Default value: 1.整型,默认值1
options选项oThe extended parameter of stress-ng, usually not configured.stress-ng的扩展参数,一般不配置string Default value: “”.字符串,默认值""
Example for simulating CPU stress​模拟CPU压力的例子
chaosd attack stress cpu --workers 2 --load 10

The result is as follows:
结果如下:

[2021/05/12 03:38:33.698 +00:00] [INFO] [stress.go:66] ["stressors normalize"] [arguments=" --cpu 2 --cpu-load 10"]
[2021/05/12 03:38:33.702 +00:00] [INFO] [stress.go:82] ["Start stress-ng process successfully"] [command="/usr/bin/stress-ng --cpu 2 --cpu-load 10"] [Pid=27483]
Attack stress cpu successfully, uid: 4f33b2d4-aee6-43ca-9c43-0f12867e5c9c

Simulating memory stress using the command-line mode​使用命令行模式模拟内存压力

Command for simulating memory stress​模拟内存压力指令

To view the configuration items supported by the memory stress simulation, run the following command:
运行以下指令查看模拟内存压力支持的配置项

chaosd attack stress mem --help

The result is as follows:
结果如下

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'
Configuration description for simulating memory stress​模拟内存压力的配置描述
Configuration item配置项Abbreviation/缩写Description描述Value
size大小sSpecifies the size of memory per VM worker.指明每个VM工作者使用内存大小string The memory size in B, KB/KiB, MB/MiB, GB/GiB, TB/TiB. If the size is not set, all available memory is used by default.字符串.使用B,KB/KiB,MB/MiB,GB/GiB,TB/TiB.如果这个大小没有设置,默认情况下所有可用内存都被使用
options选项oThe extended parameter of stress-ng, usually not configured.string Default value: “”.
Example for simulating memory stress​模拟内存压力示例
chaosd attack stress mem --workers 2 --size 100M

The result is as follows:
结果如下

[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

When running the experiment, you need to save the uid information of the experiment. When a stress simulation is not needed, you can use recover to terminate the uid-related experiment::
当运行这个实验,你需要保存实验的uid信息.当一个模拟压力不需要的时候,你可以停止uid相关实验来恢复

chaosd recover c2bff2f5-3aac-4ace-b7a6-322946ae6f13

The result is as follows:
结果如下

Recover c2bff2f5-3aac-4ace-b7a6-322946ae6f13 successfully

Create stress experiments using the service mode​使用服务模式创建压力实验

To create experiments using the service mode, follow the instructions below:
遵循以下知道来使用服务模式创建实验

  1. Run Chaosd in service mode:
    以服务模式运行Chaosd
chaosd server --port 31767
  1. Send a POST HTTP request to the /api/attack/{uid} path of Chaosd service.
    向Chaosd服务的/api/attack/{uid}发送一个HTTP POST请求
curl -X POST 172.16.112.130:31767/api/attack/jvm -H "Content-Type:application/json" -d '{fault-configuration}'

For the fault-configuration part in the above command, you need to configure it according to the fault types. For the corresponding parameters, refer to the parameters and examples of each fault type in the following sections.
对于上面指令的fault-configuration部分你需要遵循故障类型来配置.对于对应参数,参见下列各个故障类型章节的参数和例子

note

When running an experiment, remember to save the UID information of the experiment. When you want to kill the experiment corresponding to the UID, you need to send a DELETE HTTP request to the /api/attack/{uid} path of Chaosd service.

注意

当运行一个实验,记着保存这个实验的uid信息.当你想杀死uid对应的实验,你需要发送一个DELETE请求到Chaosd服务的/api/attack/{uid}路径

Simulate CPU stress using the service mode​使用服务模式模拟CPU压力

Parameters for simulating CPU stress​
模拟CPU压力参数

Parameter/参数Description描述Type类型Value
actionActions of the experiment实验的行为Set to “cpu”设置为cpu
load负载Specifies the percentage of CPU load per CPU worker. 0 means no CPU utilization, and 100 means full CPU utilization.intRange: 0 to 100; Default value: 10
workersSpecifies the number of workers used to create CPU stressintDefault value: 1
optionsThe extended parameter of stress-ng, usually not configured.stringDefault value: “”
Example for simulating CPU stress using the service mode​使用服务模式模拟CPU压力示例
curl -X POST 172.16.112.130:31767/api/attack/stress -H "Content-Type:application/json" -d '{"load":10, "action":"cpu","workers":1}'

The result is as follows:
结果如下

{"status":200,"message":"attack successfully","uid":"c3c519bf-819a-4a7b-97fb-e3d0814481fa"}

Simulate memory stress using the service mode​使用服务模式模拟内存压力

Parameters for simulating memory stress​
模拟内存压力参数

Parameter/参数Description描述Type类型Value
actionActions of the experimentSet to “mem”
sizeSpecifies the size of memory per VM workerstringthe memory size in B, KB/KiB, MB/MiB, GB/GiB, TB/TiB. If the size is not set, all available memory is used by default.
optionsThe extended parameter of stress-ng, usually not configured.stringDefault value: “”
Example for simulating memory stress using the service mode​使用服务模式模拟内存压力示例
curl -X POST 172.16.112.130:31767/api/attack/stress -H "Content-Type:application/json" -d '{"size":"100M", "action":"mem"}'

The result is as follows:
结果如下

{"status":200,"message":"attack successfully","uid":"a551206c-960d-4ac5-9056-518e512d4d0d"}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值