Add HTTP 404 and exclude /metrics

85 views
Skip to first unread message

Igor

unread,
Mar 9, 2018, 3:44:31 AM3/9/18
to Prometheus Users

Hi!

Some simple question:

  1. How can I add HTTP 404 code to general metrics for all routers?
    promhttp_metric_handler_requests_total{code="200"} 1
    promhttp_metric_handler_requests_total{code="500"} 0
    promhttp_metric_handler_requests_total{code="503"} 0
    promhttp_metric_handler_requests_total{code="404"} 0 - I'd like to see this

  2. How can I exclude /metrics router from metrics?

promhttp_metric_handler_requests_total{code="200"} 1 - here will be wrong value if someone regularly ask /metrics host

Björn Rabenstein

unread,
Mar 9, 2018, 7:39:01 AM3/9/18
to Igor, Prometheus Users

On 9 March 2018 at 09:44, ‘Igor’ via Prometheus Users <promethe...@googlegroups.com> wrote:

  1. How can I add HTTP 404 code to general metrics for all routers?
    promhttp_metric_handler_requests_total{code="200"} 1
    promhttp_metric_handler_requests_total{code="500"} 0
    promhttp_metric_handler_requests_total{code="503"} 0
    promhttp_metric_handler_requests_total{code="404"} 0 - I'd like to see this

This metric name is coming from InstrumentMetricHandler, a middleware specifically meant to instrument the Prometheus metrics handler. This handler will never return the 404 status code, and thus it is not included in the metric (which is also specifically named to refer to the metrics handler).

If you want to instrument handlers in general, use all the other InstrumentHandler… middlewares in the promhttp package. You can then easily pass in a CounterVec that has {code="404"} pre-initialized.

  1. How can I exclude /metrics router from metrics?

promhttp_metric_handler_requests_total{code="200"} 1 - here will be wrong value if someone regularly ask /metrics host

I don’t quite understand. The whole point of this metric is to count requests to the /metrics endpoint. If you want to instrument other handlers, see the advice above.

--
Björn Rabenstein, Engineer
http://soundcloud.com/brabenstein

SoundCloud Ltd. | Rheinsberger Str. 76/77, 10115 Berlin, Germany
Managing Director: Alexander Ljung | Incorporated in England & Wales with Company No. 6343600 | Local Branch Office | AG Charlottenburg  | HRB 110657B
Reply all
Reply to author
Forward
0 new messages