IBM Cloud Docs
使用 Prometheus 远程写来收集度量

使用 Prometheus 远程写来收集度量

您可以配置 Prometheus 远程写入,以从 Monitoring 代理程序不可用的环境收集度量值,并将其发送到 Monitoring 实例。

您可以从以下位置收集度量值:

  • 现有 Prometheus 服务器。
  • 可能存在时间不够长的临时或批处理作业,无法由 Monitoring 代理程序提取。
  • Windows 主机和其他操作系统,其中 Monitoring 代理程序不可用
  • 基于 Non-x86 的体系结构,通常在 IoT 环境或 Edge 计算上显示。
  • 非容器化工作负载,如 NGNIX、自定义应用程序、RabbitMQ, 等。

Prometheus remote write option
Prometheus remote write

您可以通过 Monitoring Web UI 使用 Prometheus 远程写来监视收集的度量。 您还可以使用 PromQL 通过标准 Prometheus 查询语言来查询数据。

配置 Prometheus 远程写入

您可以将 Prometheus 服务器配置为远程写入 Monitoring 实例。 例如

  • 您可以通过不同方式配置在 Kubernetes 集群中运行的 Prometheus 服务器。 根据安装方式,您可以选择以下任何选项来配置 Prometheus 中的远程写入功能,以将度量值发送到 IBM Cloud Monitoring 实例:

    • 配置由 Prometheus 操作程序管理的 Prometheus 服务器

    • 使用 Helm 配置 Prometheus 服务器

    • 通过 Kubernetes ConfigMap 配置 Prometheus 服务器

    更多信息,请参阅 使用 Prometheus 远程写入收集指标

Prometheus v2.25 和先前版本

对于 Prometheus v2.25 和先前版本,必须在 prometheus.yml 配置文件中配置 remote_write 部分,如下所示:

global:
  external_labels:
    [ <labelname>: <labelvalue> ... ]
remote_write:
- url: "https://<INGESTION_URL>/prometheus/remote/write"
  bearer_token: "<MONITOR_API_TOKEN>"

Where

  • <MONITOR_API_TOKEN> 包含授权令牌。 有关更多信息,请参阅 使用 Monitor API 令牌
  • <INGESTION_URL> 表示摄入终点。 必须将此值设置为 Monitoring 实例可用的区域的摄入端点。 有关更多信息,请参阅 端点

Prometheus V 2.26 和更高版本

对于 Prometheus V 2.26 和更高版本,必须在 prometheus.yml 配置文件中配置 remote_write 部分,如下所示:

global:
  external_labels:
    [ <labelname>: <labelvalue> ... ]
remote_write:
- url: "https://<INGESTION_URL>/prometheus/remote/write"
  authorization:
    credentials: "<MONITOR_API_TOKEN>"

Where

  • <MONITOR_API_TOKEN> 包含授权令牌。 有关更多信息,请参阅 使用 Monitor API 令牌
  • <INGESTION_URL> 表示摄入终点。 必须将此值设置为 Monitoring 实例可用的区域的摄入端点。 有关更多信息,请参阅 端点

管理通过远程写入收集的度量

缺省情况下,当您配置 Prometheus 服务器以远程写入 Monitoring 实例时,将收集所有度量值并包含 remote_write: true 标签以轻松识别这些度量值。

控制发送的度量

您可以管理和控制收集并发送到 Monitoring 实例的度量。 要选择要收集的序列和标签,并减少发送到 Monitoring 实例的活动序列数,可以使用 remote_write 部分中的 write_relabel_configs 块来设置重新标记配置。

例如,要从 1 namespace my-namespace 收集度量值,可以添加以下内容:

remote_write:
    - url: https://<INGESTION_URL>/prometheus/remote/write
      authorization:
        credentials_file: /etc/secrets/<SECRET_NAME>
      write_relabel_configs:
        - action: keep
          regex: my-namespace
          source_labels:
          - namespace

按 Prometheus 服务器标记度量

您可以使用 global 中的 external_labels 块来指定随 Prometheus 服务器收集的每个时间序列一起发送的定制标签。

您可以使用这些标签来过滤和定义通过 Monitoring UI 中的仪表板监视的度量的作用域。

例如,如果您将 2 不同的 Prometheus 服务器配置为远程写入 Monitoring 实例,那么可以包含外部标签来标识每个服务器:

# Prometheus server 1
global:
  external_labels:
    provider: prometheus1
remote_write:
- url: ...
# Prometheus server 2
global:
  external_labels:
    provider: prometheus2
remote_write:
- url: ...

费率限制

下表列出了每个实例的缺省速率限制:

费率限制
费率 限制 参考
并行写入数 100 个并发请求
每分钟的数据点 (DPM) 1 百万 发送的数据点数取决于发送度量值的频率。 例如,提取时间间隔 10s 将提交超过时间间隔 60 秒的 DPM
每分钟写入次数 10,000

用于远程写入的采集端点

IBM Cloud Monitoring 不推荐使用 https://ingest.<region>https://ingest.private.<region> 格式的 Prometheus 客户机支持端点,并在 2024 年 5 月 31 日将其替换为新端点。 对旧端点的支持将于 2024 年 8 月 31 日结束。 此后,旧的端点将停止工作。 使用 Prometheus Remote Write 的客户需要在 2024 年 8 月 31 日前迁移到新的端点,以便继续使用 Prometheus Remote Write。

下表列出了公共 Monitoring 采集端点,您可以配置这些端点以通过 Prometheus Remote Write 收集度量值:

远程写摄入使用 TCP 443 端口。

Prometheus远程写公共端点
区域 端点
达拉斯 (US-South) https://ingest.us-south.monitoring.cloud.ibm.com/prometheus/remote/write 不推荐
https://ingest.prws.us-south.monitoring.cloud.ibm.com/prometheus/remote/write
法兰克福 (EU-DE) https://ingest.eu-de.monitoring.cloud.ibm.com/prometheus/remote/write 不推荐
https://ingest.prws.eu-de.monitoring.cloud.ibm.com/prometheus/remote/write
伦敦 (EU-GB) https://ingest.eu-gb.monitoring.cloud.ibm.com/prometheus/remote/write 不推荐
https://ingest.prws.eu-gb.monitoring.cloud.ibm.com/prometheus/remote/write
马德里 (EU-ES) https://ingest.eu-es.monitoring.cloud.ibm.com/prometheus/remote/write 不推荐
https://ingest.prws.eu-es.monitoring.cloud.ibm.com/prometheus/remote/write
大板 (JP-OSA) https://ingest.jp-osa.monitoring.cloud.ibm.com/prometheus/remote/write 不推荐
https://ingest.prws.jp-osa.monitoring.cloud.ibm.com/prometheus/remote/write
圣保罗 (BR-SAO) https://ingest.br-sao.monitoring.cloud.ibm.com/prometheus/remote/write 不推荐
https://ingest.prws.br-sao.monitoring.cloud.ibm.com/prometheus/remote/write
悉尼 (AU-SYD) https://ingest.au-syd.monitoring.cloud.ibm.com/prometheus/remote/write 不推荐
https://ingest.prws.au-syd.monitoring.cloud.ibm.com/prometheus/remote/write
东京 (JP-TOK) https://ingest.jp-tok.monitoring.cloud.ibm.com/prometheus/remote/write 不推荐
https://ingest.prws.jp-tok.monitoring.cloud.ibm.com/prometheus/remote/write
多伦多 (CA-TOR) https://ingest.ca-tor.monitoring.cloud.ibm.com/prometheus/remote/write 不推荐
https://ingest.prws.ca-tor.monitoring.cloud.ibm.com/prometheus/remote/write
华盛顿 (US-EAST) https://ingest.us-east.monitoring.cloud.ibm.com/prometheus/remote/write 不推荐
https://ingest.prws.us-east.monitoring.cloud.ibm.com/prometheus/remote/write

下表列出了您可以配置为通过 Prometheus Remote Write 收集度量的专用 Monitoring 采集端点:

Prometheus远程写入专用端点
区域 端点
达拉斯 (US-South) https://ingest.private.us-south.monitoring.cloud.ibm.com/prometheus/remote/write 不推荐
https://ingest.prws.private.us-south.monitoring.cloud.ibm.com/prometheus/remote/write
法兰克福 (EU-DE) https://ingest.private.eu-de.monitoring.cloud.ibm.com/prometheus/remote/write 不推荐
https://ingest.prws.private.eu-de.monitoring.cloud.ibm.com/prometheus/remote/write
伦敦 (EU-GB) https://ingest.private.eu-gb.monitoring.cloud.ibm.com/prometheus/remote/write 不推荐
https://ingest.prws.private.eu-gb.monitoring.cloud.ibm.com/prometheus/remote/write
马德里 (EU-ES) https://ingest.private.eu-es.monitoring.cloud.ibm.com/prometheus/remote/write 不推荐
https://ingest.prws.private.eu-es.monitoring.cloud.ibm.com/prometheus/remote/write
大板 (JP-OSA) https://ingest.private.jp-osa.monitoring.cloud.ibm.com/prometheus/remote/write 不推荐
https://ingest.prws.private.jp-osa.monitoring.cloud.ibm.com/prometheus/remote/write
圣保罗 (BR-SAO) https://ingest.private.br-sao.monitoring.cloud.ibm.com/prometheus/remote/write 不推荐
https://ingest.prws.private.br-sao.monitoring.cloud.ibm.com/prometheus/remote/write
悉尼 (AU-SYD) https://ingest.private.au-syd.monitoring.cloud.ibm.com/prometheus/remote/write 不推荐
https://ingest.prws.private.au-syd.monitoring.cloud.ibm.com/prometheus/remote/write
东京 (JP-TOK) https://ingest.private.jp-tok.monitoring.cloud.ibm.com/prometheus/remote/write 不推荐
https://ingest.prws.private.jp-tok.monitoring.cloud.ibm.com/prometheus/remote/write
多伦多 (CA-TOR) https://ingest.private.ca-tor.monitoring.cloud.ibm.com/prometheus/remote/write 不推荐
https://ingest.prws.private.ca-tor.monitoring.cloud.ibm.com/prometheus/remote/write
华盛顿 (US-EAST) https://ingest.private.us-east.monitoring.cloud.ibm.com/prometheus/remote/write 不推荐
https://ingest.prws.private.us-east.monitoring.cloud.ibm.com/prometheus/remote/write

限制

IBM Cloud Monitoring Prometheus 远程写入功能具有以下限制:

  • 可以在“探索”中访问发送到实例的度量,但这些度量与作用域树不兼容。

  • 只能使用在源中收集的标签来过滤度量值。

  • 度量的元数据不会通过远程写入发送。

  • 名称以 _total_sum_count 结尾的度量将存储为计数器,否则将作为标尺进行管理。

  • 您可以手动在仪表板中设置单元。

  • 不能在仪表板中混用具有不同采样的度量值,例如 10s 和 1min。

    请考虑将提取时间间隔配置为 10s,以便可以将 Prometheus 远程写入度量值与 Monitoring 代理程序度量值结合使用。