|
54 | 54 | ) |
55 | 55 | from prometheus_client.core import ( |
56 | 56 | REGISTRY, |
| 57 | + GaugeHistogramMetricFamily, |
57 | 58 | GaugeMetricFamily, |
58 | | - Sample, |
59 | | - Timestamp, |
60 | 59 | ) |
61 | 60 |
|
62 | 61 | from twisted.python.threadpool import ThreadPool |
@@ -345,7 +344,7 @@ def _register_with_collector(self) -> None: |
345 | 344 | all_gauges[self.name] = self |
346 | 345 |
|
347 | 346 |
|
348 | | -class GaugeHistogramMetricFamilyWithLabels(Metric): |
| 347 | +class GaugeHistogramMetricFamilyWithLabels(GaugeHistogramMetricFamily): |
349 | 348 | """ |
350 | 349 | Custom version of `GaugeHistogramMetricFamily` from `prometheus_client` that allows |
351 | 350 | specifying labels and label values. |
@@ -376,51 +375,7 @@ def __init__( |
376 | 375 |
|
377 | 376 | # Create a gauge for each bucket. |
378 | 377 | if buckets is not None: |
379 | | - self.add_metric( |
380 | | - labelvalues=labelvalues, buckets=buckets, gsum_value=gsum_value |
381 | | - ) |
382 | | - |
383 | | - def add_metric( |
384 | | - self, |
385 | | - labelvalues: StrSequence, |
386 | | - buckets: Sequence[Tuple[str, float]], |
387 | | - gsum_value: float, |
388 | | - timestamp: Optional[Union[float, Timestamp]] = None, |
389 | | - ) -> None: |
390 | | - """Add a metric to the metric family. |
391 | | -
|
392 | | - Args: |
393 | | - labelvalues: A list of label values |
394 | | - buckets: A list of pairs of bucket names and values. |
395 | | - The buckets must be sorted, and +Inf present. |
396 | | - gsum_value: The sum value of the metric. |
397 | | - """ |
398 | | - for bucket, value in buckets: |
399 | | - self.samples.append( |
400 | | - Sample( |
401 | | - self.name + "_bucket", |
402 | | - dict(list(zip(self._labelnames, labelvalues)) + [("le", bucket)]), |
403 | | - value, |
404 | | - timestamp, |
405 | | - ) |
406 | | - ) |
407 | | - # +Inf is last and provides the count value. |
408 | | - self.samples.extend( |
409 | | - [ |
410 | | - Sample( |
411 | | - self.name + "_gcount", |
412 | | - dict(zip(self._labelnames, labelvalues)), |
413 | | - buckets[-1][1], |
414 | | - timestamp, |
415 | | - ), |
416 | | - Sample( |
417 | | - self.name + "_gsum", |
418 | | - dict(zip(self._labelnames, labelvalues)), |
419 | | - gsum_value, |
420 | | - timestamp, |
421 | | - ), |
422 | | - ] |
423 | | - ) |
| 378 | + self.add_metric(labels=labelvalues, buckets=buckets, gsum_value=gsum_value) |
424 | 379 |
|
425 | 380 |
|
426 | 381 | class GaugeBucketCollector(Collector): |
|
0 commit comments