본문 바로가기
Study/Cloud Computing

Monitor and Manage Google Cloud Resources

by sumping 2024. 9. 22.
  • Cloud Monitoring
  • Cloud Functions
  • Monitor and Manage Google Cloud Resources

✅ Cloud Monitoring

[ Create an uptime check ]

Uptime checks verify that a resource is always accessible. For practice, create an uptime check to verify your VM is up.

  1. In the Cloud Console, in the left menu, click Uptime checks, and then click Create Uptime Check.
  2. For Protocol, select HTTP.
  3. For Resource Type, select Instance.
  4. For Instance, select lamp-1-vm.
  5. For Check Frequency, select 1 minute.
  6. Click Continue.
  7. In Response Validation, accept the defaults and then click Continue.
  8. In Alert & Notification, accept the defaults, and then click Continue.
  9. For Title, type Lamp Uptime Check.
  10. Click Test to verify that your uptime check can connect to the resource.
  11. When you see a green check mark everything can connect.
  12. Click Create.

 

 

[ Create a dashboard and chart ]

You can display the metrics collected by Cloud Monitoring in your own charts and dashboards. In this section you create the charts for the lab metrics and a custom dashboard.

  1. In the left menu select Dashboards, and then +Create Dashboard.
  2. Name the dashboard Cloud Monitoring LAMP Qwik Start Dashboard.

Add the first chart

  1. Click on + ADD WIDGET
  2. Select the Line option under Visualization in the Add widget.
  3. Name the Widget title CPU Load.
  4. Click on Select a metric dropdown. Uncheck the Active.
  5. Type CPU load (1m) in filter by resource and metric name and click on VM instance > Cpu. Select CPU load (1m) and click Apply. Leave all other fields at the default value. Refresh the tab to view the graph.

Add the second chart

  1. Click + Add WIDGET and select Line option under Visualization in the Add widget.
  2. Name this Widget title Received Packets.
  3. Click on Select a metric dropdown. Uncheck the Active.
  4. Type Received packets in filter by resource and metric name and click on VM instance > Instance. Select Received packets and click Apply. Refresh the tab to view the graph.
  5. Leave the other fields at their default values. You see the chart data.

 


 Cloud Functions

A cloud function is a piece of code that runs in response to an event, such as an HTTP request, a message from a messaging service, or a file upload. Cloud events are things that happen in your cloud environment.


Since cloud functions are event-driven, they only run when something happens. This makes them a good choice for tasks that need to be done quickly or that don't need to be running all the time.

 

[ Create a function ]

In this step, you're going to create a cloud function using the console.

  1. In the console, on the Navigation menu click VIEW ALL PRODUCTS and click Serverless > Cloud Run functions.
  2. Click Create function.
  3. In the Create function dialog, enter the following values:
Field Value
Environment Cloud Run function
Function name GCFunction
Region us-central1
Trigger type HTTPS
Authentication Allow unauthenticated invocations
Memory allocated (In Runtime, Build, Connections and Security Settings) Keep it default
Autoscaling Set the Maximum number of instance to 5 and then click Next

 

 

[ View logs ]

 


 Monitor and Manage Google Cloud Resources

 

You need to:

  • Create a Cloud Storage bucket and share with a second user.
  • Create a Pub/Sub topic for the Cloud Run Function to send messages.
  • Create a Cloud Run Function that executes every time a new object is created in the Cloud Storage bucket.
  • Create an alerting policy to send a notification email about the number of active Cloud Run Function instances.

 

Task 1. Create a bucket

 

Task 2. Create a Pub/Sub topic

Task 3. Create the thumbnail Cloud Run Function

  1. Create a Cloud Run Function called travel-thumbnail-generator that executes every time an object is created in the bucket travel-bucket-qwiklabs-gcp-04-d0d7a5dbdd66 you created in task 1.
  2. Make sure you set the Entry point (Function to execute) to thumbnail and Trigger to Cloud Storage.

Note: You must upload one JPG or PNG image into the bucket to verify the thumbnail was created (after creating the function successfully). 

Task 4. Create an alerting policy

  1. Create an alerting policy named Active Cloud Run Function Instances that notifies your personal email account when the number of active Cloud Run Function instances is greater than zero (0).
  2. For the metric, be sure to select Cloud Run Function > Function > Active Instances.