You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Grafana提示‘Datasource ${Prometheus} was not found’,如何修复UID问题?

Kafka KRaft指标集成Grafana时数据源UID配置问题解决

问题背景

在CentOS 7环境中,将Kafka KRaft指标与最新版本的Prometheus、Grafana集成时,通过Grafana仪表板查看指标出现数据源未找到的错误,排查确认问题出在kafka-cluster.json的数据源UID配置上。

相关配置片段

kafka-cluster.json问题片段

....
     {
      "datasource": {
        "type": "prometheus",
        "uid": "${Prometheus}"
      },
      "description": "Number of active controllers in the cluster.",
      "fieldConfig": {
        "defaults": {
          "mappings": [
            {
              "options": {
                "match": "null",
                "result": {
                  "text": "N/A"
                }
              },
              "type": "special"
            }
          ],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "#299c46",
                "value": null
              },
              {
                "color": "#e5ac0e",
                "value": 2
              },
              {
                "color": "#bf1b00"
              }
            ]
          },
          "unit": "none"
        },
        "overrides": []
      },
 ....

dashboard.yml配置

apiVersion: 1

providers:
    - name: "Prometheus"
      orgId: 1
      folder: ""
      type: file
      disableDeletion: false
      allowUiUpdates: true
      editable: true
      options:
          path: /home/kafka/grafana/conf/provisioning/dashboards

datasource.yml配置

# config file version
apiVersion: 1

# list of datasources that should be deleted from the database
#deleteDatasources:
#  - name: Prometheus
#    orgId: 1

# list of datasources to insert/update depending
# whats available in the database
datasources:
  # <string, required> name of the datasource. Required
- name: Prometheus
  # <string, required> datasource type. Required
  type: prometheus
  # <string, required> access mode. direct or proxy. Required
  access: proxy
  # <int> org id. will default to orgId 1 if not specified
  orgId: 1
  # <string> url
  url: http://prometheus:9090
  # <string> database password, if used
  password:
  # <string> database user, if used
  user:
  # <string> database name, if used
  database:
  # <bool> enable/disable basic auth
  basicAuth: true
  # <string> basic auth username
  basicAuthUser: admin
  # <string> basic auth password
  basicAuthPassword: foobar
  # <bool> enable/disable with credentials headers
  withCredentials:
  # <bool> mark as default datasource. Max one per org
  isDefault: true
  # <map> fields that will be converted to json and stored in json_data
  jsonData:
     # <sting> the typical scrap and evaluation interval configured in Prometheus, used to calculate '$__rate_interval'
     timeInterval: 60s
     tlsAuth: false
     tlsAuthWithCACert: false
  # <string> json object of data that will be encrypted.
  secureJsonData:
    tlsCACert: "..."
    tlsClientCert: "..."
    tlsClientKey: "..."
  version: 1
  # <bool> allow users to edit datasources from the UI.
  editable: true

解决方法

方法1:替换为Prometheus数据源的实际UID

  1. 登录Grafana UI,进入Connections > Data sources,找到已配置的Prometheus数据源
  2. 进入数据源详情页,从浏览器地址栏提取UID:地址栏路径类似/datasources/edit/xxxxxx,最后一段字符串即为UID
  3. 修改kafka-cluster.json中的uid值,将${Prometheus}替换为实际UID:
{
  "datasource": {
    "type": "prometheus",
    "uid": "xxxxxx" // 替换为你的Prometheus数据源UID
  }
}
  1. 重启Grafana或重新加载仪表板配置

方法2:直接使用数据源名称匹配(Grafana 8.0+支持)

无需手动查找UID,直接用数据源名称替代原有的datasource对象配置:

{
  "datasource": "Prometheus" // 与datasource.yml中配置的name字段一致
}

修改后保存并刷新Grafana仪表板即可生效

方法3:为Prometheus数据源配置固定UID

在datasource.yml中为Prometheus数据源添加固定UID,确保仪表板可以稳定引用:

  1. 修改datasource.yml,添加uid字段:
datasources:
- name: Prometheus
  type: prometheus
  access: proxy
  orgId: 1
  url: http://prometheus:9090
  uid: "prometheus-fixed-uid" // 设置固定UID
  # 其他原有配置不变
  1. 在kafka-cluster.json中引用该固定UID:
{
  "datasource": {
    "type": "prometheus",
    "uid": "prometheus-fixed-uid"
  }
}
  1. 重启Grafana使配置生效

内容的提问来源于stack exchange,提问作者호이호이

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 08:25:57