重命名服务监视器中的指标

Renaming metrics in service monitor

阅读 this 文章后,我正在尝试清理 Spark 3.0.1 中的指标。这是我的 servicemonitor.yml 文件:

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  labels:
    app: spark3
    release:  prometheus
  name: spark3-servicemonitor
spec:
  endpoints:
  - interval: 5s
    port: spark-ui
    path: /metrics/prometheus
    relabelings:
    # Rename metrics
      - sourceLabels: [__name__]
        targetLabel: __name__
        regex: 'metrics_spark_driver_.+_StreamingMetrics_([a-zA-Z_]{1,})_Value'
        replacement: 'spark_driver_'
  namespaceSelector:
    matchNames:
    - default
  selector:
    matchLabels:
      spark-version: "3"

我希望进行以下转换: metrics_spark_driver_whateverappid_StreamingMetrics_streaming_lastCompletedBatch_totalDelay_Value -> spark_driver_streaming_lastCompletedBatch_totalDelay 但是重新标记似乎不起作用。你能帮我解决这个问题吗?

relabelings 必须根据 spec 命名为 metricRelabelings。请注意,ServiceMonitors 的 yaml 格式不使用与相应的 prometheus 配置相同的键名(但它仍然是有效的 yaml)。