All Products
Search
Document Center

Simple Log Service:Collect metric data from Prometheus by using the Remote Write Protocol

Last Updated:Sep 02, 2024

Prometheus is a cloud native application that you can use to collect and monitor metric data of various software and systems. This topic describes how to collect metric data from Prometheus to Log Service. This topic also describes how to use Log Service to analyze and monitor the data.

Prerequisites

Procedure

Log Service supports the Remote Write Protocol. You can use the remote write feature of Prometheus to collect metric data to Log Service. Before you can use the remote write feature, you must perform the following steps to enable the feature in Prometheus:

  1. Log on to the server on which Prometheus is installed.

  2. Open the configuration file and configure the parameters based on your business requirements. For more information, see remote_write.

    url: https://sls-prometheus-test.cn-beijing.log.aliyuncs.com/prometheus/sls-prometheus-test/prometheus-raw/api/v1/write
    basic_auth:
      username: access-key-id
      password: access-key-secret
    
    queue_config:
      batch_send_deadline: 20s
      capacity: 20480
      max_backoff: 5s
      max_samples_per_send: 2048
      min_backoff: 100ms
      min_shards: 100                      

    Parameter

    Description

    url

    The URL of a Metricstore in Log Service. Format: https://{project}.{sls-endpoint}/prometheus/{project}/{metricstore}/api/v1/write. Take note of the following instructions:

    • {sls-endpoint}: the Log Service endpoint. For more information, see Endpoints.

    • {project}: the project that you created.

    • {metricstore}: the Metricstore that you created.

    Important
    • If you use an Alibaba Cloud internal network, we recommend that you use an internal Log Service endpoint.

    • To ensure secure transmission, we recommend that you use HTTPS.

    basic_auth

    The authentication information. If data is written to Log Service over the Remote Write Protocol, basic authentication is required. Take note of the following instructions:

    • username: the AccessKey ID of your Alibaba Cloud account.

    • password: the AccessKey secret of your Alibaba Cloud account.

    We recommend that you use the AccessKey pair of a RAM user that has only the write permissions on the Log Service project. For more information, see Use custom policies to grant permissions to a RAM user.

    queue_config

    The policies used to write data, such as cache and retry policies.

    To minimize invalid network requests, set min_backoff to a value that is greater than or equal to 100ms and set max_backoff to a value that is greater than or equal to 5s.

    If you want to collect a large amount of metric data from Prometheus, use the following settings for queue_config:

    batch_send_deadline: 20s
    capacity: 20480
    max_backoff: 5s
    max_samples_per_send: 2048
    min_backoff: 100ms
    min_shards: 100
  3. Check whether data is collected to Log Service.

    After you configure Prometheus, you can use the preview feature in the Log Service console to check whether data is collected to Log Service.

    1. Log on to the Log Service console.

    2. In the Projects section, click the name of the project.

    3. On the Time Series Storage > Metricstore tab, choose Modify a Logstore > Consumption Preview next to the name of the Metricstore.

      If data is displayed in the Consumption Preview panel, Prometheus is correctly configured. Prometheus data consumption

What to do next

After metric data is collected from Prometheus, you can perform the following operations on the data: