TECHZEN Zenoss User Community ARCHIVE  

Trouble with Calculated Performance Expression development for CPU Util AND CPU ...

Subject: Trouble with Calculated Performance Expression development for CPU Util AND CPU Load Monitoring
Author: [Not Specified]
Posted: 2014-10-20 12:23

I am running zenoss 4.2.4 on centOS 6.5 in a lab environment. I found the default Linux Zenpack and the improved Linux ZenPack to be insufficient to satisfy my requirements. Those requirements are that Zenoss only generates a CPU usage alert when both utilization and load are pegged on a particular device. This means I can't have an alert come in for high util and then have another alert once load hits as well. There should only be one alert correlating both thresholds. After discussing that with cluther and trelane on the zenoss IRC during dev hours we came up with the following expression to be used in a Calculated Performance ZenPack.

# Provided by cluther, notice it is not dynamic to number of cpu cores, but I tried it anyway and got an error event regarding the expression in Zenoss
avg((cpu_load / 10.0), (cpu_util / 99.0))

# I changed this to the following, and got a nice error event from zenoss explaining that the avg function doesn't support multiple arguments. After checking the utils.py code in the CP zp I found this to be absolutely true. It expects a dpList argument.
avg[(laLoadInt5 / here.hw.cpus.countObjects()), ((TotalCpuUsage / here.hw.cpus.countObjects()) / 99.0)]

# So I thought okay I will create a list and give avg the argument it expects. Not so fast Python eval() apparently doesn't support assignments. So yeah this also failed.
dplist=[(laLoadInt5 / here.hw.cpus.countObjects()), ((TotalCpuUsage / here.hw.cpus.countObjects()) / 99.0)]
avg(dplist)

# After looking closely at the avg function code in utils.py I saw it just divides the total against the length as you might expect. That's pretty easy right, so I can just do it myself..........Nope. I even took out the len function to simplify and just divided by two as I knew it did not need to be dynamic in this case. In other words I couldn't think of a case where I was going to have more arguments than cpu util and cpu load.
(laLoadInt5 / here.hw.cpus.countObjects()) + ((TotalCpuUsage / here.hw.cpus.countObjects()) / 99.0) / 2

# Here is the final error.
Expression for hostname_:CpuUtilAndLoad ((laLoadInt5 / here.hw.cpus.countObjects()) + ((TotalCpuUsage / here.hw.cpus.countObjects()) / 99.0) / 2) failed: 'list' object is not callable

# I didn't see any lists in my expression , but I googled the "'list' object is not callable" anyway. Here is what I found. Basically a bunch of smart python people agreeing that I used parens to call my list(s) when I should have used brackets.
http://stackoverflow.com/questions/5735841/python-typeerror-list-object-...

That seems reasonable, but I don't see a list in my expression, maybe you do, but then I noticed that Zenoss actually wrapped my expression in parens in the error event that was generated. It got me to thinking maybe the CP zp code actually treats the expressions as lists but then calls it with parens instead of brackets. I don't know if that is true, but I think I could definitely use some help at this point. I have spent many hours on this one without being able to find a solution, so as to not waste anyones time but my own. I am hoping the zenoss community can point me in the right direction. Specifically, what is wrong with my expression Is there a better way to build a robust cpu monitor that meets the above mentioned requirements Finally I did plug my python expression in to the python evaluator at the link below and I was able to get it to work, but not within an eval() even after trying many of the previously mentioned variations including using the avg function by taking the code from utils.py in the cp zp and then calling it with the expression provided by cluther.

http://pyeval.appspot.com/index.htmlid=aghzfnB5ZXZhbHIUCxILQ29tcHV0ZUNl...



Subject: Calculated Performance utils.py avg function
Author: [Not Specified]
Posted: 2014-10-21 11:45

I referred to this several times, but here is the actual CP avg function. Note that it only takes one argument.

def avg(dpList):
"""
Average a list of datapoints. A list with no non-None items has an average of zero.
"""
if not dpList:
return 0.0

dpList = [x for x in dpList if x is not None]
if not dpList:
return 0.0

return sum(dpList) / len(dpList)



Subject: I guess you can use 'hw.cpus
Author: [Not Specified]
Posted: 2015-11-29 17:36

I guess you can use 'hw.cpus.countObjects[0]' to get number of CPUs in the expression



< Previous
how to upgrade control center(serviced)
  Next
Network Device graphs stops and starts every 6 hours
>