[GCP] Perform CPU load test & set alert on GCE

2 minute read

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

  1. Click “Monitoring” → “Alert”.
    image.png

  2. Click “CREATE POLICY”.
    image.png

  3. Click ADD CONDITION.
    image.png

  4. 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
      image.png
  5. Set the timing to issue an alert in “Configuration” and click “SAVE”.
    image.png

  6. Click Next.
    image.png

  7. Set the option to issue an alert in “Notification Channels” (such as issuing an alert to an email address), and click “NEXT”.
    image.png

  8. 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.
      image.png
  9. Make sure the alert has been created and that the alert is enabled.
    image.png

2. CPU load test

  1. Log in to GCE.

  2. Execute the following command that intentionally consumes the CPU multiple times. (Infinitely output y to / dev / null / in the background)

    $ yes > /dev/null &
    

    image.png

  3. Execute the top command and confirm that the CPU usage is 100%.
    image.png

3. Test result

GCP dashboard

  1. Confirm that an alert with 100% CPU usage has been issued.
    image.png

  2. Click the alert that was raised to see the incident details.
    image.png
    image.png
    image.png

If you set to issue an alert to your email address

Confirm that you have received the following alert email.

image.png
image.png

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.

image.png
image.png

Finally

By setting the GCP monitoring function and alerts, you can notice problems such as CPU usage.