You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using a histogram metrics we can use the 'observe' method to evaluate which bucket our latest sample will fall in:
E.g. h1.labels('device-1').observe(value.get('latest_sample'))
->
for i, bound in enumerate(self._upper_bounds):
if amount <= bound:
self._buckets[i].inc(1)
break
However as I am proxying metrics I believe I should be using a Customer Collector and the HistogramMetricFamily which only provides add_metric which seems to just populate all the buckets.
am I supposed to calculate the buckets in my code before writing the metric?
That's how I'd do it, keep in mind that you possibly want to switch the type to GaugeHistogram before sending it on if you're using a custom collector like this.
It's a type thing, so may be used by downstream tooling for better hints etc.. If the data is based on counters then it's a Histogram. If it's a snapshot of current state it's a GaugeHistogram.
In that case, I guess you’re not proxying the data anymore? My use case is
for reading counters from another system/format and exposing those as
Prometheus metrics.
Activity
brian-brazil commentedon Sep 1, 2021
That's how I'd do it, keep in mind that you possibly want to switch the type to GaugeHistogram before sending it on if you're using a custom collector like this.
brian-brazil commentedon Sep 1, 2021
It's a type thing, so may be used by downstream tooling for better hints etc.. If the data is based on counters then it's a Histogram. If it's a snapshot of current state it's a GaugeHistogram.
brian-brazil commentedon Sep 1, 2021
You should create a new Histogram for each collect, otherwise you're risking race conditions.
cunningr commentedon Sep 2, 2021
brian-brazil commentedon Sep 2, 2021
In that case, manually putting together the Histogram's samples is what I'd do.