A single info and its samples. For use by custom collectors.
| 333 | |
| 334 | |
| 335 | class InfoMetricFamily(Metric): |
| 336 | """A single info and its samples. |
| 337 | |
| 338 | For use by custom collectors. |
| 339 | """ |
| 340 | |
| 341 | def __init__(self, |
| 342 | name: str, |
| 343 | documentation: str, |
| 344 | value: Optional[Dict[str, str]] = None, |
| 345 | labels: Optional[Sequence[str]] = None, |
| 346 | ): |
| 347 | Metric.__init__(self, name, documentation, 'info') |
| 348 | if labels is not None and value is not None: |
| 349 | raise ValueError('Can only specify at most one of value and labels.') |
| 350 | if labels is None: |
| 351 | labels = [] |
| 352 | self._labelnames = tuple(labels) |
| 353 | if value is not None: |
| 354 | self.add_metric([], value) |
| 355 | |
| 356 | def add_metric(self, |
| 357 | labels: Sequence[str], |
| 358 | value: Dict[str, str], |
| 359 | timestamp: Optional[Union[Timestamp, float]] = None, |
| 360 | ) -> None: |
| 361 | """Add a metric to the metric family. |
| 362 | |
| 363 | Args: |
| 364 | labels: A list of label values |
| 365 | value: A dict of labels |
| 366 | """ |
| 367 | self.samples.append(Sample( |
| 368 | self.name + '_info', |
| 369 | dict(dict(zip(self._labelnames, labels)), **value), |
| 370 | 1, |
| 371 | timestamp, |
| 372 | )) |
| 373 | |
| 374 | |
| 375 | class StateSetMetricFamily(Metric): |
no outgoing calls