
# 配置Remote Write地址实现自建Prometheus数据上报到AOM
AOM提供获取当前Prometheus实例的Remote Write地址的能力，支持将原生Prometheus的指标通过Remote Write上报到AOM服务端，即可实现时序数据的长期存储。
#### 前提条件
- 已[购买](https://support.huaweicloud.com/usermanual-ecs/ecs_03_7002.html)弹性云服务器ECS。
- 服务已接入可观测Prometheus监控。具体操作请参见：
  - [Prometheus实例 for CCE](https://support.huaweicloud.com/usermanual-aom2/mon_01_0073.html)
  
  - [Prometheus 通用实例](https://support.huaweicloud.com/usermanual-aom2/mon_01_0070.html)
  
  - [Prometheus实例 for 多账号聚合实例](https://support.huaweicloud.com/usermanual-aom2/mon_01_0071.html)
  
  - [Prometheus实例 for 多账号虚拟聚合实例](https://support.huaweicloud.com/usermanual-aom2/mon_01_0181.html)
   
 
 #### 配置自建Prometheus数据上报到AOM
1. 安装并启动开源版Prometheus，具体操作请参见[Prometheus官方文档](https://prometheus.io/docs/prometheus/latest/getting_started/)。（如果已经部署并正在使用开源Prometheus，可以忽略该步骤。）
2. 添加Access Code。 
   1. 登录[AOM 2.0控制台](https://console.huaweicloud.com/aom2#/aom2/betaTest)。
   
   2. 在左侧导航栏中选择"设置 \> 全局设置"，进入全局设置界面。
   
   3. 在左侧导航栏选择"认证管理"，然后在右侧区域单击"创建Access Code"。
   
   4. 在弹出的对话框中单击"立即生成"，系统自动为当前用户生成Access Code。 **Access Code是调用API的身份凭据，每个项目最多可创建5个Access Code，请您妥善保管。**
      
   
   
   
   
3. 获取Remote Write Prometheus配置代码。
   
   1. 登录[AOM 2.0控制台](https://console.huaweicloud.com/aom2#/aom2/betaTest)。
   
   2. 在左侧导航栏选择"Prometheus监控 \> 实例列表"，在实例列表中单击目标Prometheus实例名称。
   
   3. 从"设置"页签的"服务地址"区域，单击右侧![](https://support.huaweicloud.com/usermanual-aom2/zh-cn_image_0000002142729384.png)复制当前Prometheus实例的Remote Write Prometheus配置代码。（配置代码中的bearer_token取值为Access Code的值，请用户自行加密保存。）
      图1Remote Write Prometheus配置代码   
      ![](https://support.huaweicloud.com/usermanual-aom2/zh-cn_image_0000002536784656.png "点击放大") 
   
   
   
   
4. 登录ECS主机，配置prometheus.yaml文件。 
   1. 通过以下命令找到并启动prometheus.yaml文件。
      ```
      ./prometheus --config.file=prometheus.yaml
      ```
      
   
   2. 将[3]获取的Remote Write Prometheus配置代码添加到prometheus.yaml文件末尾。
   
   
   一个完整的配置示意如下，您需要配置斜体部分：
   ```
   # my global config
   global:
   scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
   evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
   # scrape_timeout is set to the global default (10s).
   # Alertmanager configuration
   alerting:
   alertmanagers:
     - static_configs:
     - targets:
   # - alertmanager:9093
   # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
   rule_files:
   # - "first_rules.yml"
   # - "second_rules.yml"
   # A scrape configuration containing exactly one endpoint to scrape:
   # Here it's Prometheus itself.
   scrape_configs:
   # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
     - job_name: 'prometheus'
   # metrics_path defaults to '/metrics'
   # scheme defaults to 'http'.
   static_configs:
     - targets: ['localhost:9090']
   # 用3获取的Remote Write Prometheus配置代码替换斜体内容
   remote_write:
     - url:'https://aom-**.***.myhuaweicloud.com:8443/v1/6d6df***2ab7/58d6***c3d/push'
       tls_config:
         insecure_skip_verify: true
       bearer_token: 'SE**iH'
   ```
   
   
5. 检查内网域名配置。 
   由于上述配置中的数据上报是通过内网进行数据传输，因此需要确保您的Prometheus所在的主机能够解析内网域名，请参考[配置内网DNS](https://support.huaweicloud.com/vpc_faq/vpc_faq_0105.html)。
   
   
6. 重新启动Prometheus。
7. 可[通过Grafana查看AOM中的指标数据](https://support.huaweicloud.com/usermanual-aom2/mon_01_0077.html)，来验证上述配置修改后数据上报是否成功。
 
