Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
We all have heard the concept of cloud monitoring, and while working on Cloud Monitoring, we have to monitor a Compute Engine virtual machine (VM) instance. So this blog will help you in doing this.
So let's dive into the topic to learn more about it.
Cloud Monitoring
Cloud Monitoring gathers data from hosted uptime probes, application instrumentation, Google Cloud, Amazon Web Services (AWS), and events.
Monitor a Compute Engine virtual machine
You perform the following in this quickstart:
A Compute Engine VM instance should be created.
Activate the Apache HTTP Server.
The Cloud Monitoring and Logging agents should be installed.
Make a check for uptime that includes an alerting policy.
Make a dashboard and chart that are unique.
Observe your logs.
Cleaning up
Creating a Compute Engine instance
1.Go to Compute in the Google Cloud console, and then pick Compute Engine:
3. For your instance, complete the fields as follows:
Enter lamp-1-vm in the Name field.
Select Small in the Machine type field.
Make sure Debian GNU/Linux is configured on the boot disk.
Select Allow HTTP traffic as well as Allow HTTPS traffic in the Firewall area.
4. Press Create. On the VM Instances page, wait a few minutes for your instance to start up.
5. Select SSH under Connect in the Connect column to launch a terminal to your instance.
6. Update your instance's package lists
sudo apt-get update
7. Set up the HTTP server Apache2.
sudo apt-get install apache2 php7.0
8. Open your browser and go to http://[External IP] to connect to your Apache2 HTTP server. The external IP address of your Compute Engine instance should be used in place of [External IP]. You see the default page for Apache2:
Installing agents
The VM instance's logs and metrics are delivered to Cloud Monitoring and Logging by the agents:
1.Either open a new terminal or switch to the one connected to your VM instance.
2. Activate the Cloud Monitoring agent after installation:
Update the package list and add the package repository:
For instance, if you want to delete, check the box.
Click more to remove the instance. Click on More, then Delete, and then adhere to the directions.
Setting up Datalab to use with Cloud Monitoring.
In this, you'll learn how to configure Datalab for use with your projects for cloud monitoring. You can run ad hoc analyses and visualisations with Datalab's dynamic notebooks that go beyond what Monitoring currently offers.
Setting up Datalab
From a terminal window on your local system, carry out the following actions:
1.Obtain the latest gcloud command:
$ gcloud components update
2. The gcloud datalab component should be installed:
$ gcloud components install datalab
3. Run the following command after changing [PROJECT ID] with your Google Cloud project ID to set up gcloud to connect to your Google Cloud project ID:
$ gcloud config set project [PROJECT_ID]
Run the upcoming command to confirm the configuration:
$ gcloud config get-value project
4. Run the following command to create a Datalab instance, substituting [DATALAB-INSTANCE-NAME] with the name of your instance. All names must start with a lowercase letter, have no more than 62 lowercase letters, numerals, or hyphens, and not include a hyphen at the conclusion.
$ datalab create [DATALAB-INSTANCE-NAME]
5. While the datalab command is in use, the connection to your Datalab instance is still active. The connection is cut off if the terminal command window is closed or stopped. Run the next command to restart the connection:
$ datalab connect [DATALAB-INSTANCE-NAME]
The Datalab Interface
The URL for the newly opened browser window when you run the datalab connect command is http://127.0.0.1:8081/. The Datalab home page is shown on this page:
You can explore a number of Datalab getting started notebooks, including notebooks for cloud monitoring, in the Datalab docs/ subdirectory.
Monitoring tutorials
There are various interactive Monitoring lessons installed with Datalab:
Getting Started:
Shows how to integrate the Python Google Cloud's operations suite API into Datalab and specify your default Google Cloud project ID. The API is called using sample code, and monitoring data from your project is obtained.
Group metrics
Shows how to analyze a project's group structure and how to use groups to aggregate and filter metric data. You must set up a Cloud Monitoring group in order to use group metrics. To learn more, go to Using resource groups.
Time-Shifted data
Demonstrates some intriguing techniques to modify time series data. The tutorial is set up to potentially use previously-extracted data from a demonstration project because your project might not have enough VM instances to be a decent example.
Running the tutorials
Follow these steps to run the tutorials:
In the Datalab interface, select Docs, Tutorials, and Stackdriver Monitoring.
Choosing the tutorial. Select the tutorial by clicking its name.
Set the project ID to Your Google Cloud project ID should be substituted for my-project-id in the column that contains set datalab project id('my-project-id').
Start the tutorial program. Select Run > Run all cells from the menu bar at the top of the screen. This executes all of the tutorial's code again using your current project ID.
Cleaning up
Please follow these instructions to prevent your Google Cloud account from being charged for the resources used on this page.
Close any open notebooks by clicking the Running Sessions button in the top-right corner of the Datalab interface. If necessary, you can restart them later. Close any related browser windows or tabs.
Close the Datalab tab in your browser by pressing CTRL-C in the Datalab window.
From the moment the Datalab VM instance is created until it is deleted, you are responsible for paying charges. After the Datalab VM has been deleted, the Persistent Disk continues to exist until you destroy it.
The datalab create command generates extra resources that can be used by other Datalab instances you create.
Delete the firewall rule that permits SSH access to your Datalab instances, datalab-network-allow-ssh:
Delete the default connection made by Datalab instances to the datalab-network Virtual Private Cloud (VPC) network:
$ gcloud compute networks delete datalab-network
Delete the notebook storage repository you created, datalab-notebooks Cloud Source Repository.
$ gcloud source repos delete datalab-notebooks
5. Delete any projects or VM instances you don't wish to maintain from your creations.
Set up a query-based alert by using MQL
In this, you'll learn how to explore metrics, make charts, and set up a query-based alert using Monitoring Query Language (MQL).
Create a Compute Engine instance
Create a Compute Engine instance by completing following steps to have a Google Cloud resource to get metrics from:
1.Choose Compute Engine from the menu on the Google Cloud console.
2. Click Create after selecting Create instance.
Navigate to the Query Editor
Start by performing the following to use MQL:
Select Monitoring from the Google Cloud console menu.
Choose Metrics Explorer under Monitoring.
Choosing the MQL tab.
Perform a simple query and then create a chart
Make a simple query that displays your instance's CPU usage:
In the Query Editor, copy the following query and past it
fetch gce_instance::compute.googleapis.com/instance/cpu/utilization
| {
top 1, max(val())
;
bottom 1, min(val())
}
| union
2. Select Run Query.
3. Click Save Chart to store the chart. Give the chart a name and then add it to a dashboard that already exists or create a new one.
Set up a query-based alert
You can design an alerting strategy that keeps track of a query's outcomes. Complete the following actions to develop such an alerting policy:
1.Pick Monitoring, then select Alerting from the console's menu.
2. Click Edit Notification Channels on the Alerting page. You set up an email address in this stage to receive alert messages.
Scroll down to Email on the Notification channels page and click Add.
In the Email Address area, type the email address where you want alert notifications sent.
In the Display name area, type a precise summary of this channel, such as "Alert on-call."
Click on Save.
By clicking Back on the page header, you can return to the Alerting page.
3. Click on Create Policy on the Alerting page.
4. Click Add Condition to specify what you want the alert to be about. The form-based condition editor appears when this action is taken.
Clicking on code Query Editor will switch to the Query Editor window of the condition editor. The Query Editor and a Configuration pane are included in this version of the condition editor:
Give your condition a name, e.g., "MQL Quickstart condition."
Enter the following command to receive a notification when the CPU utilization time for your instance exceeds 2 seconds:
2. After selecting Shut down, proceed as directed.
Frequently asked questions
What is called a cloud?
The term "the cloud" describes the software and databases that run on servers that may be accessed via the Internet.
What is the Cloud Controls Matrix?
The Cloud Controls Matrix (CCM) from the Cloud Security Alliance is a tool created expressly to help potential cloud customers and cloud vendors analyze the overall security risk of a cloud provider.
What is AWS?
AWS (Amazon Web Service) is an online platform that offers scalable and affordable cloud computing solutions.
What is troubleshooting?
A methodical method of problem-solving known as troubleshooting is frequently used to identify and resolve problems with sophisticated machinery, electronics, computers, and software systems.
For what Compute Engines are used?
The Google infrastructure can be used to build and run virtual machines using Compute Engine, a customized compute service.
Conclusion
This blog has extensively discussed Monitoring a compute engine VM.
We hope this blog has helped you in enhancing your knowledge about monitoring a compute engine virtual machine. If you want to learn more, check out the excellent content on the Coding Ninjas Website: