Transforms - Nice Memory Events

From Zenoss Wiki
This is the approved revision of this page, as well as being the most recent.
Jump to: navigation, search

This provides a nice percentage utilization with raw amount free.

Event Class: Perf > Memory

# Converts memory events into percentage with raw values
import time, re, logging
 
match = re.search('threshold of .*(swap|memory).* (exceeded|restored|not met): current value ([\d\.]+)', evt.message, re.I)
if match and device:
    available = float(match.groups()[2])
    total = device.hw.totalMemory
    evt.component = "Memory"
    if match.groups()[0].lower() == "swap":
        total = device.os.totalSwap
        evt.component = "Swap"
    evt.memoryavailable = available
    evt.total = total
    if total:
        percent_free = (available / total) * 100
        percent_used = ((total - available) / total) * 100
        evt.summary = "High Memory Utilization: Currently %3.0f%% used (%3.0f%% free)" % (percent_used, percent_free)
        evt.message = evt.summary
    else:
        evt.summary = 'High Memory Utilization: Currently: %s' %(convToUnits(available))
        evt.message = evt.summary
 
sum=evt.summary
if (sum.find("cbsModuleFreePageAvailableNorm") >= 0):
  sum=re.sub ("cbsModuleFreePageAvailableNorm", "cbsModuleFreePageAvailableHigh", sum)
  evt.summary=sum
  evt.message = evt.summary
  evt._action="history"