Create alerts based on a StoreView

Updated at:

An alert monitoring rule based on a StoreView evaluates the statistical results of a cross-Logstore query, so a single rule can monitor data across all Logstores associated with that StoreView. This topic describes how to prepare the monitoring query, create the rule and its email notifications in the Simple Log Service (SLS) console, and verify that alerts are triggered and delivered.

Prerequisites

  • A StoreView for Logstore associated with the Logstores that you want to monitor. For instructions, see Query and analyze data across Logstores.

  • Your account can query the target StoreView and has the permissions required to create and manage alert monitoring rules.

  • You have identified the monitoring metrics, trigger thresholds, and notification recipients for the alert.

Note

Alerts based on a StoreView are currently supported only for StoreViews for Logstore.

Prepare the monitoring query

The following example counts the total number of logs in the associated Logstores over the last 15 minutes. The alert rule checks the count once every minute, triggers an alert when the count exceeds 100, and sends an email notification. Adjust the time range, check frequency, and threshold to meet your business requirements.

  1. Log on to the Simple Log Service console.

  2. In the project list, click the target project. In the StoreView list, open the target StoreView for Logstore.

  3. Select the last 15 minutes as the time range, enter the following query statement, and then click Query/Analyze.

    * | select count(*) as cnt
  4. Verify that the query succeeds and returns the cnt field and its value.

The results of this aggregate SQL statement usually contain only one row. Even when the log count is 0, the query may return one row with cnt = 0.

Important

cnt is the number of logs within the query time range, not the number of rows in the query results. For example, cnt = 120 means that the query found 120 logs.

Create an alert monitoring rule

Open the rule configuration

You can open the alert rule configuration from either of the following entry points.

Entry point

Procedure

StoreView query page

After you run the monitoring SQL statement, click the bell icon in the upper-right corner of the query area to open the Alert Monitoring Rule panel. Check the data source, query time range, and query statement populated in Query Statistics.

Alert Center

In the target project, open Alert Center. On the Alert Rules tab, click Create Alert. In Query Statistics, click Add, and then open the Advanced Configuration tab.

(Recommended) Run the monitoring SQL statement before you use the shortcut on the query page. If you skip this step, the shortcut populates an empty query.

Configure query statistics

Check or specify the following parameters. Even if the query page has populated the SQL statement, verify that the query time range used by the alert rule meets your monitoring requirements.

Parameter

Configuration

Type

Select StoreView for Logstore.

Authorization Method

Select Default, Built-in Role, or Custom Role based on your authorization scheme. Default authorization is used to query logs or metric stores in the same project as the alert rule. Verify that the selected method can access the target StoreView.

Region

Select the region of the project to which the target StoreView belongs.

Project

Select the project to which the target StoreView belongs.

StoreView

Select the StoreView for Logstore that you want to monitor.

Query Time Range

Select an interval of fixed length, such as 15 Minutes (Relative), to query data from the last 15 minutes at each check.

Query

Enter the count SQL statement that you prepared (* | select count(*) as cnt).

Click Preview in the query statistics configuration dialog box. After you verify that the query succeeds and returns the cnt field, click Confirm to populate the query configuration in the alert rule. If the query input box or the Preview button is not visible, scroll down in the dialog box.

Configure the check frequency and trigger condition

Use the following example to configure the Alert Monitoring Rule panel. Adjust each parameter to meet your monitoring requirements.

Parameter

Example

Rule Name

Enter a descriptive name, such as storeview-log-count-alert.

Check Frequency

Select Fixed Interval and set the interval to 1 Minute.

Group Evaluation

Select No Grouping.

Trigger Condition

Select Data Matches.

Match Expression

Enter cnt > 100.

Severity

Select a severity level based on the business impact.

With these settings, the system runs the query once every minute, counts the logs from the last 15 minutes, and checks whether cnt is greater than 100. Check Frequency determines how often a check runs. Query Time Range determines the time range that each check covers. These are two different parameters.

Select the trigger condition that matches your monitoring objective.

Monitoring objective

Trigger condition

Whether the query returns results

Data Exists

Number of rows returned by the query

Specific Row Count

Whether a statistical field exceeds a threshold, such as cnt > 100

Data Matches

When you select a trigger condition, distinguish the number of result rows from the value of a statistical field.

Note

Do not use Specific Row Count > 100 to determine whether the value of count(*) exceeds 100. Specific Row Count compares the number of rows in the query results. For more information about the alert rule parameters, see Create an alert monitoring rule.

Configure email notifications

  1. In Output Destinations, select SLS Notification and turn on Enable for that output destination.

  2. In the alert policy, select Simple Mode.

  3. In the action group, set the notification channel to Email, select Static Recipients, and add the users who need to receive email notifications.

  4. Select a content template that suits your business, and then set the sending period and repeat interval.

To add a recipient

  1. Click Add next to the recipient field.

  2. Assign the recipient an unused unique identifier, such as storeview-alert-user. Enter the actual name and email address of the recipient, and keep the user enabled.

  3. Save the recipient, return to the alert rule page, and click the refresh icon next to the recipient field.

  4. Search for and select the new user. Verify that the user appears as a selected recipient. Entering search text alone does not add a recipient.

  • Simple Mode — Automatically creates the corresponding action policy.

  • Repeat interval — Controls how often notifications for repeated alerts are sent.

  • Content template — Before you use the rule in production, verify that the email subject and body suit the monitoring scenario.

Save and verify

After you complete the configuration, click OK to save the rule. Check the following items in sequence.

Verification stage

Where to check

What to check

Rule saved

Alert rule list and rule details in the target project

The rule is created. Its name, query configuration, check frequency, and trigger condition are correct, and the rule is enabled.

Execution and triggering

Alert history of the rule

The query runs successfully. When the condition is met, Alert Triggered is true.

Notification delivery

Mailbox of the recipient

The corresponding email is received. The rule name, project, and trigger time match the alert execution record.

Saving the rule does not mean that an alert has been triggered, and successful query execution does not mean that the trigger condition is met. Verify email delivery separately.

To verify the notification path first, create a separate test rule. Use the count SQL statement * | select count(*) as cnt and temporarily set the trigger condition to Specific Row Count > 0. This condition tests whether a notification can be triggered when the query returns one row. It does not prove that the business log count is greater than 0. After verification, disable the test rule and use the actual business threshold for the production rule.

FAQ

Issue

Resolution

The StoreView can be queried but cannot be selected in the alert configuration.

Verify that Type is set to StoreView for Logstore. Check the region, project, StoreView name, permissions, and feature availability. This symptom alone does not identify the root cause.

The shortcut populates an empty query.

Return to the StoreView query page, enter and run the SQL statement, and then click the bell icon again.

The rule runs successfully but does not trigger an alert.

Check whether the returned field value meets the expression. In particular, distinguish the number of result rows from the value of cnt.

An alert is triggered, but no email is received.

Check the SLS Notification switch, the selected recipients, the email addresses, the action policy, the sending period, and the repeat interval. Then search the mailbox and check the spam folder.

The email subject does not match the monitoring content.

Check the email subject and body configuration in the selected content template.

References