MCPcopy Create free account
hub / github.com/prometheus/client_python / GaugeMetricFamily

Class GaugeMetricFamily

prometheus_client/metrics_core.py:148–177  ·  view source on GitHub ↗

A single gauge and its samples. For use by custom collectors.

Source from the content-addressed store, hash-verified

146
147
148class GaugeMetricFamily(Metric):
149 """A single gauge and its samples.
150
151 For use by custom collectors.
152 """
153
154 def __init__(self,
155 name: str,
156 documentation: str,
157 value: Optional[float] = None,
158 labels: Optional[Sequence[str]] = None,
159 unit: str = '',
160 ):
161 Metric.__init__(self, name, documentation, 'gauge', unit)
162 if labels is not None and value is not None:
163 raise ValueError('Can only specify at most one of value and labels.')
164 if labels is None:
165 labels = []
166 self._labelnames = tuple(labels)
167 if value is not None:
168 self.add_metric([], value)
169
170 def add_metric(self, labels: Sequence[str], value: float, timestamp: Optional[Union[Timestamp, float]] = None) -> None:
171 """Add a metric to the metric family.
172
173 Args:
174 labels: A list of label values
175 value: A float
176 """
177 self.samples.append(Sample(self.name, dict(zip(self._labelnames, labels)), value, timestamp))
178
179
180class SummaryMetricFamily(Metric):

Callers 15

collectMethod · 0.90
test_simple_gaugeMethod · 0.90
test_gaugeMethod · 0.90
test_gauge_labelsMethod · 0.90
test_labelnamesMethod · 0.90
test_simple_gaugeMethod · 0.90
test_float_gaugeMethod · 0.90
test_unit_gaugeMethod · 0.90

Calls

no outgoing calls

Tested by 12

test_simple_gaugeMethod · 0.72
test_gaugeMethod · 0.72
test_gauge_labelsMethod · 0.72
test_labelnamesMethod · 0.72
test_simple_gaugeMethod · 0.72
test_float_gaugeMethod · 0.72
test_unit_gaugeMethod · 0.72