arrow_back

APIs Explorer: Compute Engine

Join Sign in

APIs Explorer: Compute Engine

45 minutes 1 Credit

GSP293

Google Cloud self-paced labs logo

Overview

The APIs Explorer enables you to construct REST-based API calls against any version of any Google service. In this lab, you'll use API Explorer to create (insert) a Compute Engine instance with the Compute Engine API and then use Cloud Monitoring to monitor CPU usage.

Setup and requirements

Before you click the Start Lab button

Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.

This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.

To complete this lab, you need:

  • Access to a standard internet browser (Chrome browser recommended).
Note: Use an Incognito or private browser window to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.
  • Time to complete the lab---remember, once you start, you cannot pause a lab.
Note: If you already have your own personal Google Cloud account or project, do not use it for this lab to avoid extra charges to your account.

How to start your lab and sign in to the Google Cloud Console

  1. Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the Lab Details panel with the following:

    • The Open Google Console button
    • Time remaining
    • The temporary credentials that you must use for this lab
    • Other information, if needed, to step through this lab
  2. Click Open Google Console. The lab spins up resources, and then opens another tab that shows the Sign in page.

    Tip: Arrange the tabs in separate windows, side-by-side.

    Note: If you see the Choose an account dialog, click Use Another Account.
  3. If necessary, copy the Username from the Lab Details panel and paste it into the Sign in dialog. Click Next.

  4. Copy the Password from the Lab Details panel and paste it into the Welcome dialog. Click Next.

    Important: You must use the credentials from the left panel. Do not use your Google Cloud Skills Boost credentials. Note: Using your own Google Cloud account for this lab may incur extra charges.
  5. Click through the subsequent pages:

    • Accept the terms and conditions.
    • Do not add recovery options or two-factor authentication (because this is a temporary account).
    • Do not sign up for free trials.

After a few moments, the Cloud Console opens in this tab.

Note: You can view the menu with a list of Google Cloud Products and Services by clicking the Navigation menu at the top-left. Navigation menu icon

Task 1. API Explorer tool

  1. To access the APIs Explorer tool, from the Navigation menu select APIs & Services > Library.

  2. Type "compute" in the search bar and all the APIs prefixed with "compute" are returned.

  3. Click on Compute Engine API.

  4. Make sure that API is enabled, if not click Enable.

  5. As the API is enabled, for reference, open Rest API Reference in a new tab with the Rest API Reference page for the Compute Engine API.

Task 2. Create your request

  1. From the left menu, navigate to All APIs and references > Compute Engine API > v1 > instances > insert to instances.insert method or use the Method:instances.insert link to create an instance resource.

You'll now fill out a form to use the compute.instances.insert method.

  1. The Request body contains the resource properties that you want to use to create your instance:

project= your-project-id

zone= us-central1-f

Request body= Click inside the brackets to select the following properties:

  • machineType: zones/us-central1-f/machineTypes/n1-standard-1
  • name: instance-1
  • networkInterfaces: leave empty [{}]
  • disks:
    • type: PERSISTENT
    • initializeParams > sourceImage: projects/debian-cloud/global/images/family/debian-11
  • Set the boot to true

Your form should look like this:

The form containing the completed fields previously indicated.

  1. Make sure that the Google OAuth 2.0 checkbox is selected under the Credentials section.
Note: To view Credentials FAQs, click on the question mark icon next to Credentials title.
  1. Make sure that there are no trailing spaces in any of the fields, then scroll down and click Execute.

  2. Select the student account you started the lab with.

  3. On the next screen, click Allow to give APIs Explorer access.

You can see the Request that was sent to your project as code, built from the input you provided in the form. The Response below.

  1. In the console, click Navigation menu > Compute Engine and see the instance you just created.

Test completed task

Click Check my progress to verify your performed task. If you have successfully created a Compute Engine instance via API, you will see an assessment score.

Create a Compute Engine instance via API

Task 3. Monitor your instance with Cloud monitoring

  1. Use the Cloud Monitoring API documentation to navigate to Cloud Monitoring API.

  2. From the left APIs & Reference section, navigate to All APIs and references > Cloud Monitoring API v3 > REST API reference > projects.timeSeries > list to projects.timeSeries.list method or use the Method: projects.timeSeries.list documentation to lists time series.

For this method, the name is specified as a string in the format projects/Your_Project_ID.

The monitoring filter specifies which time series should be returned. The filter must specify a single metric type and can additionally specify a metric label and other information.

  1. For this lab, specify “gce_instance” as the resource type and “cpu/usage_time” as the metric type.

  2. Add the following string in the filter box:

resource.type="gce_instance" AND metric.type="compute.googleapis.com/instance/cpu/usage_time"
  1. interval.endTime and interval.startTime: You will need to calculate RFC-3339 timestamps to filter the timeseries returned by APIs Explorer. You can use Unix Time Stamp - Epoch Converter to get the current time.

  2. Copy the last RFC 3339 timestamp and add it to interval.endTime:

Epoch & Unix Timestamp Conversion Tools page, with the date and timestamp highlighted.

  1. Subtract one hour from your timestamp time, and add that value to interval.startTime.

Your form should look like this:

Request form that contains the resource properties to create your instance using the projects.timeSeries.list method

  1. Make sure that the Google OAuth 2.0 and API key checkboxes are selected under the Credentials section.
Note: To view Credentials FAQs, click on the question mark icon next to Credentials title.
  1. Make sure that there are no trailing spaces in any of the fields, then scroll down and click Execute.

Request body for the request to use the projects.timeSeries.list method

Task 4. Bonus: See your metric in Cloud Monitoring

You can do the same exercise in Cloud Monitoring if you want. Open a Cloud monitoring workspace in the Cloud Console, then use the Metrics Explorer to monitor your VMs CPU usage.

Create a Monitoring Metrics Scope

Set up a Monitoring Metrics Scope that's tied to your Google Cloud Project. The following steps create a new account that has a free trial of Monitoring.

  • In the Cloud Console, click Navigation menu Navigation menu icon > Monitoring.

When the Monitoring Overview page opens, your metrics scope project is ready.

Monitor CPU usage

  1. In the left menu, click Metrics Explorer.

  2. Resource & Metric: VM Instance > Instance > CPU Usage then click Apply.

  3. Filter: instance_name (select your instance.)

Task 5. Delete your VM

Now use APIs Explorer to delete the instance you created.

  1. Open Rest API Reference. This will open a new tab with the Rest API Reference page for the Compute Engine API.

  2. From the left APIs & Reference section, navigate to All APIs and references > Compute Engine API > v1 > instances > delete to instances.delete method or use the Method: instances.delete documentation to delete an instance resource.

  3. You'll add your project, zone, and instance name to the form.

  4. Make sure that the Google OAuth 2.0 checkbox is selected under the Credentials section.

Note: To view Credentials FAQs, click on the question mark icon next to Credentials title.
  1. Make sure that there are no trailing spaces in any of the fields, then scroll down and click Execute.

Your Response will indicate that the deletion process has been started.

  1. Navigate to Compute Engine with Navigation menu > Compute Engine and verify that your console resembles following:

VM instance list displaying Instance-1

Note: If your instance deletion process has been completed then you won't be able to see an output as above. That means your instance has been removed.

Test completed task

Click Check my progress to verify your performed task. If you have successfully deleted your instance, you will see an assessment score.

Delete your instance

Task 6. Test your knowledge

Test your knowledge about the Google Cloud by taking our quiz.

Congratulations!

You have created an instance, monitored its CPU usage, and removed an instance using APIs Explorer.

Finish your quest

This self-paced lab is part of the Exploring APIs quest. A quest is a series of related labs that form a learning path. Completing this quest earns you a badge to recognize your achievement. You can make your badge or badges public and link to them in your online resume or social media account. Enroll in this quest or any quest that contains this lab and get immediate completion credit. See the Google Cloud Skills Boost catalog to see all available quests.

Next steps / Learn more

Google Cloud training and certification

...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.

Manual Last Updated September 19, 2022

Lab Last Tested April 1, 2022

Copyright 2023 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.