All Products
Search
Document Center

Container Service for Kubernetes:View alert events of Services

Last Updated:Oct 31, 2023

This topic describes how to use Simple Log Service to collect log data from Knative and configure alert rules based on the collected log data.

Prerequisites

Procedure

  1. Deploy a Knative Service named helloworld-go. For more information, see Use Knative to deploy serverless applications.

  2. Enable log collection for the Service. For more information, see Collect application logs.

  3. Configure statements to query and analyze logs.

    For more information, see Log analysis overview.

    1. Log on to the Simple Log Service console. Click the name of the project that you want to manage and view the created Logstores in the Logstores list.

    2. Click the name of the Logstore that you want to query.

    3. Enter a statement into the search box below the Logstore name and click Search & Analyze.

      For example, to monitor Services based on the number of errors that have occurred, enter the following SQL statement:

      * | select 'ERROR' , count(1) as total group by 'ERROR'

      This SQL statement lists all records that contain the error field, counts the number of the records, and then classifies the records by error.

      image.png
  4. Configure alert rules.

    1. Log on to the Log Service console.

    2. In the Projects section, click the project that you want to manage.

    3. On the Log Storage > Logstores tab, click the Logstore that you want to manage.

    4. On the query and analysis page, click the 告警图标 icon.

    5. In the Alert Monitoring Rule panel, set the parameters as required.

      For more information about how to configure alert rules, see Create an alert monitoring rule for logs.

    6. Configure alert notification policies.

      For more information about how to configure alert notification policies, see Configure an alert monitoring rule in Simple Log Service.

  5. Run the following command to access the helloworld-go Service:

    An alert is triggered.

    curl -H "Host: helloworld-go.default.example.com" http://<Gateway IP address> # Replace the gateway IP address and domain name with the actual values.

    Expected output:

    Hello Knative!
  6. You are notified by email if setting up email notifications.

Summary

After you configure alert rules in Simple Log Service, you can identify application exceptions in Knative and then send notifications to O&M engineers and developers at the earliest opportunity to ensure business continuity.