Neptune 的 Prometheus 端口默认是多少?如何开启 BasicAuth?

解读

在国内金融、运营商等对“可观测性”过等保三级的场景里,面试官问端口并不是背数字,而是验证候选人是否真正在生产环境对接过 Prometheus + Grafana 监控链路;同时 BasicAuth 的开启方式直接决定后续告警能否安全穿透防火墙,属于“能不能上线”的关键细节。答不出或答错,会被直接判定为“只用过控制台 Demo”。

知识点

  1. Neptune 的监控数据出口统一由 Neptune-Exporter 侧车容器暴露,Exporter 随实例自动拉起,与内核进程分离。
  2. 默认监听端口为 8184/TCP,路径 /metrics 返回 Prometheus 文本协议,Content-Type 为 text/plain; version=0.0.4。
  3. BasicAuth 并非 Neptune 内核功能,而是 Exporter 自带的环境变量开关,通过 AWS 控制台或 CLI 修改 DB Cluster Parameter Group 实现。
  4. 参数组修改后需要“滚动重启”只读副本 → 主实例,否则新变量不会注入到 Exporter 容器,属于高危操作窗口。
  5. 国内 VPC 常绑定 NAT+专线,Prometheus 拉取端需放通 8184 端口出站,同时 BasicAuth 密码必须满足等保“大小写+数字+特殊字符 8 位以上”要求。

答案

  1. 默认端口:8184。
  2. 开启 BasicAuth 步骤:
    a) 打开控制台 → 进入对应 Neptune 集群的 DB Cluster Parameter Group(如 neptune-prom-params)。
    b) 新增或修改以下键值:
    • neptune_exporter_enable_basic_auth = 1
    • neptune_exporter_basic_auth_username = <自定义用户名>
    • neptune_exporter_basic_auth_password = <符合复杂度要求的密码>
      c) 保存后选择 “立即应用”,系统会依次重启只读副本再重启主实例,期间主节点有 30–60 s 连接闪断。
      d) 重启完成后,Prometheus 拉取地址需改为
      https://<username>:<password>@<neptune-endpoint>:8184/metrics
      并验证返回头包含 401 Unauthorized 校验通过。
  3. 若使用 CLI,可一次完成:
    aws neptune modify-db-cluster-parameter-group \
      --db-cluster-parameter-group-name neptune-prom-params \
      --parameters \
        ParameterName=neptune_exporter_enable_basic_auth,ParameterValue=1,ApplyMethod=immediate \
        ParameterName=neptune_exporter_basic_auth_username,ParameterValue=ops,ApplyMethod=immediate \
        ParameterName=neptune_exporter_basic_auth_password,ParameterValue=Metrix@2025!,ApplyMethod=immediate
    

拓展思考

  • 安全加固:国内银行常要求“零信任”,可在 Prometheus 外侧再套一层 Nginx Ingress,启用 mTLS,Exporter 的 BasicAuth 作为第二道防线。
  • 高可用拉取:Neptune 只读副本跨可用区,Prometheus 可配置 dns_sd_configs 做 A 记录轮询,避免单点 8184 端口故障导致指标断流。
  • 成本优化:8184 端口返回的指标量约 1.5 K 系列/节点,若集群节点数 >20,建议通过 metric_relabel_configs 丢弃 neptune_storage_* 低频指标,可节省 30% 以上抓取流量费用。