arrow_back

Using Elastic Stack to Monitor Google Cloud

Sign in Join
Test and share your knowledge with our community!
done
Get access to over 700 hands-on labs, skill badges, and courses

Using Elastic Stack to Monitor Google Cloud

Lab 1 hour 30 minutes universal_currency_alt 1 Credit show_chart Introductory
Test and share your knowledge with our community!
done
Get access to over 700 hands-on labs, skill badges, and courses

This lab was developed with our partner, Elastic. Your personal information may be shared with Elastic, the lab sponsor, if you have opted in to receive product updates, announcements, and offers in your Account Profile.

Note: This lab requires a partner trial account. Please follow the lab instructions to create your trial account before starting the lab.

GSP992

Google Cloud self-paced labs logo

Overview

In this lab, you will learn how to use the Elastic Stack to monitor Google Cloud. You will start by creating a simple Elasticsearch deployment using Elastic Cloud.

The goal of this lab will be to install and deploy Elasticsearch then use Beats, which are Elastic's lightweight data shippers, which sends operational data - logs and metrics - from systems and applications. You will use Beats to collect and monitor your services on Google Cloud.

What you'll learn

In this lab, you learn how to perform the following tasks:

  • Create a deployment using Elastic Cloud
  • Install and configure Beats to send data to Elasticsearch
  • Use Kibana to visualize the ingested data

Prerequisites

This is an introductory level lab. No prior knowledge of Elastic and its various products and features are required, though basic system configuration, such as knowing how to run commands via a Linux based command line, and editing text files using a Unix based text editor (like Vim or Nano) is advantageous.

There is a Vim Tips section in this lab in case you need a little help or refresher to get the standard text editing accomplished.

Note: Be careful when modifying YAML files. Formatting irregularities, including spaces, can lead to a failed configuration file. It is best not to copy and paste quotation marks between systems, as they can cause an issue with these types of configuration files as well. There is very little to edit, so edit the files directly.

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.

    {{{user_0.username | "Username"}}}

    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.

    {{{user_0.password | "Password"}}}

    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

Activate Cloud Shell

Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.

  1. Click Activate Cloud Shell Activate Cloud Shell icon at the top of the Google Cloud console.

When you are connected, you are already authenticated, and the project is set to your Project_ID, . The output contains a line that declares the Project_ID for this session:

Your Cloud Platform project in this session is set to {{{project_0.project_id | "PROJECT_ID"}}}

gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.

  1. (Optional) You can list the active account name with this command:
gcloud auth list
  1. Click Authorize.

Output:

ACTIVE: * ACCOUNT: {{{user_0.username | "ACCOUNT"}}} To set the active account, run: $ gcloud config set account `ACCOUNT`
  1. (Optional) You can list the project ID with this command:
gcloud config list project

Output:

[core] project = {{{project_0.project_id | "PROJECT_ID"}}} Note: For full documentation of gcloud, in Google Cloud, refer to the gcloud CLI overview guide.

Vim tips

  1. You can go to a specific line by entering the :(colon sign), the line number, then the Enter key.
  2. Use your arrows to move up, down, left, or right.
  3. Use the letter x to remove letters or symbols, unless in insert mode, where you will use the keyboard's normal delete/backspace keys.
  4. Enter the letter i to enter into insert mode where you will then be able to add/remove text.
  5. Once your edit is complete press the Esc key to exit out of insert mode, where you will then write/save the file by entering everything everything below, including the colon sign:
:wq

This is to say, you enter a : then wq which writes the file and quits the vim editor as soon as pressing the enter key.

Task 1. Create an Elastic deployment

Elasticsearch is a real-time, distributed storage, search, and analytics engine. It can be used for many purposes, but one context where it excels is indexing streams of semi-structured data, such as logs or decoded network packets.

In this section, you will first need to sign up for an Elastic free trial with your personal email address. You will then log into Elastic Cloud and create a deployment.

Create a deployment

  1. First, sign up for a free trial.
  • Click Start free trial.
  • Use your personal email, you'll need to go to your inbox to verify your email address.
Note: You must use your personal email, not your student account, don't attempt to sign up with google, unless you sign out of your lab account first. If you attempt to sign up with your student id, your trial will be rejected or canceled.

You should be redirected to Elastic Cloud.

  1. On the Create deployment page, give your deployment a name (i.e my-lab-demo) and choose the closest Google Cloud region to you.

  2. Click Create Deployment.

  3. Download or copy and save the password for the Elastic user, as you will use this later in the lab.

Note: The deployment can take up to 5 minutes. While you're waiting for the deployment, navigate to your email and open the sign-up email sent by Elastic to verify your email address.
  1. Once your deployment is ready, click Continue.

  2. On the Welcome Page, click Explore on my own.

Task 2. Set up a service account

Google Cloud implements service accounts as a way to access APIs securely. To monitor Google Cloud with Elastic, you will need a service account. The easiest way is to use a predefined service account that Google Cloud creates automatically. Alternatively, you can create a new service account. In this lab, you will create a new one.

  1. First, navigate to the Google Cloud Console. To access the service account menu, click Navigation Menu > IAM & Admin > Service Accounts.

  2. Next, click Create Service Account. For the new service account name, use gcp-monitor. Optionally add a description (for example, "Service account to monitor Google Cloud services using the Elastic Stack"). Click Create and Continue.

  3. Next, add three main roles to the service account to monitor Google Cloud services:

  • Compute Viewer
  • Monitoring Viewer
  • Pub/Sub Admin

The step two, Grant this service account access to project (optional), section

  1. Click Continue, then skip granting users access to this service.

  2. Finally, click Done. The service account is now ready to be used.

  3. Next, to use the service account just created gcp-monitor, click Manage keys.

The Manage keys option highlighted in the expanded More menu

  1. On the Keys page, click Add Key > Create new key.

  2. Select JSON as the type and click Create.

  3. After clicking Create, the credential file is downloaded. Rename the file as credentials.json. Keep this file in an accessible place to use later.

  4. Click Close.

Click Check my progress to verify the objective. Set up a Service Account

Task 3. Install beats

To monitor Google Cloud using the Elastic Stack, you need two main components: an Elastic deployment to store and analyze the data and an agent to collect and ship the data.

Two agents can be used to monitor Google Cloud:

  • Metricbeat is used to monitor metrics
  • Filebeat to monitor logs.

You can run the agents on any machine. For this lab, you will be using Cloud Shell.

Install Metricbeat

  1. Navigate to Cloud Shell.

  2. Download and install Metricbeat:

curl -L -O https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-7.14.0-linux-x86_64.tar.gz tar xzvf metricbeat-7.14.0-linux-x86_64.tar.gz cd metricbeat-7.14.0-linux-x86_64/

Set up assets

  • Metricbeat comes with predefined assets for parsing, indexing, and visualizing your data. Run the following command to load these assets. It may take a few minutes.
Note: Substitute your Cloud ID and an administrator's username:password in this command. To find your Cloud ID, click on your deployment. ./metricbeat setup -e -E 'cloud.id=YOUR_DEPLOYMENT_CLOUD_ID' -E 'cloud.auth=elastic:YOUR_SUPER_SECRET_PASS'

Configure Metricbeat output

Next, you are going to configure Metricbeat output to Elasticsearch Service.

  1. Use the Metricbeat keystore to store secure settings. Store the Cloud ID in the keystore:
./metricbeat keystore create echo -n "<Your Deployment Cloud ID>" | ./metricbeat keystore add CLOUD_ID --stdin

To store metrics in Elasticsearch with minimal permissions, create an API key to send data from Metricbeat to Elasticsearch Service.

  1. Log into Kibana by navigating to your Elastic Cloud Deployments page and clicking Kibana on the left navigation menu.

The Kibana tabbed page

  1. Click Open.

  2. Select Management > Dev Tools.

The Management page with the Dev Tools button highlighted

  1. Send the following request. Click the play button to send the request:
POST /_security/api_key { "name": "metricbeat-monitor", "role_descriptors": { "metricbeat_writer": { "cluster": ["monitor", "read_ilm"], "index": [ { "names": ["metricbeat-*"], "privileges": ["view_index_metadata", "create_doc"] } ] } } }
  1. The response contains an api_key and an id field, which can be stored in the Metricbeat keystore in the following format: id:api_key:
echo -n "<API ID>:<API KEY>" | ./metricbeat keystore add ES_API_KEY --stdin Note: Make sure you specify the -n parameter; otherwise, you will have painful debugging sessions due to adding a newline at the end of your API key
  1. To see if both settings have been stored, run the following command:
./metricbeat keystore list
  1. To configure Metricbeat to output to Elasticsearch Service, edit the metricbeat.yml configuration file. Add the following lines to the end of the file:
cloud.id: ${CLOUD_ID} output.elasticsearch: api_key: ${ES_API_KEY}
  1. Finally, test if the configuration is working. If it is not working, verify if you used the right credentials and add them again:
./metricbeat test output

Now that the output is working, you are going to set up the input (Google Cloud).

Task 4. Configure Metricbeat Google Cloud Platform

To collect metrics from Google Cloud use the Google Cloud Platform module. This module periodically fetches monitoring metrics from Google Cloud Platform using Stackdriver Monitoring API for Google Cloud Platform services.

Note: Extra Google Cloud charges on Stackdriver Monitoring API requests may be generated by this module. For more information, please see rough estimation of the number of API calls.
  1. From the Cloud Shell toolbar, click the three dots (More icon) on the navigation menu and select Upload.

The More icon and the Upload option highlighted

  1. Select your service account JSON key file (exported in the first section) and upload it to Cloud Shell. Note the location of the file as you will be using it in this section.

  2. Next, run the following command to enable the Metricbeat GCP module.

./metricbeat modules enable gcp
  1. Navigate to the metricbeat folder then modules.d/gcp.yml file

  2. Replace the entire contents of the file with the following configurations. Make sure to replace project_id and credentials_file_path with the your correct values:

- module: gcp metricsets: - compute region: {{{ project_0.startup_script.region | Region }}} project_id: "your-project-id" credentials_file_path: "your-credentials-file-path" exclude_labels: false period: 1m Note: credentials.json is the file that you generated earlier.

Your file should resemble the following:

The open gcp.yaml3 file displaying lines one to 11

  1. To check if Metricbeat can collect data, test the input by running the following command:
./metricbeat test modules gcp

Metricbeat will print Google Cloud metrics to the terminal, if the setup is correct.

  1. When the input and output are ready, start Metricbeat to collect the data:
./metricbeat -e
  1. Finally, navigate back to Kibana and search for the [Metricbeat GCP] Compute Overview dashboard. Click the result to open the dashboard.

The compute overview search results with '[Metricbeat GCP] Compute Overview' selected

After a few minutes or so, your dashboard should resemble the following:

The [Metricbeat GCP] Compute Overview dashboard

Task 5. Install Filebeat

Now that Metricbeat is up and running, configure Filebeat to collect Google Cloud logs.

  • Open a new Cloud Shell tab, and run the following commands:
curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.14.0-linux-x86_64.tar.gz tar xzvf filebeat-7.14.0-linux-x86_64.tar.gz cd filebeat-7.14.0-linux-x86_64

Set up assets

Filebeat comes with predefined assets for parsing, indexing, and visualizing your data.

  • Run the following command to load these assets. It may take a few minutes.
Note: Substitute your Cloud ID and an administrator's username:password in this command. To find your Cloud ID, click on your deployment. ./filebeat setup -e -E 'cloud.id=YOUR_DEPLOYMENT_CLOUD_ID' -E 'cloud.auth=elastic:YOUR_SUPER_SECRET_PASS' Note: You may encounter some warnings or errors regarding setting up ML for nginx_ecs or apache_ecs. It's safe to ignore these and continue on with the lab.

Configure Filebeat output

Next, configure Filebeat output to Elasticsearch Service.

  1. Use the Filebeat keystore to store secure settings. Store the Cloud ID in the keystore:
./filebeat keystore create echo -n "<Your Deployment Cloud ID>" | ./filebeat keystore add CLOUD_ID --stdin
  1. To store logs in Elasticsearch with minimal permissions, create an API key to send data from Filebeat to Elasticsearch Service.
  • Log into Kibana (you can do so from the Cloud Console without typing in any permissions).
  • Open the left Navigation menu, scroll down and select Management > Dev Tools.
  • Send the following request. Click the play button to send the request:
POST /_security/api_key { "name": "filebeat-monitor-gcp", "role_descriptors": { "filebeat_writer": { "cluster": [ "monitor", "read_ilm", "cluster:admin/ingest/pipeline/get", "cluster:admin/ingest/pipeline/put" ], "index": [ { "names": ["filebeat-*"], "privileges": ["view_index_metadata", "create_doc"] } ] } } } Note: Filebeat needs extra cluster permissions to publish logs, which differs from the Metricbeat configuration. You can find more details here.
  1. The response contains an api_key and an id field, which can be stored in the Filebeat keystore in the following format: id:api_key:
echo -n "<API ID>:<API KEY>" | ./filebeat keystore add ES_API_KEY --stdin Note: Make sure you specify the -n parameter; otherwise, you will have painful debugging sessions due to adding a newline at the end of your API key
  1. To see if both settings have been stored, run the following command:
./filebeat keystore list
  1. To configure Filebeat to output to Elasticsearch Service, edit the filebeat.yml configuration file. Add the following lines to the end of the file:
cloud.id: ${CLOUD_ID} output.elasticsearch: api_key: ${ES_API_KEY}
  1. Finally, test if the configuration is working:
./filebeat test output

Now that the output is working, you are going to set up the input (Google Cloud).

If it is not working, verify that you used the right credentials and, if necessary, add them again.

Task 6. Configure Filebeat Google Cloud module

To collect logs from Google Cloud, use the Google Cloud Platform module. This module periodically fetches logs that have been exported from Cloud Logging to a Pub/Sub topic sink. There are three available filesets: audit, vpcflow, firewall. This lab covers the audit fileset.

  1. Use the search bar to find the Log Router page, where you'll configure Google Cloud to export logs to a Pub/Sub topic.

  2. To set up the logs routing sink, click Create sink. Set sink name as monitor-gcp-audit-sink.

  3. Click Next.

  4. Under sink service select Cloud Pub/Sub topic and under select a cloud pub/sub topic click Create a Topic, enter monitor-gcp-audit as Topic id, then click Create Topic.

  5. Click Next.

  6. Finally, under Choose logs to include in sink, add logName:"cloudaudit.googleapis.com" (it includes all audit logs).

  7. Click Create Sink. It will look something like the following:

​​The Create logs routing sink page with the following populated sections: Sink details, Sink destination, Choose logs to include in sink, and Choose logs to filter out of sink (optional)

Click Check my progress to verify the objective. Create sink

  1. Now that Google Cloud is configured to export audit logs, run the following to enable the Filebeat Google Cloud module:
./filebeat modules enable gcp
  1. Navigate to the filebeat folder then to modules.d/gcp.yml file.

  2. Replace the entire contents of the file with the following configurations. Make sure to update var.project_id and var.credentials_file with the your correct values:

- module: gcp vpcflow: enabled: false firewall: enabled: false audit: enabled: true var.project_id: "your-project-id" var.topic: "monitor-gcp-audit" var.subscription_name: "monitor-gcp-audit-sub" var.credentials_file: "your-credentials-file-path"
  1. Start Filebeat to collect the logs:
./filebeat -e
  1. Finally, log into Kibana and open the [Filebeat GCP] Audit dashboard.

The [Filebeat GCP] Audit dashboard

After a few minutes, you should see incoming data in the dashboard.

Click Check my progress to verify the objective. Configure Filebeat Google Cloud module

Congratulations!

In this lab you created a deployment using Elastic Cloud, installed and configured Beats to send data to Elasticsearch, then finally used Kibana to visualize the ingested data.

Next steps / Learn more

  • Elastic on the Google Cloud Marketplace!
  • Elastic Cloud offers a fully managed experience so that you can focus on your data instead of managing the cluster. You can check it out here and play with a free trial.
  • Check out the Elastic Integrations page and see how easily you can stream in logs, metrics, traces, content, and more from your apps, endpoints, infrastructure, cloud, network, workplace tools, and every other common source in your ecosystem.
  • Leverage the out-of-the-box solutions to give your Elastic project a jump start!

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 25, 2023

Lab Last Tested: September 25, 2023

Copyright 2024 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.