certwrangler.metrics module#

class certwrangler.metrics.DynamicInfo(name: str, documentation: str, labelnames: ~typing.Iterable[str] = (), namespace: str = '', subsystem: str = '', unit: str = '', registry: ~prometheus_client.registry.CollectorRegistry | None = <prometheus_client.registry.CollectorRegistry object>, _labelvalues: ~typing.Sequence[str] | None = None)[source]#

Bases: Info

Patched version of the Info class from prometheus_client to add support for pulling samples from a function, similar to gauges.

set_function(f: Callable[[], Dict[str, str]]) None[source]#

Call the provided function to return the Info value.

The function must return a dict of strings. All other methods of the DynamicInfo become NOOPs.

class certwrangler.metrics.EntityMetrics(counters: ~typing.Dict[str, ~prometheus_client.metrics.Counter] = <factory>, gauges: ~typing.Dict[str, ~prometheus_client.metrics.Gauge] = <factory>, infos: ~typing.Dict[str, ~certwrangler.metrics.DynamicInfo] = <factory>)[source]#

Bases: object

A registry of labeled metrics for an entity.

counters: Dict[str, Counter]#
gauges: Dict[str, Gauge]#
infos: Dict[str, DynamicInfo]#
class certwrangler.metrics.MetricRegistry(subsystem: str)[source]#

Bases: UserDict[str, EntityMetrics]

A registry of metrics for dynamic named entities. Metrics that are added to this automatically get a name label appended to them.

Parameters:

subsystem – The name of the subsystem for the metrics.

add_counter(name: str, documentation: str, unit: str = '') None[source]#

Register a new counter in the registry.

Parameters:
  • name – The name of the metric.

  • documentation – A description of the metric.

  • unit – The unit of the metric.

add_gauge(name: str, documentation: str, unit: str = '', function: Callable[[Context, str], float] | None = None) None[source]#

Register a new gauge in the registry.

Parameters:
  • name – The name of the metric.

  • documentation – A description of the metric.

  • unit – The unit of the metric.

  • function – An optional callable to execute to compute the metric.

add_info(name: str, documentation: str, function: Callable[[Context, str], Dict[str, str]] | None = None) None[source]#

Register a new info in the registry.

Parameters:
  • name – The name of the metric.

  • documentation – A description of the metric.

  • function – An optional callable to execute to compute the metric.

reconcile_entities(entities: List[str]) None[source]#

Takes the list of entities that should be present and updates the registry to reflect that.

Parameters:

entities – A list of entity names that should be present.

add_entity(entity_name: str) None[source]#

Add an entity to the registry and create labeled metrics for it.

Parameters:

entity_name – The name of the entity to add.

remove_entity(entity_name: str) None[source]#

Remove an entity from the registry and clear out all the labeled metrics for it.

Parameters:

entity_name – The name of the entity to remove.

certwrangler.metrics.reconcile_dynamic_metrics(ctx: Context) None[source]#

Triggers the metric registries to reconcile their registered entities based on any updates to the config.

Parameters:

ctx – The click.Context of the application.