Metricstores of Log Service are compatible with the query API of Prometheus. This topic describes how to connect Log Service as a Prometheus data source to Grafana. You can then send data from Log Service to Grafana and visualize the data in Grafana.
Prerequisites
- Grafana is installed. For more information, see Install Grafana.
- Time series data is imported to Log Service. For more information, see Collect metric data from Prometheus by using the Remote Write Protocol.
Configure Log Service as a Prometheus data source in Grafana
- Log on to Grafana.
- In the left-side navigation pane, choose .
- On the Data Sources tab, click Add data source.
- Move the pointer over the Prometheus card and click Select.
- On the Settings tab, set the following parameters.
Parameter or section Description Name Set a name for the data source, for example, Prometheus-01. HTTP - URL: Enter the URL of the Metricstore. Format: https://{project}.{sls-endpoint}/prometheus/{project}/{metricstore}. Replace {sls-endpoint} with the Log Service endpoint in the region where the project resides. For the list of Log Service endpoints in different regions, see Endpoints. Replace {project} and {metricstore} with the project name and Metricstore name. Example: https://sls-prometheus-test.cn-hangzhou.log.aliyuncs.com/prometheus/sls-prometheus-test/prometheus. Note To ensure secure transmission, use HTTPS.
- Whitelisted Cookies: Specify a whitelist for access. This parameter is optional.
Auth Select the Basic Auth check box. Basic Auth Details - User: Enter an AccessKey ID.
- Password: Enter an AccessKey secret that corresponds to the AccessKey ID.
- URL: Enter the URL of the Metricstore. Format: https://{project}.{sls-endpoint}/prometheus/{project}/{metricstore}. Replace {sls-endpoint} with the Log Service endpoint in the region where the project resides. For the list of Log Service endpoints in different regions, see Endpoints. Replace {project} and {metricstore} with the project name and Metricstore name. Example: https://sls-prometheus-test.cn-hangzhou.log.aliyuncs.com/prometheus/sls-prometheus-test/prometheus.
- Click Save & Test.
Import a Log Service dashboard template to Grafana
Perform the following steps to import a Log Service dashboard template to Grafana:
- Copy the template ID.
- Log on to the dashboard market of Grafana.
- Click the template.
- On the right side of the page, click Copy ID to Clipboard.
- Log on to Grafana.
- In the left-side navigation pane, choose .
- In the Grafana.com Dashboard field, paste the template ID that you copied in Step 1.
Then, click a blank area to go to the page for data source configuration.
- Configure the data source.
In this step, set the parameters based on the data source that you added when you configure Log Service as a Prometheus data source in Grafana. The parameters vary depending on the dashboard template. The parameters may include telegraf and host.
- Click Import.
Access Log Service by using the query API of Prometheus
Log Service is compatible with the query API of Prometheus. You can configure Log Service as a Prometheus data source in Grafana or use the Prometheus API to access Log Service. The following table provides examples of the supported API operations.
Operation | Example |
---|---|
Instant queries |
|
Range queries |
|
Getting label names |
|
Querying label values |
|
Finding series by label matchers |
|