Prometheus 针对 .NET core api 返回错误“服务器返回 HTTP 状态 401 未经授权”

问题描述 投票:0回答:2

我有一个托管在 IIS 中的 .NET core api,它使用 Windows 身份验证。我正在使用 Prometheus 从此 API 中获取指标。但我收到 api 目标的错误“服务器返回 HTTP 状态 401 未经授权”。有人可以帮助我如何为具有 Windows 身份验证的目标配置 prometheus 吗?

当我尝试单独浏览指标路径时,浏览器正在请求凭据,并且我可以通过 Windows 身份验证查看指标。

api .net-core prometheus prometheus-net
2个回答
3
投票

查看文档,Prometheus 似乎仅支持基本(用户/密码)和 OAuth 不记名令牌身份验证。如果您的 API/IIS 不支持其中任何一个,那么您需要禁用

/metrics
路径的身份验证,或者设置一个仅允许
/metrics
请求并为您进行身份验证的代理。


0
投票

将 basic_auth 值添加到您的 prometheus.yml 中:

  - job_name: "<JOB_NAME>"
    static_configs:
      - targets: ["host.example.com:9090"]
    basic_auth:
      username: "<USER>"
      password: "<PASSWORD>"

记住:

sudo systemctl restart prometheus
© www.soinside.com 2019 - 2024. All rights reserved.