MCPcopy Index your code
hub / github.com/prometheus/client_python / CounterMetricFamily

Class CounterMetricFamily

prometheus_client/metrics_core.py:102–145  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

100
101
102class CounterMetricFamily(Metric):
103 """A single counter and its samples.
104
105 For use by custom collectors.
106 """
107
108 def __init__(self,
109 name: str,
110 documentation: str,
111 value: Optional[float] = None,
112 labels: Optional[Sequence[str]] = None,
113 created: Optional[float] = None,
114 unit: str = '',
115 exemplar: Optional[Exemplar] = None,
116 ):
117 # Glue code for pre-OpenMetrics metrics.
118 if name.endswith('_total'):
119 name = name[:-6]
120 Metric.__init__(self, name, documentation, 'counter', unit)
121 if labels is not None and value is not None:
122 raise ValueError('Can only specify at most one of value and labels.')
123 if labels is None:
124 labels = []
125 self._labelnames = tuple(labels)
126 if value is not None:
127 self.add_metric([], value, created, exemplar=exemplar)
128
129 def add_metric(self,
130 labels: Sequence[str],
131 value: float,
132 created: Optional[float] = None,
133 timestamp: Optional[Union[Timestamp, float]] = None,
134 exemplar: Optional[Exemplar] = None,
135 ) -> None:
136 """Add a metric to the metric family.
137
138 Args:
139 labels: A list of label values
140 value: The value of the metric
141 created: Optional unix timestamp the child was created at.
142 """
143 self.samples.append(Sample(self.name + '_total', dict(zip(self._labelnames, labels)), value, timestamp, exemplar))
144 if created is not None:
145 self.samples.append(Sample(self.name + '_created', dict(zip(self._labelnames, labels)), created, timestamp))
146
147
148class GaugeMetricFamily(Metric):

Callers 15

test_simple_counterMethod · 0.90
test_utf8_counterMethod · 0.90
test_extra_whitespaceMethod · 0.90
test_tabsMethod · 0.90
test_empty_helpMethod · 0.90
test_spacesMethod · 0.90
test_commasMethod · 0.90

Calls

no outgoing calls

Tested by 15

test_simple_counterMethod · 0.72
test_utf8_counterMethod · 0.72
test_extra_whitespaceMethod · 0.72
test_tabsMethod · 0.72
test_empty_helpMethod · 0.72
test_spacesMethod · 0.72
test_commasMethod · 0.72