tencent cloud

Tencent Cloud Smart Advisor

Implementing CPU Accumulation Faults with Custom Actions

PDF
포커스 모드
폰트 크기
마지막 업데이트 시간: 2025-03-24 15:23:01

Background

The CFG allows users to create custom fault actions for chaotic experiments. Users can configure action parameters and execute script commands based on specific scenarios.

Practical Examples

This section demonstrates how to configure custom actions to perform chaos engineering experiments for CVM CPU accumulation faults.

Step 1: Experiment preparation

A CVM instance used for fault injection (The example instance runs TencentOS Server 2.6 (Final).)
Fault action script file

Step 2: Create custom actions

1. Log in to Tencent Cloud Smart Advisor > Chaotic Fault Generator, enter the Action Library Management page, and select Create Custom Action.
2. Configure the custom actions. Configure command content and command parameters. Click Save after completing the configuration.
The example command content is as follows, where the percentage, timeout, and step parameters can be passed during execution.
#!/bin/bash
user=$(whoami)
if [ !$user == 'root' ]
then
sudo -i
fi
echo -e "["`date +"%Y-%m-%d %H:%M:%S"`"] \\c"
echo "installing stress-ng..."
yum install stress-ng -y

percentage={{percentage}}
timeout={{timeout}}
step={{step}}

for (( i = $step; i < ${timeout} + $step; i=(i+step) )); do
val=`expr $percentage \\* $i / $timeout`
echo "Pre = $val"
stress-ng -c 0 -l $val --timeout $step
done

if [[ !$? -eq 0 ]]
then
echo -e "["`date +"%Y-%m-%d %H:%M:%S"`"] \\c"
echo "Failed"
exit 1
else
echo -e "["`date +"%Y-%m-%d %H:%M:%S"`"] \\c"
echo "Completed"
exit 0
fi

Step 3: Experiment orchestration

1. Enter the Experiment Management page and click Create a New Experiment.
2. Click Skip and create a blank experiment, fill in the experiment details, and select the objective CVM instance for the experiment.
3. Add experiment actions. Click Add Now, select Shell Script , select the created Custom action, and click Next .
4. Leave the action parameters as default and click Confirm.
5. After configuring action parameters, click Next. After confirming all configurations, add a monitoring metric to observe the action's effect, then click Submit.
6. Click Submit to complete the experiment creation.

Step 4: Execute the experiment

1. Execute the experiment and observe the execution results.
2. During execution, users can monitor CPU data changes via monitoring metrics. After waiting for 90 seconds, once the action is completed, you can see from the monitoring metrics that the experiment results meet the expectations.

도움말 및 지원

문제 해결에 도움이 되었나요?

피드백