json_exporter icon indicating copy to clipboard operation
json_exporter copied to clipboard

HTTP status 503 service unavailable: json_exporter with basic_auth

Open ksivap147 opened this issue 3 years ago • 3 comments
trafficstars

Hi, I'm getting below error on prometheus console log while scraping metrics from json_exporter. Target endpoint is available and able to get response with curl using basic authentication.

ts=2022-04-18T20:58:07.156Z caller=scrape.go:1292 level=debug component="scrape manager" scrape_pool=json target="http://localhost:7979/probe?target=http%3A%2F%2Flocalhost%3A9015%2Fservices%2Fv2%2Fmpoints%2FE_TIP5%2Fstatistics" msg="Scrape failed" err="server returned HTTP status 503 Service Unavailable"

Could you please help me, how to debug this issue? Is it possible to try with curl to see verbose?

Here is the prometheus.yaml

scrape_configs:

gather metrics of prometheus itself

  • job_name: prometheus static_configs:

    • targets:
      • localhost:9090

    gather the metrics of json_exporter application itself

  • job_name: json_exporter static_configs:

    • targets:
      • localhost:7979 ## Location of the json exporter's real :

    gather the metrics from third party json sources, via the json exporter

  • job_name: json scrape_interval: 15s scrape_timeout: 10s metrics_path: /probe basic_auth: username: XXXXXX password: XXXXX static_configs:

    • targets: ['http://localhost:9015/services/v2/mpoints/E_TIP5/statistics'] relabel_configs:
    • source_labels: [address] target_label: __param_target
    • source_labels: [__param_target] target_label: instance
    • target_label: address replacement: localhost:7979 ## Location of the json exporter's real :

ksivap147 avatar Apr 19 '22 05:04 ksivap147

it worked after adding the below code to util.go to pass credentials to target end point. 
if req.Header.Get("Authorization") == "" {
	req.Header.Add("Authorization", "Basic XXXXXXXX")
} else {
	fmt.Println("Authorization", req.Header.Get("Authorization"))
}

Why json_exporter is not supporting basic_auth by default?

ksivap147 avatar Apr 19 '22 22:04 ksivap147

You have to set the basic_auth in the exporter config and not at prometheus: https://github.com/prometheus-community/json_exporter/blob/master/examples/config.yml

uncomment the http_client_config including basic_auth.

david-loe avatar Jul 19 '22 06:07 david-loe

@david-loe When I use a custom resource Probe for this, does .spec.basicAuth work?

R-Studio avatar May 13 '24 08:05 R-Studio