When you run a self-managed Prometheus server, you are responsible for storage capacity, retention, and high availability of your metrics data. Managed Service for Prometheus provides a standard remote_write endpoint that lets you forward metrics from your self-managed Prometheus to a managed instance, where you can collect and view custom data.
How it works
Your self-managed Prometheus server scrapes targets and stores metrics locally.
The
remote_writesection inprometheus.ymlsends a copy of every scraped sample to the Managed Service for Prometheus endpoint over HTTP.Managed Service for Prometheus ingests the data. You can then query it through dashboards in the built-in console.
The remote write endpoint does not support HTTP/2.
Prerequisites
Before you begin, make sure that you have:
A Managed Service for Prometheus instance. See the Create a Prometheus instance section of the Manage Prometheus instances topic
An AccessKey pair (AccessKey ID and AccessKey secret) for an Alibaba Cloud account or a RAM user with the required permissions. See Obtain an AccessKey pair
Open-source Prometheus installed on a server that can reach the remote write endpoint. See Prometheus downloads
Quick start
Add the following remote_write block to your existing prometheus.yml and restart Prometheus:
remote_write:
- url: "<remote-write-url>"
basic_auth:
username: "<accesskey-id>"
password: "<accesskey-secret>"| Placeholder | Value |
|---|---|
<remote-write-url> | The remote write URL from your Managed Service for Prometheus instance settings. See Get the remote write URL |
<accesskey-id> | Your Alibaba Cloud account or RAM user AccessKey ID |
<accesskey-secret> | Your Alibaba Cloud account or RAM user AccessKey secret |
For the full setup, follow the steps below.
Grant permissions to a RAM user (optional)
Skip this step if you use an Alibaba Cloud account AccessKey pair. If you use a Resource Access Management (RAM) user AccessKey pair instead, grant the RAM user full permissions on Application Real-Time Monitoring Service (ARMS) first.
Log on to the RAM console with an Alibaba Cloud account or as a RAM administrator.
In the left-side navigation pane, choose Permissions > Grants.
On the Permission page, click Grant Permission.
In the panel that appears, configure the following parameters:
The
AliyunARMSFullAccesspolicy grants full permissions on ARMS, including the ability to view, modify, and delete all instances managed in ARMS.Parameter Description Resource Scope Select a scope based on your requirements Principal Select the RAM user Policy Select AliyunARMSFullAccess Click Grant permissions, then click Close.
Get the remote write 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 your Prometheus instance resides. Find your instance and click Settings in the Actions column.
On the Settings tab, copy the remote write URL for importing data over the Internet or internal network.
URL type When to use Internet URL Your self-managed Prometheus server is outside the Alibaba Cloud network Internal network URL Your self-managed Prometheus server runs on an Alibaba Cloud ECS instance 
Configure remote write in Prometheus
Add a remote_write section to your prometheus.yml file:
remote_write:
- url: "<remote-write-url>"
basic_auth:
username: "<accesskey-id>"
password: "<accesskey-secret>"Replace the following placeholders with your actual values:
| Placeholder | Description | Example |
|---|---|---|
<remote-write-url> | The remote write URL you copied in the previous step | http://ts-xxxxxxxxxxxx.hitsdb.rds.aliyuncs.com:3242/api/prom_write |
<accesskey-id> | The AccessKey ID of your Alibaba Cloud account or RAM user | LTAI5tXxx |
<accesskey-secret> | The AccessKey secret of your Alibaba Cloud account or RAM user | xXxXxXx |
After you save the file, restart Prometheus to apply the configuration.
The basic_auth credentials are required for both Internet and internal network remote write URLs.Full configuration example
If you are setting up Prometheus from scratch, here is a complete prometheus.yml that scrapes the local Prometheus server and forwards all metrics to Managed Service for Prometheus:
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
remote_write:
- url: "<remote-write-url>"
basic_auth:
username: "<accesskey-id>"
password: "<accesskey-secret>"Verify the data import
After Prometheus restarts with the new configuration, verify that data is flowing to the managed instance:
Log on to the Managed Service for Prometheus console.
In the left-side navigation pane, click Instances.
Select the region of your instance, then click the instance name.
In the left-side navigation pane, click Dashboards. Open a dashboard and confirm that metrics from your self-managed Prometheus appear.
It may take a few minutes for the first batch of metrics to appear after you restart Prometheus.
Production recommendations
Security
Use a RAM user with the minimum required permissions instead of an Alibaba Cloud account AccessKey pair.
Restrict file permissions on
prometheus.ymlso that only the Prometheus process user can read it, because the file contains your AccessKey secret in plain text.chmod 600 prometheus.yml chown prometheus:prometheus prometheus.ymlRotate your AccessKey pair periodically and update
prometheus.ymlaccordingly.
Performance tuning
If you send a high volume of metrics, add a queue_config section to tune remote write throughput. For details on all tuning parameters, see Prometheus remote write tuning.
remote_write:
- url: "<remote-write-url>"
basic_auth:
username: "<accesskey-id>"
password: "<accesskey-secret>"
queue_config:
max_samples_per_send: 1000
max_shards: 200
capacity: 2500| Parameter | Description |
|---|---|
max_samples_per_send | Maximum number of samples per write request |
max_shards | Maximum number of parallel write connections |
capacity | Number of samples to buffer per shard before blocking scrapes |
Troubleshooting
| Symptom | Possible cause | Solution |
|---|---|---|
| Authentication errors in Prometheus logs | Incorrect AccessKey ID or AccessKey secret | Verify the basic_auth username and password in prometheus.yml match a valid AccessKey pair |
| No data in dashboards after several minutes | Wrong remote write URL or network connectivity issue | Confirm the URL matches the one on the Settings tab. If you use the internal URL, make sure your server can reach the endpoint |
| Connection refused or timeout errors | Firewall or security group blocks outbound traffic to the endpoint | Allow outbound access to the remote write URL and port from your Prometheus server |