Stressszenarien simulieren
Diese Seite wurde von PageTurner AI übersetzt (Beta). Nicht offiziell vom Projekt unterstützt. Fehler gefunden? Problem melden →
Dieses Dokument erklärt, wie Sie mit Chaosd Belastungsszenarien simulieren können. Diese Funktion erzeugt CPU- oder Speicherbelastung auf dem Host mithilfe von stress-ng. Sie können Belastungsexperimente entweder über die Befehlszeile oder den Dienstmodus erstellen.
Stress-Experimente über die Befehlszeile erstellen
Dieser Abschnitt erklärt die Erstellung von Belastungsexperimenten im Befehlszeilenmodus.
Vor dem Erstellen von Belastungsexperimenten können Sie folgenden Befehl ausführen, um die unterstützten Experimenttypen anzuzeigen:
chaosd attack stress --help
Das Ergebnis sieht wie folgt aus:
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.
Aktuell unterstützt Chaosd CPU-Belastungsexperimente und Speicherbelastungsexperimente.
CPU-Belastung über die Befehlszeile simulieren
Befehl zur Simulation von CPU-Belastung
Um die Konfigurationsoptionen für die CPU-Belastungssimulation anzuzeigen, führen Sie folgenden Befehl aus:
chaosd attack stress cpu --help
Das Ergebnis sieht wie folgt aus:
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'
Konfigurationsbeschreibung für CPU-Belastungssimulation
| Configuration item | Abbreviation | Description | Type | Value |
|---|---|---|---|---|
load | l | Specifies the percentage of CPU load per CPU worker. 0 means no CPU utilization, and 100 means full CPU utilization. | int | Range: 0 to 100; Default value: 10. |
workers | w | Specifies the number of workers used to create CPU stress. | int | Default value: 1. |
options | o | The extended parameter of stress-ng, usually not configured. | string | Default value: "". |
Beispiel für CPU-Belastungssimulation
chaosd attack stress cpu --workers 2 --load 10
Das Ergebnis sieht wie folgt aus:
[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
Speicherbelastung über die Befehlszeile simulieren
Befehl zur Simulation von Speicherbelastung
Um die Konfigurationsoptionen für die Speicherbelastungssimulation anzuzeigen, führen Sie folgenden Befehl aus:
chaosd attack stress mem --help
Das Ergebnis sieht wie folgt aus:
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'
Konfigurationsbeschreibung für Speicherbelastungssimulation
| Configuration item | Abbreviation | Description | Type | Value |
|---|---|---|---|---|
size | s | Specifies the size of memory per VM worker. | 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. |
options | o | The extended parameter of stress-ng, usually not configured. | string | Default value: "". |
Beispiel für Speicherbelastungssimulation
chaosd attack stress mem --workers 2 --size 100M
Das Ergebnis sieht wie folgt aus:
[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
Beim Ausführen des Experiments müssen Sie die UID-Informationen speichern. Wenn die Belastungssimulation beendet werden soll, können Sie mit recover das zugehörige Experiment beenden::
chaosd recover c2bff2f5-3aac-4ace-b7a6-322946ae6f13
Das Ergebnis sieht wie folgt aus:
Recover c2bff2f5-3aac-4ace-b7a6-322946ae6f13 successfully
Stress-Experimente über den Dienstmodus erstellen
Gehen Sie wie folgt vor, um Experimente im Dienstmodus zu erstellen:
-
Starten Sie Chaosd im Dienstmodus:
chaosd server --port 31767 -
Senden Sie eine
POST-HTTP-Anfrage an den Pfad/api/attack/{uid}des Chaosd-Dienstes:curl -X POST 172.16.112.130:31767/api/attack/jvm -H "Content-Type:application/json" -d '{fault-configuration}'Für den
fault-configuration-Teil konfigurieren Sie die Werte entsprechend dem Fehlertyp. Die benötigten Parameter entnehmen Sie den folgenden Abschnitten mit Parametern und Beispielen.
Speichern Sie beim Ausführen eines Experiments die zugehörige UID. Um das Experiment zu beenden, senden Sie eine DELETE-HTTP-Anfrage an den Pfad /api/attack/{uid} des Chaosd-Dienstes.
CPU-Belastung über den Dienstmodus simulieren
Parameter für CPU-Belastungssimulation
| Parameter | Description | Type | Value |
|---|---|---|---|
action | Actions of the experiment | Set to "cpu" | |
load | Specifies the percentage of CPU load per CPU worker. 0 means no CPU utilization, and 100 means full CPU utilization. | int | Range: 0 to 100; Default value: 10 |
workers | Specifies the number of workers used to create CPU stress | int | Default value: 1 |
options | The extended parameter of stress-ng, usually not configured. | string | Default value: "" |
Beispiel für CPU-Belastungssimulation im Dienstmodus
curl -X POST 172.16.112.130:31767/api/attack/stress -H "Content-Type:application/json" -d '{"load":10, "action":"cpu","workers":1}'
Das Ergebnis sieht wie folgt aus:
{"status":200,"message":"attack successfully","uid":"c3c519bf-819a-4a7b-97fb-e3d0814481fa"}
Speicherbelastung über den Dienstmodus simulieren
Parameter für Speicherbelastungssimulation
| Parameter | Description | Type | Value |
|---|---|---|---|
action | Actions of the experiment | Set to "mem" | |
size | Specifies the size of memory per VM worker | 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. |
options | The extended parameter of stress-ng, usually not configured. | string | Default value: "" |
Beispiel für Speicherbelastungssimulation im Dienstmodus
curl -X POST 172.16.112.130:31767/api/attack/stress -H "Content-Type:application/json" -d '{"size":"100M", "action":"mem"}'
Das Ergebnis sieht wie folgt aus:
{"status":200,"message":"attack successfully","uid":"a551206c-960d-4ac5-9056-518e512d4d0d"}