# Monitoring Multiple Projects with Cloud Monitoring - GSP090

## **Overview**

Cloud Monitoring provides dashboards and alerts so you can review performance metrics for cloud services, virtual machines, and common open source servers such as MongoDB, Apache, Nginx, Elasticsearch, and more. You configure Cloud Monitoring in the Console.

In this hands-on lab you will have 2 projects to monitor in Cloud Monitoring. You'll add them both to a Cloud Monitoring account and monitor the metrics the virtual machines in the projects provide.

## **Objectives**

In this lab, you learn how to:

*   Create a Cloud Monitoring account that has two Google Cloud projects.
    
*   Monitor across both projects from the single Cloud Monitoring account.
    

## **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 Cloud 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 Cloud console** (or right-click and select **Open Link in Incognito Window** if you are running the Chrome browser).
    
    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** below and paste it into the **Sign in** dialog.
    
    ```apache
    student-00-2cf9924baa27@qwiklabs.net
    ```
    
    You can also find the **Username** in the **Lab Details** panel.
    
4.  Click **Next**.
    
5.  Copy the **Password** below and paste it into the **Welcome** dialog.
    
    ```apache
    rIO0JR0u7WLo
    ```
    
    You can also find the **Password** in the **Lab Details** panel.
    
6.  Click **Next**.
    
    **Important:** You must use the credentials the lab provides you. Do not use your Google Cloud account credentials.
    
    **Note:** Using your own Google Cloud account for this lab may incur extra charges.
    
7.  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 Google Cloud console opens in this tab.

**Note:** To view a menu with a list of Google Cloud products and services, click the **Navigation menu** at the top-left.

![Navigation menu icon](https://cdn.qwiklabs.com/nUxFb6oRFr435O3t6V7WYJAjeDFcrFb16G9wHWp5BzU%3D align="left")

## **Setup for two projects**

For this lab you are given two Project IDs. When you logged in, by default you logged in to Project 1. You'll need to keep track of your projects, and you can return to this page to remind yourself which is which. The projects will change order, so knowing the last few digits of the name will help you identify them.

![Lab details pane with Username, Password, Project ID 1, and Project ID 2](https://cdn.qwiklabs.com/UGlHmL%2FxASvunoKmY4urvekOszvXWf5VC8XH1gncQDY%3D align="left")

Project 1 already has a virtual machine (and you can look at it by going to **Compute Engine > VM instances**). You will create a virtual machine in Project 2, and then monitor both projects in Cloud Monitoring.

## **Task 1. Create Project 2's virtual machine**

1.  At the top of the screen, click on the dropdown arrow next to Project 1's name.
    

![Dropdown arrow](https://cdn.qwiklabs.com/pDc2p5A2Q51ZYDHkujlH935AEtk6ScG%2FZTthxUBAXk4%3D align="left")

2.  Make sure that you're on the **All** tab, then click on the name of **Project 2** to go into it.
    
3.  Select **Navigation menu > Compute Engine > VM instances** to open the VM instances window.
    
4.  Click **Create Instance** to create a new instance.
    
5.  In the **Machine configuration**:
    
    Enter the values for the following fields:
    
    | **Field** | **Value** (type or select) |
    | --- | --- |
    | Name | instance2 |
    | Region | `us-east4` |
    | Zone | `us-east4-b` |
    
    Leave all of the options at the default settings.
    
6.  Click **Create**.
    

Now you have resources to monitor in both of your projects.

### Test completed task

Click **Check my progress** to verify your performed task. If you have completed the task successfully you will be granted an assessment score.

Create Project 2's virtual machine

Check my progress

**Note:** Make sure that you are in Project 2 to proceed further in the lab.

### 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](https://cdn.qwiklabs.com/tkgw1TDgj4Q%2BYKQUW4jUFd0O5OEKlUMBRYbhlCrF0WY%3D align="left")
    
    ) > View All Products > Observability > **Monitoring**.
    

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

Now add both projects to Monitoring.

1.  In the left panel, click **Settings** and in the Settings window navigate to **Metric Scope** tab, click **+Add projects** in the **Google Cloud Projects** section.
    
2.  Click **Select Projects**.
    
3.  Check Project ID 1 and click **Select**.
    
4.  Click **Add projects**.
    

## **Task 2. Monitoring Overview**

Click on **Overview** in the left menu. You'll be adding a lot of good information here as the lab goes along. First, you'll create a [Cloud Monitoring Group](https://cloud.google.com/monitoring/groups/) for visibility across both projects.

### About Cloud Monitoring groups

Cloud Monitoring lets you define and monitor groups of resources, such as VM instances, databases, and load balancers. Groups can be based on names, tags, regions, applications, and other criteria. You can also create subgroups, up to six levels deep, within groups.

### Create a Cloud Monitoring group

1.  In the left menu, click **Groups**, then click **+Create group**.
    
2.  Name your group **DemoGroup**.
    

The **Criteria** is a set of rules that will dynamically evaluate which resources should be part of this group.

Cloud Monitoring dynamically determines which resources belong to your group based on the filter criteria that you set up.

*   In the first dropdown field (Type), **Name** is selected by default.
    
*   In the second dropdown (Operator), **Contains** is selected by default.
    
*   In the third field (Value), type in "instance" since both of the instance names in both of your projects start with the word `instance`.
    

3.  Click **Done**, then click **Create**.
    

#### **Test completed task**

Click **Check my progress** to verify your performed task. If you have completed the task successfully you will be granted an assessment score.

Create a Cloud Monitoring Group

Check my progress

## **Task 3. Uptime check for your group**

Uptime checks let you quickly verify the health of any web page, instance, or group of resources. Each configured check is regularly contacted from a variety of locations around the world. Uptime checks can be used as conditions in alerting policy definitions.

1.  In the left menu, click **Uptime checks**, then click **+Create uptime check**.
    
2.  Create your uptime check with the following information:
    
    **Protocol:** TCP
    
    **Resource Type:** Instance
    
    **Applies To:** Group, and then select **DemoGroup**.
    
    **Port:** 22
    
    **Check frequency:** 1 minute, then click **Continue**.
    
3.  Click **Continue** again.
    
4.  Leave the slider **ON** state for **Create an alert** option in **Alert & notification** section, then click **Continue**.
    
5.  For **Title:** enter `DemoGroup uptime check`.
    
6.  Click **TEST** to verify that your uptime check can connect to the resource.
    
7.  When you see a green check mark everything can connect, click **Create**.
    

### Test completed task

Click **Check my progress** to verify your performed task. If you have completed the task successfully you will be granted an assessment score.

Uptime Check for your group

Check my progress

## **Task 4. Alerting policy for the group**

Use Cloud Monitoring to create one or more alerting policies.

1.  In the left menu, click **Uptime checks**.
    
2.  Click the three dots at the far right of your Display Name and click **Add alert policy**.
    
3.  Click **+Add alert condition**.
    
4.  Select the previously created **Uptime health check on DemoGroup** condition from the left section and click **Delete alert condition**.
    
5.  In your **New condition**, click **Select a metric**.
    
6.  Uncheck the **Active**.
    
7.  In the **Select a metric** field, search `check_passed` and click **VM Instance > Uptime\_check > Check passed**. Click **Apply**.
    
8.  Click **Add a filter**, set the `Filter` to **check\_id** and select **demogroup-uptime-check-id** as the `Value`. Click **Done**.
    

**Note:** If `demogroup-uptime-check-id` check\_id is unavailable, please wait for a few seconds and try.

9.  In the left panel, click on the arrow button next to **VM Instance-Check passed**, then click on **Configure trigger**.
    
10.  Select **Metric absence** as Condition type and click **Next**.
     
11.  Turn off **Configure notifications**.
     
12.  In the **Alert policy name** field, enter the **Name** as **Uptime Check Policy**. Click **Next**.
     
13.  Click **Create policy**.
     

### Test completed task

Click **Check my progress** to verify your performed task. If you have completed the task successfully you will be granted an assessment score.

Alerting Policy for the group

Check my progress

## **Task 5. Custom dashboard for your group**

Create a custom dashboard so you can monitor your group easily.

1.  In the left menu, click **Dashboards**, then click **+Create dashboard**.
    
2.  Name your dashboard.
    
3.  Click **+Add Widget** and select **Line** option in **Visualization**.
    
4.  In the **Metric** field, Uncheck the **Active**.
    
5.  Search **uptime** (compute.googleapis.com/instance/uptime) and click **VM Instance > Instance > Uptime**. Click **Apply**.
    

The dashboard should look like:

![Uptimedashboard](https://cdn.qwiklabs.com/I3RCng2N4Z6hQ1tdIH%2FPNeDvOfobS3JUaVHXYKYKPBc%3D align="left")

6.  Again click on **Apply**.
    

## **Task 6. Remove one instance to cause a problem**

1.  In the console, select **Navigation menu > Compute Engine**.
    
2.  Check the box next to **instance2**, then click on the 3 vertical dots at the top of the page and click **Stop**. Click **Stop** again to turn off the machine.
    
3.  Wait a minute or 2 for the instance to stop and violate the uptime check you just set up. After a couple of minutes, turn your machine back on by clicking **Start/Resume**, then **Start**.
    
4.  Click **Navigation menu > Monitoring > Alerting** and refresh your browser. It may take a few more minutes to show that you have issues in the Summary section. Refresh until you see an Incident similar to this:
    

![Incidents page](https://cdn.qwiklabs.com/SuzfF2zeaShVgEFKsn6lpt5jkBbNQ8HkWlaQt0HO9nQ%3D align="left")

**Optional:** Using the left menu, look at **Dashboards** to view your custom dashboard. This provides details on both VMs. If you mouse over your chart, you can see which of your instances was stopped and restarted.

### Incidents

When the alerting policy conditions are violated, an "incident" is created and displayed in the Incident section.

Responders can acknowledge receipt of the notification and can close the incident when it has been taken care of.

1.  In the **Incidents** section, click on the name of the alerting policy that was violated to go into it.
    

You've already **fixed** your problem by turning the VM back on, so the incident was cleared and you no longer see an incident in the Incidents section.

2.  To see the cleared incident, scroll down and click on the **Show closed incidents** link.
    

Your incident should have a **Closed** status. You can read through the incident details.

3.  You can also click on the **Uptime Check Policy** link to explore the metrics it gives you.
    

In several more minutes the Monitoring Overview page will all go back to green when the instance in Project 2 passes the Uptime Check.

## **(Optional) Remove your alerting policy**

If you set up an email alert as part of your alerting policy, there is a chance that you will receive a few emails about your resources even after the lab is completed.

To avoid this, remove the alerting policy before you complete your lab.

## **Task 7. Test your understanding**

Below is a true/false question to reinforce your understanding of this lab's concepts. Answer it to the best of your ability.

Cloud Monitoring lets you define and monitor groups of resources with Cloud Monitoring Group.

*   <mark class="bg-yellow-200 dark:bg-yellow-500/30">True</mark>
    
*   False
    

* * *

## Solution of Lab

%[https://youtu.be/0QdPVY1mBGA] 

```apache
curl -LO raw.githubusercontent.com/ePlus-DEV/storage/refs/heads/main/labs/GSP090/lab.sh
source lab.sh
```

**Script Alternative**

```apache
curl -LO raw.githubusercontent.com/QUICK-GCP-LAB/2-Minutes-Labs-Solutions/main/Monitoring%20Multiple%20Projects%20with%20Cloud%20Monitoring/gsp090.sh
sudo chmod +x *.sh
./*.sh
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746872453515/42641ca1-7817-47c1-b43b-f6bded79518d.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1746872386638/4c915089-af01-43ff-87c6-d55f2f06c35f.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768987125263/e1d2b149-4b6c-469d-a51d-8a9c288ba2b9.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768987088594/10d08d34-8568-4559-80db-dd802a11a80e.png align="center")

Open: [https://console.cloud.google.com/monitoring/groups/create](https://console.cloud.google.com/monitoring/groups/create)

**Name:** DemoGroup

**value:** instance

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768987292283/258e3d36-9ca8-4be7-890c-77c1c76de13c.png align="center")
