Commit ee0c5a57 authored by Andrey Vertiprahov's avatar Andrey Vertiprahov Committed by Dmitry Volodin
Browse files

Generic.get_metrics. Add units (Measurement Units) param to set_metrics.

parent 18b3646a
......@@ -18,8 +18,8 @@ class CapabilityIndexRule(OIDRule):
name = "capindex"
def __init__(self, oid, type=None, scale=1, start=0, capability=None):
super().__init__(oid, type=type, scale=scale)
def __init__(self, oid, type=None, scale=1, units="1", start=0, capability=None):
super().__init__(oid, type=type, scale=scale, units=units)
self.start = start
self.capability = capability
......@@ -28,4 +28,4 @@ class CapabilityIndexRule(OIDRule):
for i in range(self.start, script.capabilities[self.capability] + self.start):
oid = self.expand_oid(index=i)
if oid:
yield oid, self.type, self.scale, cfg.labels
yield oid, self.type, self.scale, self.units, cfg.labels
......@@ -24,13 +24,14 @@ class CapabilityListRule(OIDRule):
oid,
type=None,
scale=1,
units="1",
capability=None,
separator=",",
strip=True,
default=None,
labels=None,
):
super().__init__(oid, type=type, scale=scale)
super().__init__(oid, type=type, scale=scale, units=units)
self.capability = capability
self.separator = separator
self.strip = strip
......@@ -53,9 +54,9 @@ class CapabilityListRule(OIDRule):
labels = self.labels[:]
labels[self.labels.index(item)] = item.replace("item", i)
if oid:
yield oid, self.type, self.scale, labels
yield oid, self.type, self.scale, self.units, labels
else:
if self.default is not None:
oid = self.expand_oid(item=self.default)
if oid:
yield oid, self.type, self.scale, cfg.labels
yield oid, self.type, self.scale, self.units, cfg.labels
......@@ -20,4 +20,4 @@ class InterfaceRule(OIDRule):
if cfg.ifindex is not None:
oid = self.expand_oid(ifIndex=cfg.ifindex)
if oid:
yield oid, self.type, self.scale, cfg.labels
yield oid, self.type, self.scale, self.units, cfg.labels
......@@ -22,13 +22,15 @@ class OIDRule(object):
name = "oid"
default_type = "gauge"
default_units = "1"
_scale_locals = {}
def __init__(self, oid, type=None, scale=1, labels=None):
def __init__(self, oid, type=None, scale=1, units=None, labels=None):
self.oid = oid
self.is_complex = not isinstance(oid, str)
self.type = type or self.default_type
self.units = units or self.default_units
self.scale = self._convert_scale(scale)
self.labels = labels or []
......@@ -50,9 +52,9 @@ class OIDRule(object):
:return:
"""
if self.is_complex:
yield tuple(self.oid), self.type, self.scale, self.labels
yield tuple(self.oid), self.type, self.scale, self.units, self.labels
else:
yield self.oid, self.type, self.scale, self.labels
yield self.oid, self.type, self.scale, self.units, self.labels
@classmethod
def from_json(cls, data):
......
......@@ -54,5 +54,7 @@ class IGetMetrics(BaseInterface):
"type": StringParameter(choices=["gauge", "counter", "bool", "delta"]),
# Measurement scale
"scale": IntParameter(default=1),
# Measurement units
"units": StringParameter(required=False)
}
)
{
"$metric": "CPU | Usage",
"$type": "oid",
"oid": "1.3.6.1.4.1.9148.3.2.1.1.1.0"
"oid": "1.3.6.1.4.1.9148.3.2.1.1.1.0",
"units": "%"
}
{
"$metric": "Memory | Usage",
"$type": "oid",
"oid": "1.3.6.1.4.1.9148.3.2.1.1.2.0"
"oid": "1.3.6.1.4.1.9148.3.2.1.1.2.0",
"units": "%"
}
\ No newline at end of file
......@@ -79,8 +79,8 @@ class SlotRule(OIDRule):
if self.is_complex:
gen = [mib[self.expand(o, {"hwSlotIndex": r[i]})] for o in self.oid]
if gen:
yield tuple(gen), self.type, self.scale, list(i)
yield tuple(gen), self.type, self.scale, self.units, list(i)
else:
oid = mib[self.expand(self.oid, {"hwSlotIndex": r[i]})]
if oid:
yield oid, self.type, self.scale, list(i)
yield oid, self.type, self.scale, self.units, list(i)
{
"$metric": "CPU | Usage",
"$type": "oid",
"oid": "1.3.6.1.4.1.637.61.1.9.29.1.1.4.4353"
"oid": "1.3.6.1.4.1.637.61.1.9.29.1.1.4.4353",
"units": "%"
}
......@@ -5,5 +5,6 @@
"1.3.6.1.4.1.637.61.1.9.29.2.1.2.4353",
"1.3.6.1.4.1.637.61.1.9.29.2.1.1.4353"
],
"scale": "percent"
"scale": "percent",
"units": "%"
}
......@@ -54,4 +54,4 @@ class SlotRule(OIDRule):
]
)
if oid:
yield oid, self.type, self.scale, labels
yield oid, self.type, self.scale, self.units, labels
{
"$metric": "CPU | Usage",
"$type": "oid",
"oid": "1.3.6.1.4.1.6486.800.1.2.1.16.1.1.1.13.0"
"oid": "1.3.6.1.4.1.6486.800.1.2.1.16.1.1.1.13.0",
"units": "%"
}
{
"$metric": "CPU | Usage | 5sec",
"$type": "slot",
"oid": "1.3.6.1.4.1.6486.800.1.2.1.16.1.1.2.1.1.10.{{ hwSlotIndex }}"
"oid": "1.3.6.1.4.1.6486.800.1.2.1.16.1.1.2.1.1.10.{{ hwSlotIndex }}",
"units": "%"
}
......@@ -5,5 +5,6 @@
"1.3.6.1.4.1.2011.6.3.5.1.1.3.{{ hwSlotIndex }}",
"1.3.6.1.4.1.2011.6.3.5.1.1.2.{{ hwSlotIndex }}"
],
"scale": "percent"
"scale": "percent",
"units": "%"
}
......@@ -13,11 +13,13 @@
"$type": "oid",
"oid": "1.3.6.1.4.1.9.9.109.1.1.1.1.7.7",
"type": "gauge",
"scale": 1
"scale": 1,
"units": "%"
},{
"$type": "oid",
"oid": "1.3.6.1.4.1.9.9.109.1.1.1.1.7.1",
"type": "gauge",
"scale": 1
"scale": 1,
"units": "%"
}]
}
......@@ -5,5 +5,6 @@
"1.3.6.1.4.1.9.9.48.1.1.1.6.1",
"1.3.6.1.4.1.9.9.48.1.1.1.5.1"
],
"scale": "percent_usage"
"scale": "percent_usage",
"units": "%"
}
{
"$metric": "CPU | Usage",
"$type": "oid",
"oid": "1.3.6.1.4.1.14179.1.1.5.1.0"
"oid": "1.3.6.1.4.1.14179.1.1.5.1.0",
"units": "%"
}
......@@ -5,5 +5,6 @@
"1.3.6.1.4.1.14179.1.1.5.3.0",
"1.3.6.1.4.1.14179.1.1.5.2.0"
],
"scale": "percent"
"scale": "percent",
"units": "%"
}
......@@ -13,11 +13,13 @@
"$type": "oid",
"oid": "1.3.6.1.4.1.259.10.1.46.1.39.2.3.0",
"type": "gauge",
"scale": 1
"scale": 1,
"units": "%"
},{
"$type": "oid",
"oid": "1.3.6.1.4.1.259.6.10.94.1.39.2.3.0",
"type": "gauge",
"scale": 1
"scale": 1,
"units": "%"
}]
}
......@@ -15,13 +15,15 @@
"1.3.6.1.4.1.259.10.1.46.1.39.3.2.0",
"1.3.6.1.4.1.259.10.1.46.1.39.3.1.0"
],
"scale": "percent"
"scale": "percent",
"units": "%"
},{
"$type": "oid",
"oid": [
"1.3.6.1.4.1.259.6.10.94.1.39.3.2.0",
"1.3.6.1.4.1.259.6.10.94.1.39.3.1.0"
],
"scale": "percent"
"scale": "percent",
"units": "%"
}]
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment