Custom Email Notifications for Google Cloud VM Instance Creation: A Step-by-Step Guide

Punit Thakker/ June 22, 2023/ Cloud Solution

Effectively monitoring your Google Cloud environment is essential for maintaining optimal performance and security. In this blog post, we’ll guide you through the process of setting up custom email notifications for new VM instance creations in the Google Cloud Platform (GCP).

Step 1: Create a Custom Matrix in Logging
Begin by navigating to the logging section in your Google Cloud Console. Create a custom matrix and select the matrix type as “Counter.”

Create a Custom Matrix in Logging

Step 2: Configure Matrix Details
In the details section of the matrix configuration, set the unit to 1. This ensures that each VM creation event is counted as a single unit in the matrix.

Configure Matrix Details

Step 3: Set up Log-Based Metric
In the filter selection section, choose “PREVIEW LOGS” and define your log-based metric. Select the log scope as “Project logs” to focus on the relevant log entries within your Google Cloud project.

Set up Log-Based Metric

Step 4: Add Custom Query for Google Cloud VM Creation
Craft a custom query to specifically filter for new VM creations in Google Cloud. Use the following query in the matrix configuration:

resource.type:”gce_instance”
protoPayload.methodName:”compute.instances.insert”
operation.first:true

This query is tailored to identify instances of the resource type “gce_instance” where the method name is “compute.instances.insert,” indicating the creation of a new VM in Google Cloud.

Step 5: Set Up Email Alerts
Click on the “Create Alert” button to set up email notifications for new VM creations. Customize your alert settings and ensure it is associated with the previously created matrix.
Click on Create alert

Click on create alert

Then give name user/creation

give name user/creation

Then choose log and include alert section automatically get that matrix

choose log and include alert section

Then set the value to get a notification

set the value to get a notification

Then select the notification channel

select the notification channel

select the notification channel

select the notification channel

Conclusion:
Congratulations! You’ve successfully configured custom email notifications for new VM instances in Google Cloud. This proactive monitoring approach empowers you to stay informed about critical events, enhancing your overall management and security practices within the GCP environment.

Stay tuned for more insights and tips on optimizing your Google Cloud experience!

Share this Post