I am trying to build a perfometer which shows me metric value as well as changes color based on the service state, I found some code which i think i can implement (check_mk/web/plugins/perfometer/check_mk.py at master · v-a/check_mk · GitHub)
As shown in the code (link mentioned above), There are three parameters given row, check_command, and perf_data. I have also prepared a similar function. But i want to debug and want to know that what data is there in these variables, right now i’m blindly fetching it as per the mentioned in page up comment of the mentioned code, but want to learn more about the structure. Can someone help me with debugging this perfometer file.
As even we are not importing anything, makes me curious that how function/changes made in this file is taken into consideration.
Here is the code i’m using, In comments you can see the successfull implementation of perfometers, but in un-commented code, it is mentioned the thing i want to achieve.
from cmk.gui.plugins.metrics import perfometer_info
# perfometer_info.append(
# {
# "type": "linear",
# "segments": ["BarsGenBin_latency"],
# "total": 100.0,
# }
# )
# perfometer_info.append(
# {
# "type": "linear",
# "segments": ["QuotesBin_latency"],
# "total": 100.0,
# }
# )
# perfometer_info.append(
# {
# "type": "linear",
# "segments": ["TradesBin_latency"],
# "total": 100.0,
# }
# )
def perfometer_check_mk(row, check_command, perf_data):
varname, value, unit, warn, crit, minival, threshold = perf_data[0]
value = float(value)
threshold = float(threshold)
if warn != "" or crit != "":
warn = int(warn)
crit = int(crit)
# go red if we're over crit
if value > crit:
color = "#f44"
# yellow
elif value > warn:
color = "#f84"
else:
# all green lights
color = "#2d3"
else:
# use a brown-ish color if we have no levels.
# otherwise it could be "green" all the way to 100%
color = "#f4a460"
return "%.0f%%" % (value), perfometer_linear(value, color)
perfometer['TradesBin_latency'] = perfometer_check_mk