A single gauge and its samples. For use by custom collectors.
| 146 | |
| 147 | |
| 148 | class 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 | |
| 180 | class SummaryMetricFamily(Metric): |
no outgoing calls