Merge "Add the NOTNUMBOOL mutator"
This commit is contained in:
commit
65f1591e31
@ -89,10 +89,11 @@ METRIC_BASE_SCHEMA = {
|
||||
Required('metadata', default=list): [
|
||||
All(str, Length(min=1))
|
||||
],
|
||||
# Mutate collected value. May be any of (NONE, NUMBOOL, FLOOR, CEIL).
|
||||
# Mutate collected value. May be any of:
|
||||
# (NONE, NUMBOOL, NOTNUMBOOL, FLOOR, CEIL).
|
||||
# Defaults to NONE
|
||||
Required('mutate', default='NONE'):
|
||||
In(['NONE', 'NUMBOOL', 'FLOOR', 'CEIL']),
|
||||
In(['NONE', 'NUMBOOL', 'NOTNUMBOOL', 'FLOOR', 'CEIL']),
|
||||
# Collector-specific args. Should be overriden by schema provided for
|
||||
# the given collector
|
||||
Optional('extra_args'): dict,
|
||||
|
@ -257,6 +257,9 @@ def mutate(value, mode='NONE'):
|
||||
if mode == 'NUMBOOL':
|
||||
return float(value != 0.0)
|
||||
|
||||
if mode == 'NOTNUMBOOL':
|
||||
return float(value == 0.0)
|
||||
|
||||
if mode == 'FLOOR':
|
||||
return math.floor(value)
|
||||
|
||||
|
@ -186,6 +186,9 @@ Four values are accepted for this parameter:
|
||||
|
||||
* ``NUMBOOL``: If the collected qty equals 0, leave it at 0. Else, set it to 1.
|
||||
|
||||
* ``NOTNUMBOOL``: If the collected qty equals 0, set it to 1. Else, set it to
|
||||
0.
|
||||
|
||||
.. warning::
|
||||
|
||||
Quantity mutation is done **after** conversion. Example::
|
||||
@ -214,6 +217,21 @@ then defined based on the instance metadata. Example:
|
||||
metadata:
|
||||
- flavor_id
|
||||
|
||||
The ``NOTNUMBOOL`` mutator is useful for status-like metrics where 0 denotes
|
||||
the billable state. For example the following Prometheus metric has value of 0
|
||||
when the instance is in ACTIVE state but 4 if the instance is in ERROR state:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
metrics:
|
||||
openstack_nova_server_status:
|
||||
unit: instance
|
||||
mutate: NOTNUMBOOL
|
||||
groupby:
|
||||
- id
|
||||
metadata:
|
||||
- flavor_id
|
||||
|
||||
Display name
|
||||
~~~~~~~~~~~~
|
||||
|
||||
|
@ -0,0 +1,6 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
The new "NOTNUMBOOL" mutator has been added. This mutator is, essentially,
|
||||
an opposite of the "NUMBOOL" mutator as it returns 1.0 when quantity is 0
|
||||
and 0.0 otherwise.
|
Loading…
Reference in New Issue
Block a user