### Expected Helm Version Output Source: https://chaosblade.io/docs/getting-started/installation-and-deployment/environment-prepare This is an example of the expected output when Helm is successfully installed, showing version details. ```go version.BuildInfo{Version:"v3.4.2", GitCommit:"23dd3af5e19a02d4f4baa5b2f242645a1a3af629", GitTreeState:"dirty", GoVersion:"go1.15.5"} ``` -------------------------------- ### Install Jvm-SandBox Source: https://chaosblade.io/docs/community/java-dev-guide/bytecode Execute the local installation script after downloading the Jvm-SandBox distribution. ```bash cd sandbox ./install-local.sh ``` -------------------------------- ### Memory Load Command Examples Source: https://chaosblade.io/docs/experiment-types/host/mem/blade_create_mem_load Practical examples for executing memory load experiments using the blade CLI. ```bash # 在执行命令之前,先使用 top 命令查看内存使用信息,如下,总内存大小是 8G,使用了 7.6% KiB Mem : 7.6/8010196 # 执行内存占用 50% blade c mem load --mode ram --mem-percent 50 # 查看内存使用 KiB Mem : 50.0/8010196 # 执行内存占用 100% KiB Mem : 99.6/8010196 # 保留 200M 内存,总内存大小 1G blade c mem load --mode ram --reserve 200 --rate 100 KiB Mem : 1014744 total, 78368 free, 663660 used, 272716 buff/cache KiB Swap: 0 total, 0 free, 0 used. 209652 avail Mem KiB Mem : 79.7/1014744 [|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ] ``` -------------------------------- ### Install Project Dependencies Source: https://chaosblade.io/docs/community Navigate to the project directory and install required packages using Yarn. ```bash cd chaosblade-website # 命令安装依赖 yarn install yarn install v1.22.10 warning ../../package.json: No license field [1/4] 🔍 Resolving packages... [2/4] 🚚 Fetching packages... [3/4] 🔗 Linking dependencies... warning "@docusaurus/preset-classic > @docusaurus/theme-search-algolia > @docsearch/react@3.0.0-alpha.36" has unmet peer dependency "@types/react@>= 16.8.0 < 18.0.0". warning "@docusaurus/preset-classic > @docusaurus/theme-search-algolia > @docsearch/react > @algolia/autocomplete-preset-algolia@1.0.0-alpha.44" has unmet peer dependency "@algolia/client-search@^4.5.1". [4/4] 🔨 Building fresh packages... ✨ Done in 11.02s. ``` -------------------------------- ### Start Target Application Source: https://chaosblade.io/docs/community/java-dev-guide/bytecode Command to execute the target application jar. ```bash java -jar NumberAdd.jar ``` -------------------------------- ### Start Local Development Server Source: https://chaosblade.io/docs/community Launch the local development server to preview documentation changes. ```bash yarn start yarn run v1.22.10 warning ../../package.json: No license field $ docusaurus start Starting the development server... Docusaurus website is running at: http://localhost:3000/ ✔ Client Compiled successfully in 7.54s ℹ 「wds」: Project is running at http://localhost:3000/ ℹ 「wds」: webpack output is served from / ℹ 「wds」: Content not from webpack is served from /Users/saybot/own/chaosblade-website ℹ 「wds」: 404s will fallback to /index.html ``` -------------------------------- ### Check and Install Expect Source: https://chaosblade.io/docs/getting-started/installation-and-deployment/platform-box-install-and-uninstall Check if expect is installed and install it if necessary. Expect is used in conjunction with sshKey.sh and chaosblade-box-version.jar for automated probe installation. ```bash # Check if there is already installed expect -v # install expect, eg: Fedora || RedHat yum install expect -y ``` -------------------------------- ### Start ChaosBlade-Box Application Source: https://chaosblade.io/docs/getting-started/installation-and-deployment/platform-box-install-and-uninstall Start the ChaosBlade-Box application using Java. Configure the data source URL, username, password, and server domain. Redirect output to a log file. ```bash nohup java -Duser.timezone=Asia/Shanghai -jar chaosblade-box-1.0.0.jar --spring.datasource.url="jdbc:mysql://DATASOURCE_HOST:3306/chaosblade?characterEncoding=utf8&useSSL=false" --spring.datasource.username=DATASOURCE_USERNAME --spring.datasource.password=DATASOURCE_PASSWORD --chaos.server.domain=BOX-HOST> chaosblade-box.log 2>&1 & ``` -------------------------------- ### blade status Examples Source: https://chaosblade.io/docs/getting-started/chaosblade-tool-quick-start/cli-mode-user-guide/blade-status Common usage examples for querying experiment information by UID or command type. ```bash # 查看 status 命令帮助文档 blade status -h # 查询 uid 为 4c6b4a3fc313e1d4 的实验信息 blade status 4c6b4a3fc313e1d4 { "code": 200, "success": true, "result": { "Uid": "4c6b4a3fc313e1d4", "Command": "cpu", "SubCommand": "fullload", "Flag": " --cpu-percent=60", "Status": "Destroyed", "Error": "", "CreateTime": "2020-01-14T14:09:49.152708+08:00", "UpdateTime": "2020-01-14T14:10:45.605888+08:00" } } # 查询 create 类型命令的实验信息 blade status --type create { "code": 200, "success": true, "result": [ { "Uid": "4c6b4a3fc313e1d4", "Command": "cpu", "SubCommand": "fullload", "Flag": " --cpu-percent=60", "Status": "Destroyed", "Error": "", "CreateTime": "2020-01-14T14:09:49.152708+08:00", "UpdateTime": "2020-01-14T14:10:45.605888+08:00" } ] } # 查询 prepare 类型命令的实验信息 blade status --type prepare { "code": 200, "success": true, "result": [ { "Uid": "e669d57f079a00cc", "ProgramType": "jvm", "Process": "dubbo.consumer", "Port": "59688", "Status": "Running", "Error": "", "CreateTime": "2019-03-29T16:19:37.284579975+08:00", "UpdateTime": "2019-03-29T17:05:14.183382945+08:00" } ] } ``` -------------------------------- ### Ping Command Output Example Source: https://chaosblade.io/docs/experiment-types/host/network/blade_create_network_reorder Example output from the ping command, demonstrating packet reordering with varying 'time' values. ```text PING 180.101.49.12 (180.101.49.12) 56(84) bytes of data. 64 bytes from 180.101.49.12: icmp_seq=1 ttl=50 time=510 ms 64 bytes from 180.101.49.12: icmp_seq=2 ttl=50 time=9.66 ms 64 bytes from 180.101.49.12: icmp_seq=4 ttl=50 time=9.70 ms 64 bytes from 180.101.49.12: icmp_seq=3 ttl=50 time=509 ms 64 bytes from 180.101.49.12: icmp_seq=6 ttl=50 time=10.0 ms 64 bytes from 180.101.49.12: icmp_seq=5 ttl=50 time=509 ms 64 bytes from 180.101.49.12: icmp_seq=8 ttl=50 time=9.71 ms 64 bytes from 180.101.49.12: icmp_seq=7 ttl=50 time=509 ms 64 bytes from 180.101.49.12: icmp_seq=10 ttl=50 time=9.72 ms 64 bytes from 180.101.49.12: icmp_seq=9 ttl=50 time=509 ms 64 bytes from 180.101.49.12: icmp_seq=11 ttl=50 time=509 ms 64 bytes from 180.101.49.12: icmp_seq=12 ttl=50 time=509 ms 64 bytes from 180.101.49.12: icmp_seq=13 ttl=50 time=509 ms 64 bytes from 180.101.49.12: icmp_seq=15 ttl=50 time=9.90 ms 64 bytes from 180.101.49.12: icmp_seq=14 ttl=50 time=509 ms 64 bytes from 180.101.49.12: icmp_seq=16 ttl=50 time=509 ms ``` -------------------------------- ### Prepare JVM Experiment Source: https://chaosblade.io/docs/experiment-types/application/jvm Before running a JVM experiment, use the 'prepare' command to set up the necessary agent. This example prepares for a CPU full load experiment on a process named 'tomcat'. ```bash # 先执行 prepare 操作 blade prepare jvm --process tomcat {"code":200,"success":true,"result":"af9ec083eaf32e26"} ``` -------------------------------- ### Get Help for CPU Full Load Experiment Source: https://chaosblade.io/docs/experiment-types/host/cpu/blade_create_cpu_load Run this command to view the help information for the CPU full load experiment scenario. ```bash blade create cpu fullload -h ``` -------------------------------- ### Install ChaosBlade-Box using Helm Source: https://chaosblade.io/docs/getting-started/installation-and-deployment/platform-box-install-and-uninstall Install ChaosBlade-Box on Kubernetes using Helm. Specify the chart package, namespace, and the database password. ```bash helm install chaosblade-box chaosblade-box-1.0.0.tgz --namespace chaosblade --set spring.datasource.password=DATASOURCE_PASSWORD ``` -------------------------------- ### blade destroy Command Usage and Examples Source: https://chaosblade.io/docs/getting-started/chaosblade-tool-quick-start/cli-mode-user-guide/blade-destroy Displays the command syntax, aliases, and basic usage examples for destroying experiments. ```bash Destroy a chaos experiment by experiment uid which you can run status command to query Usage: blade destroy UID blade destroy [command] Aliases: destroy, d Examples: blade destroy 47cc0744f1bb blade check [target] [action] [flags] ``` -------------------------------- ### Stop Process by Keyword Example Source: https://chaosblade.io/docs/experiment-types/host/process/blade_create_process_stop Example of stopping a process that contains the keyword 'SimpleHTTPServer' in its command line. ```bash blade create process stop --process SimpleHTTPServer ``` -------------------------------- ### Execute blade version command Source: https://chaosblade.io/docs/getting-started/chaosblade-tool-quick-start/cli-mode-user-guide/blade-version Example output when running the version command to check tool details. ```bash # 查看 blade 工具版本信息 [root@test chaosblade]# blade version version: 1.7.2 # 版本 env: #1 SMP Tue May 26 11:42:35 UTC 2020 x86_64 # 环境信息 build-time: Thu Oct 20 02:18:52 UTC 2022 # 构建时间 ``` -------------------------------- ### Target Application Method Example Source: https://chaosblade.io/docs/community/java-dev-guide/bytecode A sample main method and add function used to demonstrate bytecode manipulation. ```java public static void main(String[] args) throws Exception { while (true) { Random random = new Random(); int a = random.nextInt(10); int b = random.nextInt(10); int add = new NumberAdd().add(a, b); System.out.println("a(" + a + ")\t+\tb(" + b + ")\t=" + add); TimeUnit.SECONDS.sleep(3); } } public int add(int a, int b) { return a + b; } ``` -------------------------------- ### Example: Kill Process by Keyword Source: https://chaosblade.io/docs/experiment-types/host/process/blade_create_process_kill Demonstrates how to kill processes that contain the keyword 'SimpleHTTPServer' in their command line. This is useful for targeting specific application instances. ```bash blade create process kill --process SimpleHTTPServer ``` -------------------------------- ### Verify ChaosBlade Installation Source: https://chaosblade.io/docs/getting-started/chaosblade-tool-quick-start Navigate to the ChaosBlade directory and run './blade version' or './blade v' to confirm the tool is installed and executable. Check the output for the version number and build details. ```bash [root@test chaosblade]# cd /opt/chaosblade [root@test chaosblade]# ./blade version version: 1.7.2 env: #1 SMP Tue May 26 11:42:35 UTC 2020 x86_64 build-time: Thu Oct 20 02:18:52 UTC 2022 ``` -------------------------------- ### Kubernetes Installation Output Source: https://chaosblade.io/docs/getting-started/installation-and-deployment/tool-chaosblade-install-and-uninstall Expected status output for a successful Kubernetes deployment. ```text NAME READY STATUS RESTARTS AGE chaosblade-operator-688568959-lcwgb 1/1 Running 0 6s chaosblade-tool-c9xjd 1/1 Running 0 6s chaosblade-tool-hvqcv 1/1 Running 0 6s chaosblade-tool-q8jjd 1/1 Running 0 6s ``` -------------------------------- ### blade query network interface Example Source: https://chaosblade.io/docs/getting-started/chaosblade-tool-quick-start/cli-mode-user-guide/blade-query An example demonstrating how to query network interface information using the `blade query network interface` command and its expected JSON response. ```APIDOC ## Example: Query Network Interface ### Command ```bash blade query network interface ``` ### Response Example (Success) ```json { "code": 200, "success": true, "result": [ "lo", "eth0", "cni-podman0", "veth00000de" ] } ``` ``` -------------------------------- ### Example: Revoke Java Agent by UID Source: https://chaosblade.io/docs/getting-started/chaosblade-tool-quick-start/cli-mode-user-guide/blade-revoke Example of uninstalling a Java agent using its prepare UID. ```bash blade revoke 2552c05c6066dde5 ``` -------------------------------- ### ChaosBlade Network Delay Command Examples Source: https://chaosblade.io/docs/experiment-types/host/network/blade_create_network_delay Examples of creating network delay experiments with ChaosBlade. Ensure to replace 'eth0' with your actual network interface. Use the '--timeout' or '--exclude-port' flags to prevent connectivity loss. ```bash blade create network delay --time 3000 --offset 1000 --interface eth0 --local-port 8080,8081 ``` ```bash blade destroy 9b4aa9fabe073624 ``` ```bash blade create network delay --time 3000 --interface eth0 --remote-port 80 --destination-ip 14.215.177.39 ``` ```bash blade create network delay --time 5000 --interface eth0 --exclude-port 22,8000-8080 ``` -------------------------------- ### Simulate Node Disk Usage Source: https://chaosblade.io/docs/experiment-types/k8s/node/blade_create_k8s_node-disk Example of filling a specific Kubernetes node disk to 80% capacity and subsequently destroying the experiment. ```bash blade c k8s node-disk fill --names cn-hangzhou.192.168.0.35 --percent 80 --kubeconfig ~/.kube/config {"code":200,"success":true,"result":"ec322fbb977a455c"} df -h Filesystem Size Used Available Use% Mounted on /dev/vda1 118.0G 89.0G 24.0G 79% / # 恢复实验 blade d ec322fbb977a455c {"code":200,"success":true,"result":{"Target":"node-disk","Scope":"","ActionName":"fill","ActionFlags":{"kubeconfig":"~/.kube/config","names":"cn-hangzhou.192.168.0.35","percent":"80"}}} df -h Filesystem Size Used Available Use% Mounted on /dev/vda1 118.0G 74.8G 38.1G 66% / ``` -------------------------------- ### Query Network Interface Example Source: https://chaosblade.io/docs/getting-started/chaosblade-tool-quick-start/cli-mode-user-guide/blade-query Demonstrates how to query network interfaces on the current machine using the `blade query network interface` command. The output is a JSON object containing the results. ```bash # 查看当前机器网络接口 blade query network interface # 返回结果如下 {"code":200,"success":true,"result":["lo","eth0","cni-podman0","veth00000de"]} ``` -------------------------------- ### Example: Kill Process with Specific Signal and Port Source: https://chaosblade.io/docs/experiment-types/host/process/blade_create_process_kill Illustrates killing a process associated with local port 8080 using signal 15 (SIGTERM). This example includes a pre-execution check using netstat. ```bash # 指定信号量和本地端口杀进程 blade c process kill --local-port 8080 --signal 15 # 执行前 netstat -tanp | grep 8080 tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 10764/java # 执行后此进程已不存在 ``` -------------------------------- ### Plugin Loading Logic in ChaosBlade Source: https://chaosblade.io/docs/community/java-dev-guide/architecture Illustrates the process of adding a plugin, including PointCut filtering and event listening setup. It handles both 'after' and 'before' event types. ```java // 加载插件 public void add(PluginBean plugin) { PointCut pointCut = plugin.getPointCut(); if (pointCut == null) { return; } String enhancerName = plugin.getEnhancer().getClass().getSimpleName(); // 创建filter PointCut匹配 Filter filter = SandboxEnhancerFactory.createFilter(enhancerName, pointCut); if (plugin.isAfterEvent()) { // 事件监听 int watcherId = moduleEventWatcher.watch(filter, SandboxEnhancerFactory.createAfterEventListener(plugin), Type.BEFORE, Type.RETURN); watchIds.put(PluginUtil.getIdentifierForAfterEvent(plugin), watcherId); } else { int watcherId = moduleEventWatcher.watch( filter, SandboxEnhancerFactory.createBeforeEventListener(plugin), Event.Type.BEFORE); watchIds.put(PluginUtil.getIdentifier(plugin), watcherId); } } ``` -------------------------------- ### Execute Redis cache-expire experiments Source: https://chaosblade.io/docs/experiment-types/host/redis/blade_create_redis_cache_expire Examples for setting key expiration times using specific parameters. ```bash # 设置key 1分钟后过期 # blade create redis cache-expire --addr 192.168.56.101:6379 --password 123456 --key test1 --expiry 1m {"code":200,"success":true,"result":"b6a0f477b7fb1f4c"} # 当要设置的过期时间大于key当前过期时间时,设置新过期时间。不存在则直接设置。 # blade create redis cache-expire --addr 192.168.56.101:6379 --password 123456 --key test1 --option GT --expiry 1m {"code":200,"success":true,"result":"b6a0f477b7fb1f4c"} ``` -------------------------------- ### Verify Kubernetes Installation Source: https://chaosblade.io/docs/getting-started/installation-and-deployment/tool-chaosblade-install-and-uninstall Lists pods in the chaosblade namespace to confirm the operator is running. ```bash kubectl get po -n chaosblade ``` -------------------------------- ### Example: Kill Java Processes Source: https://chaosblade.io/docs/experiment-types/host/process/blade_create_process_kill Shows how to kill processes identified by the command name 'java'. This targets all running Java processes. ```bash blade create process kill --process-cmd java ``` -------------------------------- ### Execute Groovy Script Source: https://chaosblade.io/docs/experiment-types/application/jvm/blade_create_jvm_script Example of running a Groovy script by specifying the script type. ```bash blade c jvm script --classname com.example.controller.DubboController --methodname call --script-file /Users/Shared/IdeaProjects/Workspace_WebApp/dubbodemo/src/main/java/com/example/controller/GroovyScript.groovy --script-name exception --script-type groovy ``` -------------------------------- ### Verify Shutdown Experiment CLI Source: https://chaosblade.io/docs/community/os-dev-guide Command to display help information for the shutdown experiment to verify successful installation. ```bash ./blade c shutdown -h Support shutdown, halt or reboot experiment. Can control shutdown or restart behavior with different flags. Warning! the experiment cannot be recovered by this tool. Usage: blade create shutdown [flags] blade create shutdown [command] Available Commands: halt Halt machine poweroff Shutdown machine reboot Reboot machine Flags: -h, --help help for shutdown Global Flags: -a, --async whether to create asynchronously, default is false -d, --debug Set client to DEBUG mode -e, --endpoint string the create result reporting address. It takes effect only when the async value is true and the value is not empty -n, --nohup used to internal async create, no need to config --uid string Set Uid for the experiment, adapt to docker and cri Use "blade create shutdown [command] --help" for more information about a command. ``` -------------------------------- ### Execute JVM Script via Content Source: https://chaosblade.io/docs/experiment-types/application/jvm/blade_create_jvm_script Example of running a Java script provided as a Base64 encoded string. ```bash blade c jvm script --classname com.example.controller.DubboController --methodname call --script-content aW1wb3J0IGphdmEudXRpbC5NYXA7CgppbXBvcnQgY29tLmV4YW1wbGUuY29udHJvbGxlci5DdXN0b21FeGNlcHRpb247CgovKioKICogQGF1dGhvciBDaGFuZ2p1biBYaWFvCiAqLwpwdWJsaWMgY2xhc3MgRXhjZXB0aW9uU2NyaXB0IHsKICAgIHB1YmxpYyBPYmplY3QgcnVuKE1hcDxTdHJpbmcsIE9iamVjdD4gcGFyYW1zKSB0aHJvd3MgQ3VzdG9tRXhjZXB0aW9uIHsKICAgICAgICBwYXJhbXMucHV0KCIxIiwgMTExTCk7CiAgICAgICAgLy9yZXR1cm4gIk1vY2sgVmFsdWUiOwogICAgICAgIC8vdGhyb3cgbmV3IEN1c3RvbUV4Y2VwdGlvbigiaGVsbG8iKTsKICAgICAgICByZXR1cm4gbnVsbDsKICAgIH0KfQo= --script-name exception ``` -------------------------------- ### Manage ChaosBlade Server Lifecycle Source: https://chaosblade.io/docs/getting-started/chaosblade-tool-quick-start/server-mode-user-guaid Commands to start the server on a specific port and stop the running service. ```bash # 启动 server 模式,服务端口是 8080 blade server start --port 8080 success, listening on 8080 # 停止 blade server blade server stop {"code":200,"success":true,"result":"pid is 12619"} ``` -------------------------------- ### Execute JVM Script via File Source: https://chaosblade.io/docs/experiment-types/application/jvm/blade_create_jvm_script Example of running a Java script by specifying the absolute path to the file. ```bash blade c jvm script --classname com.example.controller.DubboController --methodname call --script-file /Users/Shared/IdeaProjects/Workspace_WebApp/dubbodemo/src/main/java/com/example/controller/ExceptionScript.java --script-name exception ``` -------------------------------- ### Example Java Method Source: https://chaosblade.io/docs/experiment-types/application/jvm/blade_create_jvm_return This is an example of a Java method that is targeted for return value mocking. It calls a service to get a result. ```java @RequestMapping(value = "hello") @ResponseBody public String hello(String name, int code) { if (name == null) { name = "friend"; } StringBuilder result = null; try { result = new StringBuilder(sayHello(name)); } catch (Exception e) { return e.getMessage() + "\n"; } return result.toString() + "\n"; } ``` -------------------------------- ### Verifying I/O Exception in Pod Source: https://chaosblade.io/docs/experiment-types/k8s/pod/blade_create_k8s_pod-IO Execute a command within the pod to verify the injected I/O exception. This example shows reading a file and observing the 'No space left on device' error and delay. ```bash kubectl exec test-bc7786698-k6tb7 -c test -n test time cat /data/conf/file ``` -------------------------------- ### Check and Install Ansible Source: https://chaosblade.io/docs/getting-started/installation-and-deployment/platform-box-install-and-uninstall Check if Ansible is installed and install it if necessary. Ansible is required for the platform to automatically install probes in the host environment. ```bash # Check if there is already installed ansible --version # install ansible, eg: Fedora || RedHat yum install ansible -y ``` -------------------------------- ### Verify ChaosBlade CLI Installation Source: https://chaosblade.io/docs/getting-started/installation-and-deployment/tool-chaosblade-install-and-uninstall Checks the installed version of the CLI tool. ```bash ./blade v ``` -------------------------------- ### View blade prepare Help Source: https://chaosblade.io/docs/getting-started/chaosblade-tool-quick-start/cli-mode-user-guide/blade-prepare Display help information for the prepare command to see supported targets. ```bash [root@test chaosblade]# ./blade prepare -h Prepare to experiment, for example, attach agent to java process or deploy agent to kubernetes cluster. Usage: blade prepare blade prepare [command] Aliases: prepare, p Examples: prepare jvm --process tomcat Available Commands: cplus Active cplus agent. jvm Attach a type agent to the jvm process Flags: -h, --help help for prepare Global Flags: -d, --debug Set client to DEBUG mode Use "blade prepare [command] --help" for more information about a command. ``` -------------------------------- ### Java Method Example Source: https://chaosblade.io/docs/experiment-types/application/jvm/blade%20create%20jvm%20throwCustomException This is an example of a Java method that can be targeted for exception injection. ```java private String sayHello(String name) throws BeansException { demoService = (DemoService)SpringContextUtil.getBean("demoService"); StringBuilder result = new StringBuilder(); result.append(demoService.sayHello(name)); return result.toString(); } ``` -------------------------------- ### Check Java Version Source: https://chaosblade.io/docs/getting-started/installation-and-deployment/platform-box-install-and-uninstall Verify if Java is installed on the host environment. This is a prerequisite for installing ChaosBlade-Box. ```bash java -verison ``` -------------------------------- ### Execute Disk Fill Experiment (Reserve Size) Source: https://chaosblade.io/docs/experiment-types/host/disk/blade%20create%20disk%20fill Demonstrates how to execute a disk fill experiment while reserving a specific amount of disk space. Includes checking the resulting disk usage. ```bash # 执行保留固定大小实验场景 blade c disk fill --path /home --reserve 1024 df -h Filesystem Size Used Avail Use% Mounted on /dev/vda1 40G 37G 1.1G 98% / ``` -------------------------------- ### Example: Revoke Experiment by UID Source: https://chaosblade.io/docs/getting-started/chaosblade-tool-quick-start/cli-mode-user-guide/blade-revoke Example of how to revoke a chaos experiment using its prepare UID. ```bash blade revoke cc015e9bd9c68406 ``` -------------------------------- ### Execute Disk Fill Experiment (Percent and Retain Handle) Source: https://chaosblade.io/docs/experiment-types/host/disk/blade%20create%20disk%20fill Shows how to perform a disk fill experiment using a percentage of disk usage and retaining the file handle. Includes checking disk usage and file handles. ```bash # 执行按百分比填充磁盘,并且保留填充磁盘的文件句柄 blade c disk fill --path /home --percent 80 --retain-handle {"code":200,"success":true,"result":"f1fa65e70950d0eb"} df -h /dev/vda1 40G 30G 8.1G 79% / # 查看文件句柄 lsof /home/chaos_filldisk.log.dat COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME chaos_fil 19297 root 3r REG 253,1 17697865728 394174 /home/chaos_filldisk.log.dat ``` -------------------------------- ### Stop Java Process Example Source: https://chaosblade.io/docs/experiment-types/host/process/blade_create_process_stop Example of stopping processes identified as 'java' by their command name. ```bash blade create process stop --process-cmd java ``` -------------------------------- ### Execute Disk Fill Experiment (Size) Source: https://chaosblade.io/docs/experiment-types/host/disk/blade%20create%20disk%20fill Demonstrates how to execute a disk fill experiment by specifying the size. It includes checking disk space before and after the experiment, creating the experiment, and destroying it. ```bash # 执行实验之前,先看下 /home 所在磁盘的大小 df -h /home Filesystem Size Used Avail Use% Mounted on /dev/vda1 40G 4.0G 34G 11% / # 执行磁盘填充,填充 40G,即达到磁盘满的效果(可用34G) blade create disk fill --path /home --size 40000 # 返回结果 {"code":200,"success":true,"result":"7a3d53b0e91680d9"} # 查看磁盘大小 df -h /home Filesystem Size Used Avail Use% Mounted on /dev/vda1 40G 40G 0 100% / # 销毁实验 blade destroy 7a3d53b0e91680d9 {"code":200,"success":true,"result":"command: disk fill --debug false --help false --path /home --size 40000"} # 查看磁盘大小 df -h /home Filesystem Size Used Avail Use% Mounted on /dev/vda1 40G 4.0G 34G 11% / ``` -------------------------------- ### Check Helm Installation Source: https://chaosblade.io/docs/getting-started/installation-and-deployment/environment-prepare Run this command to confirm if Helm is installed on your system. The output should indicate a version number. ```bash helm version ``` -------------------------------- ### blade create Help and Available Commands Source: https://chaosblade.io/docs/getting-started/chaosblade-tool-quick-start/cli-mode-user-guide/blade-create Displays the help output for the create command, including available targets and flags. ```bash [root@test chaosblade]# ./blade c -h Create a chaos engineering experiment Usage: blade create [command] Aliases: create, c Examples: blade create cpu load --cpu-percent 60 Available Commands: cplus C++ chaos experiments cpu Cpu experiment cri CRI experiment disk Disk experiment druid Experiment with the Druid dubbo Experiment with the Dubbo es ElasticSearch experiment! feign feign experiment file File experiment gateway gateway experiment! hbase hbase experiment! hsf Hsf experiment jedis jedis experiment jvm Experiment with the JVM k8s Kubernetes experiment kafka kafka experiment lettuce redis client lettuce experiment log log experiment mem Mem experiment mysql mysql experiment network Network experiment notify notify send or receive message error process Process experiment psql Postgrelsql experiment redisson redisson experiment rocketmq Rocketmq experiment,can make message send or pull delay and exception script Script chaos experiment sentinel Sentinel experiment servlet java servlet experiment shutdown Support shutdown, halt or reboot experiment. strace strace experiment stressng stressng experiment systemd Systemd experiment tair Tair experiment tars tars experiment tddl Tddl experiment time Time experiment zuul Zuul experiment Flags: -a, --async whether to create asynchronously, default is false -e, --endpoint string the create result reporting address. It takes effect only when the async value is true and the value is not empty -h, --help help for create -n, --nohup used to internal async create, no need to config --uid string Set Uid for the experiment, adapt to docker and cri Global Flags: -d, --debug Set client to DEBUG mode Use "blade create [command] --help" for more information about a command. ``` -------------------------------- ### ChaosBlade OS Shutdown Experiment Commands Source: https://chaosblade.io/docs/community/os-dev-guide Demonstrates how to use ChaosBlade CLI to create and destroy OS shutdown, power-off, and reboot experiments. Shows how to specify time and force options. ```bash # 系统1分钟后关机, 不添加时间默认是立即执行 blade create shutdown halt --time 1 # 系统立即断电 blade create shutdown poweroff --force # 系统2分钟后强制重启 blade create shutdown reboot --time 2 # 取消 shutdown 实验 blade destroy UID ``` -------------------------------- ### Create CPU Load Experiment with Percentage Source: https://chaosblade.io/docs/experiment-types/host/cpu/blade_create_cpu_load This command creates a CPU load experiment with a specified percentage of CPU utilization. Use 'top' to verify the overall CPU load. ```bash blade create cpu fullload --percent 50 ``` -------------------------------- ### Install ChaosBlade Operator with Helm Source: https://chaosblade.io/docs/experiment-types/k8s Installs the ChaosBlade Operator in the kube-system namespace using Helm. Ensure you replace with the correct operator version. ```bash helm install --namespace kube-system --name chaosblade-operator chaosblade-operator-.tgz ``` -------------------------------- ### View JVM Prepare Options Source: https://chaosblade.io/docs/getting-started/chaosblade-tool-quick-start/cli-mode-user-guide/blade-prepare Display specific flags and options available for the jvm prepare command. ```bash [root@test chaosblade]# ./blade prepare jvm -h Attach a type agent to the jvm process for java framework experiment. Usage: blade prepare jvm Examples: prepare jvm --process tomcat Flags: -a, --async whether to attach asynchronously, default is false -e, --endpoint string the attach result reporting address. It takes effect only when the async value is true and the value is not empty -h, --help help for jvm -j, --javaHome string the java jdk home path -n, --nohup used to internal async attach, no need to config --pid string the target java process id -P, --port int the port used for agent server -p, --process string the java application process name (required) -u, --uid string used to internal async attach, no need to config Global Flags: -d, --debug Set client to DEBUG mode ``` -------------------------------- ### Run ChaosBlade Demo Container Source: https://chaosblade.io/docs/getting-started Execute this command to run the ChaosBlade demo container with privileged access. ```bash docker run -it --privileged chaosbladeio/chaosblade-demo ``` -------------------------------- ### Example Java Method for Null Return Mocking Source: https://chaosblade.io/docs/experiment-types/application/jvm/blade_create_jvm_return This Java method is an example of a target for return value mocking, specifically to return null. It retrieves a bean and calls a method on it. ```java private String sayHello(String name) throws BeansException { demoService = (DemoService)SpringContextUtil.getBean("demoService"); StringBuilder result = new StringBuilder(); result.append(demoService.sayHello(name)); return result.toString(); } ``` -------------------------------- ### Create CPU Full Load Experiment Source: https://chaosblade.io/docs/experiment-types/host/cpu/blade_create_cpu_load Execute this command to create a CPU full load experiment. The 'result' field in the output provides the experiment's UID, which is needed for destroying the experiment. ```bash blade create cpu fullload ``` -------------------------------- ### View OS check help Source: https://chaosblade.io/docs/getting-started/chaosblade-tool-quick-start/cli-mode-user-guide/blade-check Display help information for OS-specific environment checks. ```bash [root@test chaosblade]# ./blade check os -h Check the environment of os for chaosblade Usage: blade check os blade check os [command] Examples: check os Available Commands: cpu Cpu experiment disk Check disk experiment men Mem experiment network Network experiment Flags: -h, --help help for os Global Flags: -d, --debug Set client to DEBUG mode Use "blade check os [command] --help" for more information about a command. ``` -------------------------------- ### Download ChaosBlade Demo Image Source: https://chaosblade.io/docs/getting-started Use this command to download the Docker image for the ChaosBlade demo environment. ```bash docker pull chaosbladeio/chaosblade-demo ``` -------------------------------- ### Java Agent Parameters Source: https://chaosblade.io/docs/experiment-types/application/jvm/blade_prepare_jvm Configuration flags for the prepare jvm command. ```bash -j, --javaHome string 指定 JAVA_HOME 路径,用于指定 java bin 和 tools.jar,如果不添加此参数,默认会优先获取 JAVA_HOME 环境变量,如果获取失败,会解析指定进程参数获取 JAVA_HOME,获取失败,会使用 chaosblade 自带的 tools.jar --pid string java 进程ID -P, --port int java agent 暴露服务的本地端口,用于下发实验命令 -p, --process string java 进程关键词,用于定位 java 进程 -d, --debug 开启 debug 模式 ``` -------------------------------- ### Get ChaosBlade Experiment Status using kubectl Source: https://chaosblade.io/docs/experiment-types/k8s/container/blade_create_k8s_container-network Retrieve the execution status of a ChaosBlade experiment using kubectl get blade. This command helps monitor the progress and outcome of your applied chaos experiments. ```bash kubectl get blade tamper_container_dns_by_id.yaml -o json ``` -------------------------------- ### Build Agent Jar Source: https://chaosblade.io/docs/community/java-dev-guide/bytecode Command to package the agent project. ```bash mvn clean package ``` -------------------------------- ### Install ChaosBlade Operator via Helm Source: https://chaosblade.io/docs/getting-started/installation-and-deployment/tool-chaosblade-install-and-uninstall Deploys the operator into the specified Kubernetes namespace. ```bash helm install chaosblade-operator chaosblade-operator-1.7.2.tgz --namespace chaosblade ``` -------------------------------- ### Create CPU Full Load Experiment with Specific Core List Source: https://chaosblade.io/docs/experiment-types/host/cpu/blade_create_cpu_load This command creates a CPU full load experiment targeting specific CPU cores by their indices. Use 'top 1' to verify the load distribution. ```bash blade create cpu fullload --cpu-list 0,3 ``` -------------------------------- ### ChaosBlade CLI Version Output Source: https://chaosblade.io/docs/getting-started/installation-and-deployment/tool-chaosblade-install-and-uninstall Expected output format when verifying the CLI installation. ```text version: 1.7.2 env: #1 SMP Thu Mar 17 17:08:06 UTC 2022 x86_64 build-time: Tue Sep 6 07:06:55 UTC 2022 ``` -------------------------------- ### ChaosBlade CLI Response Examples Source: https://chaosblade.io/docs/experiment-types/k8s/container/blade_create_k8s_container-process JSON responses returned by the blade CLI after execution or query. ```json {"code":200,"success":true,"result":"06d5ebae60e8fe3f"} ``` ```json {"code":200,"success":true,"result":{"uid":"06d5ebae60e8fe3f","success":true,"error":"","statuses":[{"id":"1000cbd2018e2c90","uid":"f1de335b4eeaf035b8d23a87080f3d24cebc803cbb6ad15e5fe0d8567e2e8939","name":"php-redis","state":"Success","kind":"container","success":true,"nodeName":"cn-hangzhou.192.168.0.204"}]}} ``` -------------------------------- ### blade create Usage Syntax Source: https://chaosblade.io/docs/getting-started/chaosblade-tool-quick-start/cli-mode-user-guide/blade-create Basic syntax and aliases for the create command. ```bash Usage: blade create [command] Aliases: create, c blade create [target] [action] [flags] ``` -------------------------------- ### Implement ActionExecutor Logic Source: https://chaosblade.io/docs/community/java-dev-guide/plugin Example implementation snippet for processing delay logic using EnhancerModel. ```java // 延迟多少毫秒 Long time = Long.valueOf(enhancerModel.getActionFlag("time")); TimeUnit.MILLISECONDS.sleep(time); ``` -------------------------------- ### Target Business Class Example Source: https://chaosblade.io/docs/experiment-types/application/jvm/blade_create_jvm_script The original business class code intended for modification during the experiment. ```java @RestController @RequestMapping("/pet") public class PetController { @GetMapping("/list") public Result> getPets() { Map petDiscount = discountManager .getPetDiscounts() .stream() .filter(discount -> discount.getExpired() == 0) .collect(Collectors.toMap( Discount::getPetId, Function.identity() )); List pets = petManager .getPets() .stream() .map(pet -> { PetVO petVO = PetVO.from(pet); Discount discount = petDiscount.get(pet.getId()); if (null != discount && null != discount.getDiscountPrice() && discount.getDiscountPrice() > 0L) { petVO.setDiscountPrice(discount.getDiscountPrice()); } return petVO; }) .collect(Collectors.toList()); return Result.success(pets); } ``` -------------------------------- ### Create Java Process CPU Full Load Experiment Source: https://chaosblade.io/docs/experiment-types/application/jvm/blade_create_jvm_cpufullload Use this command to simulate a full CPU load on a specified Java process. The experiment will utilize all available CPU cores by default. The output includes an experiment ID for later management. ```bash blade c jvm cfl --process tomcat {"code":200,"success":true,"result":"48d70f01e65f68f7"} ``` -------------------------------- ### Clone ChaosBlade Repository Source: https://chaosblade.io/docs/community/java-dev-guide/practise Clone the official ChaosBlade repository to your local machine to start development. ```bash git clone https://github.com/chaosblade-io/chaosblade ``` -------------------------------- ### Get ChaosBlade Experiment Status Source: https://chaosblade.io/docs/experiment-types/k8s/node/blade_create_k8s_node-cpu Retrieve the execution status of a ChaosBlade experiment in JSON format. ```bash kubectl get blade cpu-load -o json ``` -------------------------------- ### Kubernetes Node Disk Scenario Parameters Source: https://chaosblade.io/docs/experiment-types/k8s/node/blade_create_k8s_node-disk Common flags available for configuring Kubernetes node disk experiments. ```text --evict-count string 限制实验生效的数量 --evict-percent string 限制实验生效数量的百分比,不包含 % --labels string 节点资源标签 --names string 节点资源名,多个资源名之间使用逗号分隔 --kubeconfig string kubeconfig 文件全路径(仅限使用 blade 命令调用时使用) --waiting-time string 实验结果等待时间,默认为 20s,参数值要包含单位,例如 10s,1m ``` -------------------------------- ### Verify ChaosBlade Operator Deployment Source: https://chaosblade.io/docs/experiment-types/k8s Checks if the chaosblade-operator and chaosblade-tool pods are running in the kube-system namespace after installation. ```bash kubectl get pod -n kube-system -o wide | grep chaosblade ```