Difference between revisions of "Transforms - Nice Filesystem Events"

From Zenoss Wiki
Jump to: navigation, search
m
Line 1: Line 1:
 
Output provides a nice percentage with raw amount free.
 
Output provides a nice percentage with raw amount free.
  
 +
Event Class: Perf > Filesystem
 
<syntaxhighlight lang=python>
 
<syntaxhighlight lang=python>
 
# Converts file system events into a prettier message with percentage and raw values
 
# Converts file system events into a prettier message with percentage and raw values

Revision as of 17:41, 6 May 2014

Output provides a nice percentage with raw amount free.

Event Class: Perf > Filesystem

# Converts file system events into a prettier message with percentage and raw values
import time, re, logging
 
if device and evt.eventKey:
    for f in device.os.filesystems():
        if f.name() != evt.component and f.id != evt.component: continue
 
        # Extract the used blocks from the event's message
        import re
        m = re.search("threshold of [^:]+: current value ([\d\.]+)", evt.message)
        if not m: continue
 
        # Get the total blocks from the model. Adjust by specified offset.
        totalBlocks = f.totalBlocks * getattr(device, "zFileSystemSizeOffset", 1.0)
        if not totalBlocks: continue
        evt.totalBlocks = totalBlocks
        totalBytes = totalBlocks * f.blockSize
        usedBytes = None
 
        currentValue = float(m.groups()[0])
        evt.currentValue = currentValue
        if 'usedBlocks' in evt.eventKey:
            usedBytes = currentValue * f.blockSize
            evt.ifstatement = "usedBlocks in evt.eventKey"
        elif 'FreeMegabytes' in evt.eventKey:
            usedBytes = totalBytes - (currentValue * 1048576)
            evt.ifstatement = "usedBlocks = totalBytes - (current ..."
        elif 'availBlocks' in evt.eventKey:
            usedBytes = totalBytes - (currentValue * 1024)
        else:
            continue
        try:
            # Calculate the used percent and amount free.
            usedBlocks = float(m.groups()[0])
            evt.usedBlocks = usedBlocks
            p = (usedBytes / totalBytes) * 100
            evt.p = p
            from Products.ZenUtils.Utils import convToUnits
            free = convToUnits(totalBytes - usedBytes)
 
            # Make a nicer summary
            evt.summary = "High Disk Utilization: Currently %3.0f%% used (%s free)" % (p, free)
            evt.message = evt.summary
 
        except ZeroDivisionError, e:
            # Total size hasn't been calculated
            pass
 
        break