菜单
文档breadcrumb arrow Grafana Mimirbreadcrumb arrow 配置breadcrumb arrow OpenTelemetry Collector
开源

配置 OpenTelemetry Collector 将指标写入 Mimir

注意

要将 OpenTelemetry 数据发送到 Grafana Cloud,请参阅使用 OpenTelemetry Protocol (OTLP) 发送数据

使用 OpenTelemetry Collector 时,您可以使用 OpenTelemetry 协议 (OTLP) 或 Prometheus remote write 协议将指标写入 Mimir。建议您使用 OpenTelemetry 协议。

使用 OpenTelemetry 协议

Mimir 支持通过 HTTP 的原生 OTLP。要配置 collector 使用 OTLP 接口,请使用 otlphttp 导出器 和原生 Mimir 端点。例如:

yaml
exporters:
  otlphttp:
    endpoint: http://<mimir-endpoint>/otlp

然后,在 service.pipelines 块中启用它:

yaml
service:
  pipelines:
    metrics:
      receivers: [...]
      processors: [...]
      exporters: [..., otlphttp]

如果您想使用 basic auth 进行身份验证,请使用 basicauth 扩展。例如:

yaml
extensions:
  basicauth/otlp:
    client_auth:
      username: username
      password: password

exporters:
  otlphttp:
    auth:
      authenticator: basicauth/otlp
    endpoint: http://<mimir-endpoint>/otlp

service:
  extensions: [basicauth/otlp]
  pipelines:
    metrics:
      receivers: [...]
      processors: [...]
      exporters: [..., otlphttp]

使用 Prometheus remote write 协议

要使用 Prometheus remote write 协议将指标发送到 Mimir,请在 Collector 中使用 prometheusremotewrite 导出器和原生 Mimir 端点。

exporters 部分,添加:

yaml
exporters:
  prometheusremotewrite:
    endpoint: http://<mimir-endpoint>/api/v1/push

然后,在 service.pipelines 块中启用它:

yaml
service:
  pipelines:
    metrics:
      receivers: [...]
      processors: [...]
      exporters: [..., prometheusremotewrite]

如果您想使用 basic auth 进行身份验证,请使用 basicauth 扩展。例如:

yaml
extensions:
  basicauth/prw:
    client_auth:
      username: username
      password: password

exporters:
  prometheusremotewrite:
    auth:
      authenticator: basicauth/prw
    endpoint: http://<mimir-endpoint>/api/v1/push

service:
  extensions: [basicauth/prw]
  pipelines:
    metrics:
      receivers: [...]
      processors: [...]
      exporters: [..., prometheusremotewrite]

处理默认 OpenTelemetry 标签

OpenTelemetry 指标使用资源属性来描述与生成遥测数据的给定资源或实体关联的一组特征。例如,主机资源可能有多个属性,包括 ID、镜像和类型。

为了优化此数据的存储和查询能力,您可以配置 Mimir 在摄取时将指定的 OTel 资源属性提升为标签,并将句点 (.) 替换为下划线 (_)。

Grafana Cloud 自动将以下 OTel 资源属性提升为标签:

  • service.instance.id
  • service.name
  • service.namespace
  • service.version
  • cloud.availability_zone
  • cloud region
  • container.name
  • deployment.environment.name
  • k8s.cluster.name
  • k8s.container.name
  • k8s.cronjob.name
  • k8s.daemonset.name
  • k8s.deployment.name
  • k8s.job.name
  • k8s.namespace.name
  • k8s.pod.name
  • k8s.replicaset.name
  • k8s.statefulset.name

注意

要禁用此设置或更新此列表,请联系 Grafana Labs 支持。

Mimir 将附加的 OTel 资源属性存储在一个单独的序列 target_info 中,您可以使用连接查询或 Prometheus info() 函数查询它。有关更多信息,请参阅 Prometheus 文档中的函数

要了解有关 OpenTelemetry 资源属性的更多信息,请参阅 OpenTelemetry 文档中的资源

格式注意事项

我们遵循官方的OTLP Metric points to Prometheus 规范。

默认情况下,Grafana Mimir 不接受OpenTelemetry Exponential Histogram 指标。要让 Grafana Mimir 接受它们,必须首先按照配置原生直方图摄取中的说明启用 Prometheus 原生直方图指标的摄取。完成此操作后,Grafana Mimir 将接受 OpenTelemetry Exponential Histograms,并根据Exponential Histograms 规范中描述的约定将其转换为 Prometheus 原生直方图。

您可能会遇到以下常见问题:

  • 点号 (.) 转换为下划线 (_)

    Prometheus 指标不支持指标或标签名称中的 .- 字符。Prometheus 会将这些字符转换为 _

    例如:

    OTLP 中的 requests.duration{http.status_code=500, cloud.region=us-central1}

    Prometheus 中的 requests_duration{http_status_code=”500”, cloud_region=”us-central1”}

  • 资源属性被添加到 target_info 指标中。

    然而,<service.namespace>/<service.name><service.name> (如果命名空间为空) 将作为标签 job 添加,并且 service.instance.id 将作为标签 instance 添加到每个指标中。

    有关详细信息,请参阅OpenTelemetry Resource Attributes 规范。