跳至主内容
版本:下一版本

模拟进程故障

非官方测试版翻译

本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →

本文档介绍如何使用 Chaosd 模拟进程故障。进程故障通过调用 kill 命令的 Golang 接口,模拟进程被终止或停止的场景。您可以通过命令行模式或服务模式创建实验。

使用命令行模式创建实验

在创建实验前,您可以运行以下命令查看 Chaosd 支持的进程故障类型:

chaosd attack process -h

结果如下:

Process attack related commands

Usage:
chaosd attack process [command]

Available Commands:
kill kill process, default signal 9
stop stop process, this action will stop the process with SIGSTOP

Flags:
-h, --help help for process

Global Flags:
--log-level string the log level of chaosd, the value can be 'debug', 'info', 'warn' and 'error'

Use "chaosd attack process [command] --help" for more information about a command.

目前,Chaosd 支持模拟进程被终止或停止的场景。

通过命令行模式终止进程

终止进程命令

chaosd attack process kill -h

结果如下:

kill process, default signal 9

Usage:
chaosd attack process kill [flags]

Flags:
-h, --help help for kill
-p, --process string The process name or the process ID
-r, --recover-cmd string The command to be run when recovering experiment
-s, --signal int The signal number to send (default 9)

Global Flags:
--log-level string the log level of chaosd. The value can be 'debug', 'info', 'warn' and 'error'
--uid string the experiment ID

终止进程配置说明

Configuration itemAbbreviationDescriptionValue
processpThe name or the identifier of the process to be injected faultsstring; the default value is "".
recover-cmdrThe command to be run when recovering experimentstring; the default value is "".
signalsThe provided value of the process signalint; the default value is 9. Currently, only SIGKILL, SIGTERM, and SIGSTOP are supported.

终止进程示例

chaosd attack process kill -p python

结果如下:

Attack process python successfully, uid: 10e633ac-0a37-41ba-8b4a-cd5ab92099f9
备注

只有 signalSIGSTOP 的实验才能被恢复。

通过命令行模式停止进程

停止进程命令

chaosd attack process stop -h

结果如下:

stop process, this action will stop the process with SIGSTOP

Usage:
chaosd attack process stop [flags]

Flags:
-h, --help help for stop
-p, --process string The process name or the process ID

Global Flags:
--log-level string the log level of chaosd, the value can be 'debug', 'info', 'warn' and 'error'

停止进程配置说明

Configuration itemAbbreviationDescriptionValue
processpThe name or the identifier of the process to be stoppedstring; the default value is "".

停止进程示例

chaosd attack process stop -p python

结果如下:

Attack process python successfully, uid: 9cb6b3be-4f5b-4ecb-ae05-51050fcd0010

通过服务模式创建实验

要通过服务模式创建实验,请按以下步骤操作:

  1. 在服务模式下运行 Chaosd:

    chaosd server --port 31767
  2. 向 Chaosd 服务的 /api/attack/process 路径发送 POST HTTP 请求:

    curl -X POST 172.16.112.130:31767/api/attack/process -H "Content-Type:application/json" -d '{fault-configuration}'

    在上述命令中,您需要根据故障类型配置 fault-configuration。具体参数请参考后续各故障类型的参数说明和示例。

备注

运行实验时,请务必记录实验的 UID。当您需要结束对应 UID 的实验时,应向 Chaosd 服务的 /api/attack/{uid} 路径发送 DELETE HTTP 请求。

通过服务模式模拟进程故障

进程故障模拟参数

ParameterDescriptionValue
processThe name or the identifier of the process to be injected faultsstring; the default value is "".
signalThe provided value of the process signalint; the default value is 9

服务模式进程故障模拟示例

终止进程
curl -X POST 172.16.112.130:31767/api/attack/process -H "Content-Type:application/json" -d '{"process":"12345","signal":15}'

结果如下:

{"status":200,"message":"attack successfully","uid":"c3c519bf-819a-4a7b-97fb-e3d0814481fa"}
停止进程
curl -X POST 172.16.112.130:31767/api/attack/process -H "Content-Type:application/json" -d '{"process":"12345","signal":19}'

结果如下:

{"status":200,"message":"attack successfully","uid":"a00cca2b-eba7-4716-86b3-3e66f94880f7"}
备注

只有 signalSIGSTOP 的实验才能被恢复。