prometheus

Adding custom header in HTTP request of prometheus


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)?


Solution

  • 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