5

Prometheus send HTTP request to get monitor values. My custom export supports variety of clients (to monitors system status). There is a general REST API to get list of monitors:

/api/v1/monitor/find

the output result depend on Accept attribute in header. The default accept value is application/json.

I add new mime type to support prometheus (e.g. application/prometheus) into the API.

But, how to config Prometheus to add a custom header (Accept: application/prometheus)?

Mostafa Barmshory
  • 1,849
  • 24
  • 39

2 Answers2

0

Prometheus doesn't support setting headers, as that would lead to users creating hard to debug endpoints. You can either use a separate endpoint or pass a parameter.

Prometheus also already has a specified mime type for scrapes, so you could use that. See https://prometheus.io/docs/instrumenting/exposition_formats/

brian-brazil
  • 31,678
  • 6
  • 93
  • 86
0

Actually it is not support in current version (V2.0 alpha).

If you take a look at the scrapes.go in the master branch, then you can see some constant header attached into request:

req.Header.Add("Accept", acceptHeader)
req.Header.Set("User-Agent", userAgentHeader)
req.Header.Set("X-Prometheus-Scrape-Timeout-Seconds", fmt.Sprintf("%f", s.timeout.Seconds()))

So, there are some basic mime-types which you can support:

application/vnd.google.protobuf;proto=io.prometheus.client.MetricFamily;encoding=delimited;q=0.7,text/plain;version=0.0.4;q=0.3,*/*;q=0.1

None of artifacts on premetheus.io added this header, so you have to build from source (master branch).

I run a PHP exporter (my own exporter), here is screen shot of request header

enter image description here

aSemy
  • 5,485
  • 2
  • 25
  • 51
Mostafa Barmshory
  • 1,849
  • 24
  • 39