The ironic_lib.metrics
Module¶
-
class
ironic_lib.metrics.
Counter
(metrics, name, sample_rate)[source]¶ Bases:
object
A counter decorator and context manager.
This metric type increments a counter every time the decorated method or context manager is executed. It is bound to this MetricLogger. For example:
from ironic_lib import metrics_utils METRICS = metrics_utils.get_metrics_logger() @METRICS.counter('foo') def foo(bar, baz): print bar, baz with METRICS.counter('foo'): do_something()
-
class
ironic_lib.metrics.
Gauge
(metrics, name)[source]¶ Bases:
object
A gauge decorator.
This metric type returns the value of the decorated method as a metric every time the method is executed. It is bound to this MetricLogger. For example:
from ironic_lib import metrics_utils METRICS = metrics_utils.get_metrics_logger() @METRICS.gauge('foo') def add_foo(bar, baz): return (bar + baz)
-
class
ironic_lib.metrics.
MetricLogger
(prefix=”, delimiter=’.’)[source]¶ Bases:
object
Abstract class representing a metrics logger.
A MetricLogger sends data to a backend (noop or statsd). The data can be a gauge, a counter, or a timer.
- The data sent to the backend is composed of:
- a full metric name
- a numeric value
- The format of the full metric name is:
- _prefix<delim>name
- where:
- _prefix: [global_prefix<delim>][uuid<delim>][host_name<delim>]prefix
- name: the name of this metric
- <delim>: the delimiter. Default is ‘.’
-
get_metric_name
(name)[source]¶ Get the full metric name.
- The format of the full metric name is:
- _prefix<delim>name
- where:
- _prefix: [global_prefix<delim>][uuid<delim>][host_name<delim>] prefix
- name: the name of this metric
- <delim>: the delimiter. Default is ‘.’
Parameters: name – The metric name. Returns: The full metric name, with logger prefix, as a string.
-
send_counter
(name, value, sample_rate=None)[source]¶ Send counter metric data.
Counters are used to count how many times an event occurred. The backend will increment the counter ‘name’ by the value ‘value’.
Optionally, specify sample_rate in the interval [0.0, 1.0] to sample data probabilistically where:
P(send metric data) = sample_rate
If sample_rate is None, then always send metric data, but do not have the backend send sample rate information (if supported).
Parameters: - name – Metric name
- value – Metric numeric value that will be sent to the backend
- sample_rate – Probabilistic rate at which the values will be sent. Value must be None or in the interval [0.0, 1.0].
-
send_gauge
(name, value)[source]¶ Send gauge metric data.
Gauges are simple values. The backend will set the value of gauge ‘name’ to ‘value’.
Parameters: - name – Metric name
- value – Metric numeric value that will be sent to the backend
-
class
ironic_lib.metrics.
NoopMetricLogger
(prefix=”, delimiter=’.’)[source]¶ Bases:
ironic_lib.metrics.MetricLogger
Noop metric logger that throws away all metric data.
-
class
ironic_lib.metrics.
Timer
(metrics, name)[source]¶ Bases:
object
A timer decorator and context manager.
This metric type times the decorated method or code running inside the context manager, and emits the time as the metric value. It is bound to this MetricLogger. For example:
from ironic_lib import metrics_utils METRICS = metrics_utils.get_metrics_logger() @METRICS.timer('foo') def foo(bar, baz): print bar, baz with METRICS.timer('foo'): do_something()