OS Process Transform

6 posts / 0 new
Last post
Theboogwa
Theboogwa's picture
Offline
Last seen: 1 month 1 week ago
Joined: 03/31/2016 - 17:21
Posts: 15
OS Process Transform

Hello,

I'm trying to write my first transform and my goal is to do something similar to the Nice Memory Events example located here http://wiki.zenoss.org/Transforms_-_Nice_Memory_Events

We monitor how much memory a particular process is using and have an alarm when it reach a particular size. The event summary lists a big number that doesn't show any units and I just want to clean that up a bit. Does anyone one have a transform already built that handles this or know what values I need to use in my script?

Thanks in advance!

Theboogwa
Theboogwa's picture
Offline
Last seen: 1 month 1 week ago
Joined: 03/31/2016 - 17:21
Posts: 15
I'm guessing the memory value

I'm guessing the memory value that I'm looking for would be under device.os.processes (found in another post), but I don't know how to search those values. Once I get the memory value, I think I can use the convToUnits subroutine in the "Nice Memory Events" example. Am I heading the right direction?

Jcurry
Jcurry's picture
Offline
Last seen: 1 day 11 hours ago
Joined: 01/02/2014 - 13:04
Posts: 391
A device process does not

A device process does not have an attribute for the amount of memory that a process should use so you don't find anything helpful in OSProcess.py.  A device DOES have an attribute for it's total memory - it is under hw - device.hw.totalMemory .

The way I went about this was to first create a new event class, /Perf/Memory/Process to use in the threshold definition.  This event class will have a transform that prettifies the summary.

Next, pick a process on a device as a test - preferably one that uses a reasonable amount of memory.  Select the process from the device's OSProcesses list; change the Display dropdown from Graphs to Templates and click the "Create Local Copy" button - that way we can play around with the test process without mucking up anything else.

Now navigate to ADVANCED -> Monitoring Templates ->OSProcess and select the instance for the local copy you have just created.  Create a new threshold based on the mem_mem datapoint.

You can either set the maximum value to a fixed number or use an expression; fundamentally, this value is in BYTES.  I used an expression to limit max to to 1% of the total memory on the device.

here.device().hw.totalMemory * 0.01

Don't forget that this is a component template so the value "here" refers to an instance of an OSProcess on a device.  To get back to the device itself, we use the device() method; then get the hw.totalMemory attribute (I got some clues for this from the standard transform on /Perf/Snmp/availMemory). Once you have modified this template, no need to do anything else or restart anything - it is a component template so it binds automatically and will take effect automatically.

Next, configure a transform for the /Perf/Memory/Process event class - use the Action icon at the bottom-left of the selected event class panel to reach the Transform.  As you suggest, the Zenoss utility, convToUnits can be used to automatically scale your numbers.

import re
if device and evt.summary.startswith('threshold of') and evt.severity !=0:
    m = re.search("threshold of [^:]+: current value ([\d\.]+)", evt.summary)
    #JC - test whether re produced a result in m
    if m:
        currentusage = (float(m.groups()[0]))
        # JC - if action is drop, dont waste any more cycles
        if currentusage < 1: 
            evt._action='drop'
        else:
            convTotalMem = convToUnits(device.hw.totalMemory)
            convCurrentusage = convToUnits(currentusage)
            convDevMax = convToUnits(float(evt.max))
            evt.summary = "Process memory threshold exceeded: %s  used. Threshold is %s . Total memory on device is %s " % (convCurrentusage, convDevMax, convTotalMem  )

This produces an event with a modified summary:

"Process memory threshold exceeded: 141.0MB used. Threshold is 57.7MB . Total memory on device is 5.6GB".

Note that the threshold event - any threshold event with a Maximum set - has an event attribute, evt.max which is the  value of the threshold (whether it is a constant or an expression).  Also note that this max value is actually a string representation so the transform has to convert it to float before applying the convToUnits method.  The output of convToUnits is a string so, in the evt.summary line, the formatting has %s for the three variables to be substituted.

Hopefully, that gets you started!

Cheers,

Jane

 

 

Theboogwa
Theboogwa's picture
Offline
Last seen: 1 month 1 week ago
Joined: 03/31/2016 - 17:21
Posts: 15
Thanks a bunch Jane! This

Thanks a bunch Jane! This will work just fine for me. Also, a very detailed explanation of how to configure this on my end. Are you aware of anywhere I can read up on transforms, the attributes and values that can be used and where they live? I want to get better at this and willing to do some reading if I can get my hands on some material. Thanks again!

Jcurry
Jcurry's picture
Offline
Last seen: 1 day 11 hours ago
Joined: 01/02/2014 - 13:04
Posts: 391
Pull my Zenoss Event

Pull my Zenoss Event Management paper from  https://www.skills-1st.co.uk/papers/jane/zenoss4-events/  .

Cheers,

Jane

Theboogwa
Theboogwa's picture
Offline
Last seen: 1 month 1 week ago
Joined: 03/31/2016 - 17:21
Posts: 15
Thanks again!

Thanks again!

Log in to post comments