On 27 November 2017 at 11:35, Marco Jantke <
marco....@gmail.com> wrote:
>
> Other ideas how I could prevent having to build my own sampling logic are
> still welcome :) I have the problem described above with a lot of metrics,
> also e.g. traefik_backend_http_requests_total (counter) or
> traefik_backend_req_duration_seconds (histogram), which is data I can not
> gather on the fly.
In general, the happy case is that metrics a binary exposes are static
throughout the lifetime of a binary. That's why you should avoid
metrics suddenly popping up (see
https://prometheus.io/docs/practices/instrumentation/#avoid-missing-metrics
), and initialize metric vectors with all the possible label values
(which, in the Go client, can be done by
`someMetricVec.With(prometheus.Labels{"foo": "bar"})`, you don't even
need to call `Set` or something. The metric child will be created with
0 as a starting value), see also last paragraph of
https://prometheus.io/docs/instrumenting/writing_clientlibs/#labels
In reality, the happy case is not always feasible. Most of the time,
that's because you cannot predict all possible label values, or there
would just be too many (proverbial example: all possible HTTP status
codes). It's much rarer that you actually want to _remove_ a metric
child from the vector. As Ben said, if you just want to mirror metrics
from a 3rd party source, the "one shot" const metrics are the way to
go. If you still end up with the need to remove a metric child from a
metric vector, you can use the `Delete` method (in the Go client), see
https://godoc.org/github.com/prometheus/client_golang/prometheus#GaugeVec.Delete
--
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