[GCP] Perform CPU load test & set alert on GCE
Overview
This document will perform a load test that causes GCE created with GCP to use a large amount of CPU. Also, set the GCP monitoring function to alert you when the CPU usage reaches 100%.
0. Prerequisites
- You have created a GCP account.
- This document uses f1-micro, which is a GCP free frame.
- The version of CentOS 8 used in this manual is as follows.
$ cat /etc/redhat-release
CentOS Linux release 8.2.2004 (Core)
1. Create an alert
-
Click “Monitoring” → “Alert”.
-
Click “CREATE POLICY”.
-
Click ADD CONDITION.
- Set the contents to be monitored as follows. (The following measures the CPU usage of the VM instance (GCE))
- Resource type : VM Instance
- Metric : CPU utilization
-
Set the timing to issue an alert in “Configuration” and click “SAVE”.
-
Click Next.
-
Set the option to issue an alert in “Notification Channels” (such as issuing an alert to an email address), and click “NEXT”.
- Enter the following items and click “SAVE”.
- Alert name
- Document: Describe the text to be displayed in the incident details created when the alert is issued (such as the coping method when the alert is issued) in Markdown format.
- Make sure the alert has been created and that the alert is enabled.
2. CPU load test
-
Log in to GCE.
-
Execute the following command that intentionally consumes the CPU multiple times. (Infinitely output
y
to/ dev / null /
in the background)$ yes > /dev/null &
-
Execute the
top
command and confirm that the CPU usage is 100%.
3. Test result
GCP dashboard
-
Confirm that an alert with 100% CPU usage has been issued.
-
Click the alert that was raised to see the incident details.
If you set to issue an alert to your email address
Confirm that you have received the following alert email.
4. End of test
What to do with GCE
Execute the top
command and make a note of the PID of the yes
process (the process that is intentionally consuming CPU). After that, execute the following command to terminate all yes
processes.
$ kill PID
After that, execute the top
command and confirm that the CPU usage has decreased.
Dashboard, alert email
Confirm that the incident details have been updated as recovering from the failure. Also, if you have set the alert email to be sent to your email address, make sure that you have received the “Alert recovered” email after the failure has been recovered.
Finally
By setting the GCP monitoring function and alerts, you can notice problems such as CPU usage.