I wrote a SNMP-plugin for the QueueTree of Mikrotik Routers, which discovers the services and gets values. But theses values are absolut counters which are raising all the time - like interface counters. What I want is to display these as values per seconds like the bandwidth in interfaces.
But they are diplayed as they are - raising counters.
Thanks in advance,
Bernhard
Here is my plugin:
from .agent_based_api.v1 import *
from .agent_based_api.v1.render import bytes as render_bytes
from .agent_based_api.v1.type_defs import CheckResult, DiscoveryResult
import pprint
def discover_mikrotik_queuetree(section):
pprint.pprint(section)
for id, QueueTreeName, QueueTreeBytes, QueueTreePackets, QueueTreeDropped in section:
yield Service(item=QueueTreeName)
# def check_mikrotik_queuetree(item, section) -> CheckResult:
def check_mikrotik_queuetree(item, section):
for id, QueueTreeName, QueueTreeBytes, QueueTreePackets, QueueTreeDropped in section:
if QueueTreeName == item:
QueueTreeBytes = int(QueueTreeBytes) # convert string to int
QueueTreePackets = int(QueueTreePackets) # convert string to int
QueueTreeDropped = int(QueueTreeDropped) # convert string to int
print(item, ": ", QueueTreeBytes, "Bytes, ", QueueTreePackets, "Packets, ", QueueTreeDropped, "Drops")
yield Metric(
"queue_bps",
QueueTreeBytes,
boundaries=(0, None))
yield Metric(
"queue_pkts",
QueueTreePackets,
boundaries=(0, None))
yield Metric(
"queue_drops",
QueueTreeDropped,
levels=(None, 1),
boundaries=(0, None))
yield Result(
state = State.OK,
notice = f"{QueueTreeDropped} dropped Packets"
)
return
register.snmp_section(
name = "mikrotik_queuetree",
detect = matches(".1.3.6.1.2.1.1.1.0","RouterOS RB4011iGS\+"),
fetch = SNMPTree(
base = '.1.3.6.1.4.1.14988.1.1.2.2.1', # mtxrQueueTreeEntry
oids = [
OIDEnd(),
'2', # mtxrQueueTreeName
'5', # mtxrQueueTreeBytes
'6', # mtxrQueueTreePackets
'9', # mtxrQueueTreeDropped
],
),
)
register.check_plugin(
name="mikrotik_queuetree",
service_name="Queue %s",
discovery_function=discover_mikrotik_queuetree,
check_function=check_mikrotik_queuetree,
)
And here is my metrics file:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from cmk.gui.i18n import _
from cmk.gui.plugins.metrics import metric_info
#.
# .--Metrics-------------------------------------------------------------.
# | __ __ _ _ |
# | | \/ | ___| |_ _ __(_) ___ ___ |
# | | |\/| |/ _ \ __| '__| |/ __/ __| |
# | | | | | __/ |_| | | | (__\__ \ |
# | |_| |_|\___|\__|_| |_|\___|___/ |
# | |
# +----------------------------------------------------------------------+
# | Definitions of metrics |
# '----------------------------------------------------------------------'
metric_info["queue_bps"] = {
"title": _("Queue bandwidth"),
"unit": "bits/s",
"color": "#00e060",
}
metric_info["queue_pkts"] = {
"title": _("Queue Packets"),
"unit": "1/s",
"color": "#00e060",
}
metric_info["queue_drops"] = {
"title": _("Queue Drops"),
"unit": "1/s",
"color": "#00e060",
}