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

云端Hasura(Docker容器)指标无法暴露给Prometheus,配置后接口报错

问题描述

已在云端运行Hasura容器,计划通过Prometheus和Grafana监控其性能。按照要求配置了metrics相关环境变量:

  • HASURA_GRAPHQL_ENABLED_APIS=metadata,graphql,config,metrics
  • HASURA_GRAPHQL_METRICS_SECRET=SOME_SECRET_KEY

docker-compose配置如下:

graphql-engine:
  image: hasura/graphql-engine:v2.18.0.cli-migrations-v3
  restart: on-failure:1
  ports:
    - "8080:8080"
  environment:
    HASURA_GRAPHQL_METADATA_DATABASE_URL: MY_DB_URL
    HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # set "false" to disable console
    HASURA_GRAPHQL_DEV_MODE: "true"
    HASURA_GRAPHQL_UNAUTHORIZED_ROLE: "anonymous"
    HASURA_GRAPHQL_ADMIN_SECRET: SOME_SECRET
    ## For Monitoring uses, with Prometheus and Grafana
    HASURA_GRAPHQL_ENABLED_APIS: "metadata,graphql,config,metrics"
    HASURA_GRAPHQL_METRICS_SECRET: "PROMETHEUSSECRET"
  command:
  - graphql-engine
  - serve

执行以下curl命令尝试获取指标:

curl 'http://localhost:8080/v1/metrics' -H 'Authorization: Bearer PROMETHEUSSECRET'

返回错误:

{"code":"not-found","error":"resource does not exist","path":"$"}

当前Prometheus配置文件:

global:
  scrape_interval:     15s 
scrape_configs:
  - job_name: 'hasura'
    static_configs:
      - targets: ['localhost:8080']
解决方案

1. 修正Metrics端点路径

你使用的Hasura v2.18.0版本中,metrics的暴露端点是/metrics,而非/v1/metrics(该路径是后续版本才启用的)。这是导致"resource does not exist"错误的核心原因。

修改curl命令为:

curl 'http://localhost:8080/metrics' -H 'Authorization: Bearer PROMETHEUSSECRET'

2. 更新Prometheus配置

Prometheus需要配置正确的metrics路径和认证信息才能拉取Hasura指标,更新后的配置如下:

global:
  scrape_interval: 15s 
scrape_configs:
  - job_name: 'hasura'
    static_configs:
      - targets: ['localhost:8080']
    metrics_path: '/metrics'
    authorization:
      credentials: 'PROMETHEUSSECRET'
      type: 'Bearer'

3. 验证配置生效

完成修改后执行以下步骤:

  • 重启Hasura容器:docker-compose restart graphql-engine
  • 重启Prometheus服务,加载新配置
  • 执行修正后的curl命令,确认能返回Prometheus格式的metrics文本
  • 访问Prometheus UI的Targets页面,检查hasura任务状态是否为UP

额外注意事项

  • 云端部署时,确保Hasura的8080端口已对Prometheus所在环境开放
  • HASURA_GRAPHQL_METRICS_SECRET应设置为强随机字符串,避免使用示例明文值
  • 后续升级Hasura版本时,需核对官方文档确认metrics端点是否有变更

内容的提问来源于stack exchange,提问作者Jackk-Doe

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 09:37:45