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): ...@@ -18,8 +18,8 @@ class CapabilityIndexRule(OIDRule):
name = "capindex" name = "capindex"
def __init__(self, oid, type=None, scale=1, start=0, capability=None): def __init__(self, oid, type=None, scale=1, units="1", start=0, capability=None):
super().__init__(oid, type=type, scale=scale) super().__init__(oid, type=type, scale=scale, units=units)
self.start = start self.start = start
self.capability = capability self.capability = capability
...@@ -28,4 +28,4 @@ class CapabilityIndexRule(OIDRule): ...@@ -28,4 +28,4 @@ class CapabilityIndexRule(OIDRule):
for i in range(self.start, script.capabilities[self.capability] + self.start): for i in range(self.start, script.capabilities[self.capability] + self.start):
oid = self.expand_oid(index=i) oid = self.expand_oid(index=i)
if oid: 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): ...@@ -24,13 +24,14 @@ class CapabilityListRule(OIDRule):
oid, oid,
type=None, type=None,
scale=1, scale=1,
units="1",
capability=None, capability=None,
separator=",", separator=",",
strip=True, strip=True,
default=None, default=None,
labels=None, labels=None,
): ):
super().__init__(oid, type=type, scale=scale) super().__init__(oid, type=type, scale=scale, units=units)
self.capability = capability self.capability = capability
self.separator = separator self.separator = separator
self.strip = strip self.strip = strip
...@@ -53,9 +54,9 @@ class CapabilityListRule(OIDRule): ...@@ -53,9 +54,9 @@ class CapabilityListRule(OIDRule):
labels = self.labels[:] labels = self.labels[:]
labels[self.labels.index(item)] = item.replace("item", i) labels[self.labels.index(item)] = item.replace("item", i)
if oid: if oid:
yield oid, self.type, self.scale, labels yield oid, self.type, self.scale, self.units, labels
else: else:
if self.default is not None: if self.default is not None:
oid = self.expand_oid(item=self.default) oid = self.expand_oid(item=self.default)
if oid: 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): ...@@ -20,4 +20,4 @@ class InterfaceRule(OIDRule):
if cfg.ifindex is not None: if cfg.ifindex is not None:
oid = self.expand_oid(ifIndex=cfg.ifindex) oid = self.expand_oid(ifIndex=cfg.ifindex)
if oid: 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): ...@@ -22,13 +22,15 @@ class OIDRule(object):
name = "oid" name = "oid"
default_type = "gauge" default_type = "gauge"
default_units = "1"
_scale_locals = {} _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.oid = oid
self.is_complex = not isinstance(oid, str) self.is_complex = not isinstance(oid, str)
self.type = type or self.default_type self.type = type or self.default_type
self.units = units or self.default_units
self.scale = self._convert_scale(scale) self.scale = self._convert_scale(scale)
self.labels = labels or [] self.labels = labels or []
...@@ -50,9 +52,9 @@ class OIDRule(object): ...@@ -50,9 +52,9 @@ class OIDRule(object):
:return: :return:
""" """
if self.is_complex: 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: else:
yield self.oid, self.type, self.scale, self.labels yield self.oid, self.type, self.scale, self.units, self.labels
@classmethod @classmethod
def from_json(cls, data): def from_json(cls, data):
......
...@@ -54,5 +54,7 @@ class IGetMetrics(BaseInterface): ...@@ -54,5 +54,7 @@ class IGetMetrics(BaseInterface):
"type": StringParameter(choices=["gauge", "counter", "bool", "delta"]), "type": StringParameter(choices=["gauge", "counter", "bool", "delta"]),
# Measurement scale # Measurement scale
"scale": IntParameter(default=1), "scale": IntParameter(default=1),
# Measurement units
"units": StringParameter(required=False)
} }
) )
{ {
"$metric": "CPU | Usage", "$metric": "CPU | Usage",
"$type": "oid", "$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", "$metric": "Memory | Usage",
"$type": "oid", "$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): ...@@ -79,8 +79,8 @@ class SlotRule(OIDRule):
if self.is_complex: if self.is_complex:
gen = [mib[self.expand(o, {"hwSlotIndex": r[i]})] for o in self.oid] gen = [mib[self.expand(o, {"hwSlotIndex": r[i]})] for o in self.oid]
if gen: if gen:
yield tuple(gen), self.type, self.scale, list(i) yield tuple(gen), self.type, self.scale, self.units, list(i)
else: else:
oid = mib[self.expand(self.oid, {"hwSlotIndex": r[i]})] oid = mib[self.expand(self.oid, {"hwSlotIndex": r[i]})]
if oid: if oid:
yield oid, self.type, self.scale, list(i) yield oid, self.type, self.scale, self.units, list(i)
{ {
"$metric": "CPU | Usage", "$metric": "CPU | Usage",
"$type": "oid", "$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 @@ ...@@ -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.2.4353",
"1.3.6.1.4.1.637.61.1.9.29.2.1.1.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): ...@@ -54,4 +54,4 @@ class SlotRule(OIDRule):
] ]
) )
if oid: if oid:
yield oid, self.type, self.scale, labels yield oid, self.type, self.scale, self.units, labels
{ {
"$metric": "CPU | Usage", "$metric": "CPU | Usage",
"$type": "oid", "$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", "$metric": "CPU | Usage | 5sec",
"$type": "slot", "$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 @@ ...@@ -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.3.{{ hwSlotIndex }}",
"1.3.6.1.4.1.2011.6.3.5.1.1.2.{{ hwSlotIndex }}" "1.3.6.1.4.1.2011.6.3.5.1.1.2.{{ hwSlotIndex }}"
], ],
"scale": "percent" "scale": "percent",
"units": "%"
} }
...@@ -13,11 +13,13 @@ ...@@ -13,11 +13,13 @@
"$type": "oid", "$type": "oid",
"oid": "1.3.6.1.4.1.9.9.109.1.1.1.1.7.7", "oid": "1.3.6.1.4.1.9.9.109.1.1.1.1.7.7",
"type": "gauge", "type": "gauge",
"scale": 1 "scale": 1,
"units": "%"
},{ },{
"$type": "oid", "$type": "oid",
"oid": "1.3.6.1.4.1.9.9.109.1.1.1.1.7.1", "oid": "1.3.6.1.4.1.9.9.109.1.1.1.1.7.1",
"type": "gauge", "type": "gauge",
"scale": 1 "scale": 1,
"units": "%"
}] }]
} }
...@@ -5,5 +5,6 @@ ...@@ -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.6.1",
"1.3.6.1.4.1.9.9.48.1.1.1.5.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", "$metric": "CPU | Usage",
"$type": "oid", "$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 @@ ...@@ -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.3.0",
"1.3.6.1.4.1.14179.1.1.5.2.0" "1.3.6.1.4.1.14179.1.1.5.2.0"
], ],
"scale": "percent" "scale": "percent",
"units": "%"
} }
...@@ -13,11 +13,13 @@ ...@@ -13,11 +13,13 @@
"$type": "oid", "$type": "oid",
"oid": "1.3.6.1.4.1.259.10.1.46.1.39.2.3.0", "oid": "1.3.6.1.4.1.259.10.1.46.1.39.2.3.0",
"type": "gauge", "type": "gauge",
"scale": 1 "scale": 1,
"units": "%"
},{ },{
"$type": "oid", "$type": "oid",
"oid": "1.3.6.1.4.1.259.6.10.94.1.39.2.3.0", "oid": "1.3.6.1.4.1.259.6.10.94.1.39.2.3.0",
"type": "gauge", "type": "gauge",
"scale": 1 "scale": 1,
"units": "%"
}] }]
} }
...@@ -15,13 +15,15 @@ ...@@ -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.2.0",
"1.3.6.1.4.1.259.10.1.46.1.39.3.1.0" "1.3.6.1.4.1.259.10.1.46.1.39.3.1.0"
], ],
"scale": "percent" "scale": "percent",
"units": "%"
},{ },{
"$type": "oid", "$type": "oid",
"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.2.0",
"1.3.6.1.4.1.259.6.10.94.1.39.3.1.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