Introduction
We all have worked on Cloud. But have you ever wondered how to monitor a query language?
Don't worry. Coding ninjas have got your back.
Let's explore how to monitor the query language in cloud monitoring.
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 the 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:
1.Select Monitoring from the Google Cloud console menu.
2. Choose Metrics Explorer under Monitoring.
3. Choosing the MQL tab.
Perform a simple query and create a chart
Make a simple query that displays your instance's CPU usage:
1.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. The graph shows the maximum and minimum CPU use for your instance on two lines:
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:
Source-Cloud Monitoring
- 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:
fetch gce_instance::compute.googleapis.com/instance/cpu/usage_time
| window 1m
| condition val() > 2 's'
- To view the chosen data and a threshold line, click Run Query.
- Use the Condition pane as shown to receive an alert when your instance's CPU consumption reaches the threshold and persists there for five minutes:
- Set the For field's value to five minutes.
- Keep the value in the Condition triggers if the field is unchanged.
- Click Add to save your condition in your alerting policy.
5. To go to the following step, which is creating notifications, click Next.
6. Click OK after selecting the notification channel you previously established.
7. In order to save your policy, click Save.
Clean up
Follow these instructions to prevent your Google Cloud account from being charged for the resources used on this page.
1.Go to the Google Cloud console's Identity and Access Management page.
2. After selecting Shut down, proceed as directed.