satella.instrumentation.metrics package¶
Subpackages¶
- satella.instrumentation.metrics.exporters package
- satella.instrumentation.metrics.metric_types package
- Submodules
- satella.instrumentation.metrics.metric_types.base module
- satella.instrumentation.metrics.metric_types.callable module
- satella.instrumentation.metrics.metric_types.counter module
- satella.instrumentation.metrics.metric_types.cps module
- satella.instrumentation.metrics.metric_types.empty module
- satella.instrumentation.metrics.metric_types.histogram module
- satella.instrumentation.metrics.metric_types.linkfail module
- satella.instrumentation.metrics.metric_types.measurable_mixin module
- satella.instrumentation.metrics.metric_types.registry module
- satella.instrumentation.metrics.metric_types.simple module
- satella.instrumentation.metrics.metric_types.summary module
- satella.instrumentation.metrics.metric_types.uptime module
- Module contents
- satella.instrumentation.metrics.structures package
Submodules¶
satella.instrumentation.metrics.aggregate module¶
- class satella.instrumentation.metrics.aggregate.AggregateMetric(*metrics)¶
Bases:
Metric
,MeasurableMixin
A virtual metric grabbing a few other metrics and having a single .handle() call represent a bunch of calls to other metrics. Ie, the following:
>>> m1 = getMetric('summary', 'summary') >>> m2 = getMetric('histogram', 'histogram') >>> m1.runtime() >>> m2.runtime()
Is the same as:
>>> am = AggregateMetric(getMetric('summary', 'summary'), getMetric('histogram', 'histogram')) >>> am.runtime()
Note that this class supports only reporting. It doesn’t read data, or read/write metric levels.
When reimplementing the method, remember to pass kwargs here!
- handle(level, *args, **kwargs)¶
- Parameters:
level (Union[int, MetricLevel]) –
- Return type:
None
- metrics¶
satella.instrumentation.metrics.data module¶
- class satella.instrumentation.metrics.data.MetricData(name, value, labels=None, timestamp=None, internal=False)¶
Bases:
JSONAble
- Parameters:
name (str) –
value (float) –
labels (dict) –
timestamp (Optional[float]) –
internal (bool) –
- add_labels(labels)¶
- Parameters:
labels (dict) –
- Return type:
None
- add_timestamp(timestamp)¶
- Parameters:
timestamp (Optional[float]) –
- classmethod from_json(x)¶
- Parameters:
x (dict) –
- Return type:
- internal: bool¶
- labels¶
- name: str¶
- postfix_with(postfix)¶
- Parameters:
postfix (str) –
- Return type:
None
- prefix_with(prefix)¶
- Parameters:
prefix (str) –
- Return type:
None
- timestamp: Optional[float]¶
- to_json(prefix='')¶
Return a JSON-able representation of this object
- Parameters:
prefix (str) –
- Return type:
Optional[Union[list, dict, str, int, float]]
- value: Any¶
- class satella.instrumentation.metrics.data.MetricDataCollection(*values)¶
Bases:
JSONAble
A bunch of metric datas
- Parameters:
values (Union[MetricData, MetricDataCollection]) –
- add_labels(labels)¶
- Parameters:
labels (dict) –
- Return type:
None
- classmethod from_json(x)¶
- Parameters:
x (List[dict]) –
- Return type:
- postfix_with(postfix)¶
Postfix every child with given postfix and return self
- Parameters:
postfix (str) –
- Return type:
- prefix_with(prefix)¶
Prefix every child with given prefix and return self
- Parameters:
prefix (str) –
- Return type:
- remove_internals()¶
Remove entries marked as internal
- set_timestamp(timestamp)¶
Assign every child this timestamp and return self
- Parameters:
timestamp (float) –
- Return type:
- set_value(value)¶
Set all children to a particular value and return self. Most useful
- Return type:
- strict_eq(other)¶
Do values in other MetricDataCollection match also?
- Parameters:
other (MetricDataCollection) –
- Return type:
bool
- to_json()¶
Return a JSON-able representation of this object
- Return type:
Optional[Union[list, dict, str, int, float]]
- values¶
- satella.instrumentation.metrics.data.join_metric_data_name(prefix, name)¶
- Parameters:
prefix (str) –
name (str) –
satella.instrumentation.metrics.labeled module¶
- class satella.instrumentation.metrics.labeled.LabeledMetric(metric_to_wrap, **labels)¶
Bases:
Metric
,MeasurableMixin
A wrapper to another metric that will always call it’s .runtime and .handle with some predefined labels
Use like:
>>> a = getMetric('a', 'counter') >>> b = LabeledMetric(a, key=5)
Then this:
>>> a.runtime(1, key=5)
Will be equivalent to this:
>>> b.runtime(1)
When reimplementing the method, remember to pass kwargs here!
- callable¶
- handle(level, *args, **kwargs)¶
- Parameters:
level (Union[int, MetricLevel]) –
- Return type:
None
- labels¶
- metric_to_wrap¶
Module contents¶
- class satella.instrumentation.metrics.AggregateMetric(*metrics)¶
Bases:
Metric
,MeasurableMixin
A virtual metric grabbing a few other metrics and having a single .handle() call represent a bunch of calls to other metrics. Ie, the following:
>>> m1 = getMetric('summary', 'summary') >>> m2 = getMetric('histogram', 'histogram') >>> m1.runtime() >>> m2.runtime()
Is the same as:
>>> am = AggregateMetric(getMetric('summary', 'summary'), getMetric('histogram', 'histogram')) >>> am.runtime()
Note that this class supports only reporting. It doesn’t read data, or read/write metric levels.
When reimplementing the method, remember to pass kwargs here!
- handle(level, *args, **kwargs)¶
- Parameters:
level (Union[int, MetricLevel]) –
- Return type:
None
- metrics¶
- class satella.instrumentation.metrics.LabeledMetric(metric_to_wrap, **labels)¶
Bases:
Metric
,MeasurableMixin
A wrapper to another metric that will always call it’s .runtime and .handle with some predefined labels
Use like:
>>> a = getMetric('a', 'counter') >>> b = LabeledMetric(a, key=5)
Then this:
>>> a.runtime(1, key=5)
Will be equivalent to this:
>>> b.runtime(1)
When reimplementing the method, remember to pass kwargs here!
- callable¶
- handle(level, *args, **kwargs)¶
- Parameters:
level (Union[int, MetricLevel]) –
- Return type:
None
- labels¶
- metric_to_wrap¶
- class satella.instrumentation.metrics.Metric(name, root_metric=None, metric_level=None, internal=False, *args, **kwargs)¶
Bases:
object
Container for child metrics. A base metric class, as well as the default metric.
Switch levels by setting metric.level to a proper value
- Parameters:
enable_timestamp – append timestamp of last update to the metric
internal (bool) – if True, this metric won’t be visible in exporters
root_metric (Metric) –
metric_level (Optional[Union[MetricLevel, int]]) –
When reimplementing the method, remember to pass kwargs here!
- CLASS_NAME = 'base'¶
- can_process_this_level(target_level)¶
- Parameters:
target_level (MetricLevel) –
- Return type:
bool
- debug(*args, **kwargs)¶
- enable_timestamp¶
- get_fully_qualified_name()¶
- get_timestamp()¶
Return this timestamp, or None if no timestamp support is enabled
- Return type:
Optional[float]
- handle(level, *args, **kwargs)¶
- Parameters:
level (Union[int, MetricLevel]) –
- Return type:
None
- internal¶
- last_updated: Optional[float]¶
- property level: MetricLevel¶
- name¶
- reset()¶
Delete all child metrics that this metric contains.
Also, if called on root metric, sets the runlevel to RUNTIME
- Return type:
None
- root_metric¶
- runtime(*args, **kwargs)¶
- to_metric_data()¶
- Return type:
- class satella.instrumentation.metrics.MetricData(name, value, labels=None, timestamp=None, internal=False)¶
Bases:
JSONAble
- Parameters:
name (str) –
value (Any) –
labels (dict) –
timestamp (Optional[float]) –
internal (bool) –
- add_labels(labels)¶
- Parameters:
labels (dict) –
- Return type:
None
- add_timestamp(timestamp)¶
- Parameters:
timestamp (Optional[float]) –
- classmethod from_json(x)¶
- Parameters:
x (dict) –
- Return type:
- internal: bool¶
- labels¶
- name: str¶
- postfix_with(postfix)¶
- Parameters:
postfix (str) –
- Return type:
None
- prefix_with(prefix)¶
- Parameters:
prefix (str) –
- Return type:
None
- timestamp: Optional[float]¶
- to_json(prefix='')¶
Return a JSON-able representation of this object
- Parameters:
prefix (str) –
- Return type:
Optional[Union[list, dict, str, int, float]]
- value: Any¶
- class satella.instrumentation.metrics.MetricDataCollection(*values)¶
Bases:
JSONAble
A bunch of metric datas
- Parameters:
values (Union[MetricData, MetricDataCollection]) –
- add_labels(labels)¶
- Parameters:
labels (dict) –
- Return type:
None
- classmethod from_json(x)¶
- Parameters:
x (List[dict]) –
- Return type:
- postfix_with(postfix)¶
Postfix every child with given postfix and return self
- Parameters:
postfix (str) –
- Return type:
- prefix_with(prefix)¶
Prefix every child with given prefix and return self
- Parameters:
prefix (str) –
- Return type:
- remove_internals()¶
Remove entries marked as internal
- set_timestamp(timestamp)¶
Assign every child this timestamp and return self
- Parameters:
timestamp (float) –
- Return type:
- set_value(value)¶
Set all children to a particular value and return self. Most useful
- Return type:
- strict_eq(other)¶
Do values in other MetricDataCollection match also?
- Parameters:
other (MetricDataCollection) –
- Return type:
bool
- to_json()¶
Return a JSON-able representation of this object
- Return type:
Optional[Union[list, dict, str, int, float]]
- values¶
- class satella.instrumentation.metrics.MetricLevel(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)¶
Bases:
IntEnum
- DEBUG = 3¶
- DISABLED = 1¶
- INHERIT = 4¶
- RUNTIME = 2¶
- satella.instrumentation.metrics.getMetric(metric_name='', metric_type='base', metric_level=None, **kwargs)¶
Obtain a metric of given name.
- Parameters:
metric_name (str) – a metric name. Subsequent nesting levels have to be separated with a dot
metric_type (str) – metric type
metric_level (Optional[MetricLevel]) – a metric level to set this metric to.
- Raises:
MetricAlreadyExists – a metric having this name already exists, but with a different type
ValueError – metric name contains a forbidden character