Page 1 of 1

How to add process info (like from top) in cpu alert email?

Posted: Tue May 17, 2016 5:34 pm
by mlangkau
Is there a way to add the output from the "top" command to an email alert? We currently use nrpe to monitor Linux systems.

For example, when cpu or load crosses a threshold, I would like to include the output of something like this:

top -cSbn 1 | head -14 | tail -8

...and the resulting output looks like this:

Code: Select all

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
17294 apache    20   0  515m  84m 8768 R 100.0  2.2   4:13.14 /usr/sbin/httpd
29665 nagios    20   0 51656 3168 1036 S  2.0  0.1  17:21.22 /usr/local/nagios/bin/ndo2db -c /usr/local/nagios/etc/ndo2db.cfg
31175 nagios    20   0 15164 1188  816 R  2.0  0.0   0:00.01 top -cSbn 1
    1 root      20   0 19364 1028  820 S  0.0  0.0  12797:05 /sbin/init
    2 root      20   0     0    0    0 S  0.0  0.0   0:00.01 [kthreadd]
    3 root      RT   0     0    0    0 S  0.0  0.0  19:43.57 [migration/0]
    4 root      20   0     0    0    0 S  0.0  0.0   4:26.39 [ksoftirqd/0]
Thanks

Re: How to add process info (like from top) in cpu alert ema

Posted: Wed May 18, 2016 11:18 am
by bwallace
This is not possible, as the only info that one can feasibly have in a notification is data which the plugin itself actually gathered - you can't get it to run top or any other utility and then have the output written to your email. Maybe this doc will assist with your effort to further customize notifications, but understand that it won't assist with what you're specifically asking here.
https://assets.nagios.com/downloads/nag ... iables.pdf

Hope this helps, but let us know if there are any other questions, thanks.

Re: How to add process info (like from top) in cpu alert ema

Posted: Wed May 18, 2016 12:10 pm
by mlangkau
Got it. I wasn't sure if an event handler could be used to get the info, but getting it into the email isn't possible. If I understand correctly, I'll need to clone and edit the plugin to include the additional information we are looking for.

Does anyone know if a cpu/memory stats plugin already exists that provides top process information?

Thanks!

Re: How to add process info (like from top) in cpu alert ema

Posted: Wed May 18, 2016 4:58 pm
by tgriep
Does this plugin look like what you are looking for?
https://exchange.nagios.org/directory/P ... rs/details

Re: How to add process info (like from top) in cpu alert ema

Posted: Wed May 18, 2016 5:10 pm
by mlangkau
That sounds like a winner - I'll check it out.

Thanks!

Re: How to add process info (like from top) in cpu alert ema

Posted: Wed May 18, 2016 6:12 pm
by mlangkau
Yes, this works. Thanks again!