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
......@@ -6,18 +6,21 @@
"$type": "oid",
"oid": "1.3.6.1.4.1.34300.1.6.7.2.1.3.4.0",
"type": "gauge",
"scale": "convert_percent_str"
"scale": "convert_percent_str",
"units": "%"
},{
"$match": "is_platform_MXA32",
"$type": "oid",
"oid": "1.3.6.1.4.1.35265.1.28.7.2.1.3.4",
"type": "gauge",
"scale": "convert_percent_str"
"scale": "convert_percent_str",
"units": "%"
},{
"$match": "is_platform_MXA64",
"$type": "oid",
"oid": "1.3.6.1.4.1.35265.1.33.7.2.1.3.4",
"type": "gauge",
"scale": "convert_percent_str"
"scale": "convert_percent_str",
"units": "%"
}]
}
\ No newline at end of file
......@@ -8,7 +8,8 @@
"1.3.6.1.4.1.34300.1.6.9.2.1.3.2.0",
"1.3.6.1.4.1.34300.1.6.9.2.1.3.1.0"
],
"scale": "percent_usage"
"scale": "percent_usage",
"units": "%"
},{
"$match": "is_platform_MXA32",
"$type": "oid",
......@@ -16,7 +17,8 @@
"1.3.6.1.4.1.35265.1.28.9.2.1.3.2",
"1.3.6.1.4.1.35265.1.28.9.2.1.3.1"
],
"scale": "percent_usage"
"scale": "percent_usage",
"units": "%"
},{
"$match": "is_platform_MXA64",
"$type": "oid",
......@@ -24,6 +26,7 @@
"1.3.6.1.4.1.35265.1.33.9.2.1.3.2",
"1.3.6.1.4.1.35265.1.33.9.2.1.3.1"
],
"scale": "percent_usage"
"scale": "percent_usage",
"units": "%"
}]
}
\ No newline at end of file
......@@ -5,5 +5,6 @@
"1.3.6.1.4.1.2021.4.5.0",
"1.3.6.1.4.1.2021.4.11.0"
],
"scale": "percent_usage"
"scale": "percent_usage",
"units": "%"
}
\ No newline at end of file
......@@ -2,5 +2,6 @@
"$metric": "Object | SysUptime",
"$type": "oid",
"oid": "1.3.6.1.4.1.35265.1.21.1.35.0",
"type": "gauge"
"type": "gauge",
"units": "s"
}
{
"$metric": "CPU | Usage",
"$type": "oid",
"oid": "1.3.6.1.4.1.89.1.8.0"
"oid": "1.3.6.1.4.1.89.1.8.0",
"units": "%"
}
{
"$metric": "Memory | Usage",
"$type": "oid",
"oid": "1.3.6.1.4.1.35265.41.1.2.1.1.6.0"
"oid": "1.3.6.1.4.1.35265.41.1.2.1.1.6.0",
"units": "%"
}
{
"$metric": "CPU | Usage",
"$type": "oid",
"oid": "1.3.6.1.4.1.35265.1.139.6.1.1.2.1.0"
"oid": "1.3.6.1.4.1.35265.1.139.6.1.1.2.1.0",
"units": "%"
}
{
"$metric": "Memory | Usage",
"$type": "oid",
"oid": "1.3.6.1.4.1.2076.81.1.73.0"
"oid": "1.3.6.1.4.1.2076.81.1.73.0",
"units": "%"
}
\ No newline at end of file
{
"$metric": "CPU | Usage",
"$type": "oid",
"oid": "1.3.6.1.4.1.4413.1.1.1.1.4.9.0"
"oid": "1.3.6.1.4.1.4413.1.1.1.1.4.9.0",
"units": "%"
}
......@@ -5,5 +5,6 @@
"1.3.6.1.4.1.4413.1.1.1.1.4.1",
"1.3.6.1.4.1.4413.1.1.1.1.4.2"
],
"scale": "percent"
"scale": "percent",
"units": "%"
}
\ No newline at end of file
......@@ -5,5 +5,6 @@
"separator": " | ",
"default": "1",
"labels": ["noc::chassis::0", "noc::slot::item", "noc::module::0"],
"oid": "1.3.6.1.4.1.1916.1.32.1.4.1.7.{{ item }}"
"oid": "1.3.6.1.4.1.1916.1.32.1.4.1.7.{{ item }}",
"units": "%"
}
......@@ -9,5 +9,6 @@
"1.3.6.1.4.1.1916.1.32.2.2.1.3.{{ item }}",
"1.3.6.1.4.1.1916.1.32.2.2.1.2.{{ item }}"
],
"scale": "percent_invert"
"scale": "percent_invert",
"units": "%"
}
......@@ -56,14 +56,15 @@ class MetricConfig(object):
class BatchConfig(object):
__slots__ = ("id", "metric", "labels", "type", "scale")
__slots__ = ("id", "metric", "labels", "type", "scale", "units")
def __init__(self, id, metric, labels, type, scale):
def __init__(self, id, metric, labels, type, scale, units):
self.id: int = id
self.metric: str = metric
self.labels: List[str] = labels
self.type: str = type
self.scale = scale
self.units = units
# Internal sequence number for @metrics decorator ordering
......@@ -399,9 +400,16 @@ class Script(BaseScript, metaclass=MetricScriptBase):
:return:
"""
for m in self.metric_configs[metric]:
for oid, vtype, scale, labels in rule.iter_oids(self, m):
for oid, vtype, scale, units, labels in rule.iter_oids(self, m):
self.snmp_batch[oid] += [
BatchConfig(id=m.id, metric=m.metric, labels=labels, type=vtype, scale=scale)
BatchConfig(
id=m.id,
metric=m.metric,
labels=labels,
type=vtype,
scale=scale,
units=units,
)
]
# Mark as seen to stop further processing
self.seen_ids.add(m.id)
......@@ -474,6 +482,7 @@ class Script(BaseScript, metaclass=MetricScriptBase):
labels=bv.labels,
type=bv.type,
scale=bv.scale,
units=bv.units,
)
def get_ifindex(self, name):
......@@ -489,13 +498,14 @@ class Script(BaseScript, metaclass=MetricScriptBase):
def set_metric(
self,
id: Union[int, Tuple[str, None]],
id: Union[int, Tuple[str, Optional[List[str]]]],
metric: str = None,
value: Union[int, float] = 0,
ts: Optional[int] = None,
labels: Optional[Union[List[str], Tuple[str]]] = None,
type: str = "gauge",
scale: Union[float, int, Callable] = 1,
units: str = "1",
multi: bool = False,
):
"""
......@@ -518,6 +528,8 @@ class Script(BaseScript, metaclass=MetricScriptBase):
"bool"
:param scale: Metric scale (Multiplier to be applied after all processing).
When callable, function will be called, passing value as positional argument
:param units: Metric MeasurementUnit code. Default - Scalar
Possible values from menu: Performance Management -> Setup -> Measurement Unit
:param multi: True if single request can return several different labels.
When False - only first call with composite labels for same labels will be returned
"""
......@@ -552,6 +564,7 @@ class Script(BaseScript, metaclass=MetricScriptBase):
"labels": labels or [],
"value": value,
"type": type,
"units": units,
"scale": scale,
}
]
......
......@@ -4,11 +4,13 @@
"hires": {
"$type": "ifindex",
"oid": "IF-MIB::ifHCInBroadcastPkts.{{ ifIndex }}",
"type": "counter"
"type": "counter",
"units": "pkt"
},
"normal": {
"$type": "ifindex",
"oid": "IF-MIB::ifInBroadcastPkts.{{ ifIndex }}",
"type": "counter"
"type": "counter",
"units": "pkt"
}
}
......@@ -4,11 +4,13 @@
"hires": {
"$type": "ifindex",
"oid": "IF-MIB::ifHCOutBroadcastPkts.{{ ifIndex }}",
"type": "counter"
"type": "counter",
"units": "pkt"
},
"normal": {
"$type": "ifindex",
"oid": "IF-MIB::ifOutBroadcastPkts.{{ ifIndex }}",
"type": "counter"
"type": "counter",
"units": "pkt"
}
}
......@@ -2,5 +2,6 @@
"$metric": "Interface | Discards | In",
"$type": "ifindex",
"oid": "IF-MIB::ifInDiscards.{{ ifIndex }}",
"type": "counter"
"type": "counter",
"units": "pkt"
}
......@@ -2,5 +2,6 @@
"$metric": "Interface | Discards | Out",
"$type": "ifindex",
"oid": "IF-MIB::ifOutDiscards.{{ ifIndex }}",
"type": "counter"
"type": "counter",
"units": "pkt"
}
......@@ -2,5 +2,6 @@
"$metric": "Interface | Errors | In",
"$type": "ifindex",
"oid": "IF-MIB::ifInErrors.{{ ifIndex }}",
"type": "counter"
"type": "counter",
"units": "pkt"
}
......@@ -2,5 +2,6 @@
"$metric": "Interface | Errors | In | Delta",
"$type": "ifindex",
"oid": "IF-MIB::ifInErrors.{{ ifIndex }}",
"type": "delta"
"type": "delta",
"units": "pkt"
}
......@@ -2,5 +2,6 @@
"$metric": "Interface | Errors | Out",
"$type": "ifindex",
"oid": "IF-MIB::ifOutErrors.{{ ifIndex }}",
"type": "counter"
"type": "counter",
"units": "pkt"
}
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