Alibaba Cloud Managed Service for Prometheus provides HTTP API URLs. You can use an HTTP API URL to import the monitoring data of a Prometheus instance to your self-managed Grafana system, or use the Prometheus API to obtain monitoring data for custom development.
Prerequisites
A Prometheus instance is created. For more information, see the following topics:
Step 1: Obtain the HTTP API URL
Log on to the Managed Service for Prometheus console.
In the left-side navigation pane, click Instances.
In the top navigation bar, select the region where the Prometheus instance is deployed, find the Prometheus instance, and then click Settings in the Actions column.
On the Settings tab, copy a public or internal HTTP API URL.
NoteIf the Prometheus instance is created to monitor an Alibaba Cloud service, select an HTTP API URL based on the type of the cloud service.
Optional: Click Generate Token to obtain the authentication token for the Prometheus instance. The token is used to ensure data security when monitoring data is imported to Grafana.
ImportantAfter the authentication token is generated, you must specify the token when you add the Prometheus instance to your Grafana system as a data source. Otherwise, monitoring data cannot be read from the Prometheus instance.
Step 2: Add the HTTP API URL to the self-managed Grafana system
Configure a data source in the Grafana system.
Log on to the Grafana system as an administrator.
Click the icon in the upper-left corner of the page.
In the left-side navigation pane, choose
.NoteThis menu is visible only to the administrator.
On the Data sources tab, click + Add data source.
On the Add data source page, click Prometheus.
On the Settings tab, enter a dashboard name in the Name field, enter the Prometheus server URL that you obtained in Step 1: obtain the URL of the Prometheus server in the Prometheus server URL field of the HTTP section.
Optional. If you have generated a token, click + Add header in the Custom HTTP Headers section, set the Header parameter to Authorization, and then set the Value parameter to the token generated in Step 1: Obtain the HTTP API URL.
Click Save & test.
Verify the result.
Log on to the Grafana system.
Click the icon in the upper-left corner of the page, and then click Dashboards in the left-side navigation pane.
On the Dashboards page, click New, and then click New dashboard from the drop-down menu.
Click + Add visualization.
On the Select data source page, select a custom data source.
On the Edit Panel page, enter the metric name and value in the Metrics and Label filters fields in the A section of the Query tab, and click Run queries.
If a chart of the metric is displayed, the Prometheus data source is added. If no chart is displayed, the Prometheus data source fails to be added. Check whether the API URL or token is valid, and whether the data source has monitoring data.
Step 3: Obtain the monitoring data of Managed Service for Prometheus
The sample request shows how to call the data of Managed Service for Prometheus. For information about how to use the HTTP API to obtain the data of Managed Service for Prometheus, see Prometheus HTTP API.
GET {HTTP API}/api/v1/query
Accept: application/json
Content-Type: application/json
Authorization: {Token}
{
"query":"arms_prometheus_target_interval_length_seconds_sum",
"time":"1635302655",
"timeout":"1000"
}
Replace the {HTTP API}
parameter with the actual HTTP API URL and the {Token}
parameter with the actual authentication token. For more information, see Step 1: Obtain the HTTP API URL.
Sample response: