2014-09-08 20:26:51 -07:00
|
|
|
.. _metrics:
|
|
|
|
|
|
|
|
===============================================
|
|
|
|
Emitting metrics from Ironic-Python-Agent (IPA)
|
|
|
|
===============================================
|
|
|
|
|
2024-10-22 14:31:34 -07:00
|
|
|
.. warning::
|
|
|
|
IPA metrics are deprecated and scheduled for removal at or after the
|
|
|
|
2026.1 OpenStack release cycle.
|
|
|
|
|
2014-09-08 20:26:51 -07:00
|
|
|
This document describes how to emit metrics from IPA, including timers and
|
|
|
|
counters in code to directly emitting hardware metrics from a custom
|
|
|
|
HardwareManager.
|
|
|
|
|
|
|
|
Overview
|
|
|
|
========
|
2024-10-22 14:31:34 -07:00
|
|
|
IPA uses a vendored version of the metrics implementation originally from
|
|
|
|
ironic-lib, with a few caveats due to the dynamic configuration done at
|
|
|
|
lookup time. You cannot cache the metrics instance as the MetricsLogger
|
|
|
|
returned will change after lookup if configs different than the default
|
|
|
|
setting have been used. This also means that the method decorator
|
|
|
|
cannot be used in IPA.
|
2014-09-08 20:26:51 -07:00
|
|
|
|
|
|
|
Using a context manager
|
|
|
|
=======================
|
|
|
|
Using the context manager is the recommended way for sending metrics that time
|
|
|
|
or count sections of code. However, given that you cannot cache the
|
|
|
|
MetricsLogger, you have to explicitly call get_metrics_logger() from
|
2024-10-22 14:31:34 -07:00
|
|
|
every time. For example::
|
2014-09-08 20:26:51 -07:00
|
|
|
|
2024-10-22 14:31:34 -07:00
|
|
|
from ironic_python_agent.metrics_lib import metrics_utils
|
2014-09-08 20:26:51 -07:00
|
|
|
|
|
|
|
def my_method():
|
2016-08-11 23:09:12 -04:00
|
|
|
with metrics_utils.get_metrics_logger(__name__).timer('my_method'):
|
2016-08-11 07:24:06 -04:00
|
|
|
return _do_work()
|
2014-09-08 20:26:51 -07:00
|
|
|
|
|
|
|
As a note, these metric collectors do work for custom HardwareManagers as
|
2016-08-11 23:09:12 -04:00
|
|
|
well. However, you may want to metric the portions of a method that determine
|
|
|
|
compatibility separate from portions of a method that actually do work, in
|
2014-09-08 20:26:51 -07:00
|
|
|
order to assure the metrics are relevant and useful on all hardware.
|
|
|
|
|
|
|
|
Explicitly sending metrics
|
|
|
|
==========================
|
|
|
|
A feature that may be particularly helpful for deployers writing custom
|
2016-08-11 23:09:12 -04:00
|
|
|
HardwareManagers is the ability to explicitly send metrics. For instance,
|
2014-09-08 20:26:51 -07:00
|
|
|
you could add a cleaning step which would retrieve metrics about a device and
|
2016-08-11 07:24:06 -04:00
|
|
|
ship them using the provided metrics library. For example::
|
2014-09-08 20:26:51 -07:00
|
|
|
|
2024-10-22 14:31:34 -07:00
|
|
|
from ironic_python_agent.metrics_lib import metrics_utils
|
2014-09-08 20:26:51 -07:00
|
|
|
|
|
|
|
def my_cleaning_step():
|
2016-08-11 07:24:06 -04:00
|
|
|
for name, value in _get_smart_data():
|
|
|
|
metrics_utils.get_metrics_logger(__name__).send_gauge(name, value)
|
2014-09-08 20:26:51 -07:00
|
|
|
|