Renjith
Renjith

Reputation: 45

Prometheus returned error "server returned HTTP status 401 Unauthorized" for .NET core api

I have a .NET core API hosted in IIS which uses windows authentication. I'm using Prometheus to scrape metrics from this API. But I'm getting the error for the api target:

"server returned HTTP status 401 Unauthorized"

Can some help me how to configure prometheus for targets with Windows authentication?

When I tried to browse the metrics path separately, the browser is requesting for credentials and I'm able to view the metrics with my Windows authentication.

Upvotes: 3

Views: 11002

Answers (2)

fguillen
fguillen

Reputation: 38792

Add the basic_auth values to your prometheus.yml:

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

Remember to:

sudo systemctl restart prometheus

Upvotes: 0

Alin S&#238;npălean
Alin S&#238;npălean

Reputation: 10084

Looking at the documentation, Prometheus seems to support basic (user/password) and OAuth bearer token authentication only. If your API/IIS doesn't support any of those, then you either need to disable authentication for the /metrics path or maybe set up a proxy that only allows /metrics requests and does the authentication for you.

Upvotes: 3

Related Questions