I haven't done search on google.
1st browsing check on https://exchange.nagios.org/directory/P ... e-and-Load does not list the script I need.
Is there a script that can do this ?
If CPU load is over threshold then display the top couple CPU loaded processes.
The goal is to show processes occasionally ran and causing cpu load to spike up.
Thanks for the pointer.
script to show top processes of high CPU load
script to show top processes of high CPU load
Last edited by nagmoto on Sat Jan 30, 2016 3:46 am, edited 2 times in total.
Re: script to show top processes of high CPU load
I don't know of one off the top of my head, but it wouldn't be hard to script in bash.
Use this sort of logic:
If cpu usage is under a certain threshold, echo the message "CPU Usage OK."
If cpu usage is not okay, echo the top process from a top command.
Something like this could get you that information:
It's not the prettiest, but I hope it gives you an idea.
Use this sort of logic:
If cpu usage is under a certain threshold, echo the message "CPU Usage OK."
If cpu usage is not okay, echo the top process from a top command.
Something like this could get you that information:
Code: Select all
top | head -n10 | tail -n3 | awk '{print $10 " " $11 " " $13}' Former Nagios Employee.
me.
me.
Re: script to show top processes of high CPU load
I wrote a couple lines to do this a while back, while it's not pretty, and I wouldn't call it a script - it will do what you're looking for. You'll want to set up an event_handler which will trigger this each time a state change occurs on the cpu check. The file it logs to is C:\Program Files\NSClient++\scripts\powershell\topcpu.txt.
I call it... topcpu.ps1!
Add this under your external scripts configuration -
If you're looking for linux, here's a bash script that will log to checktopcpu.txt in the same directory -
I call it... topcpu.ps1!
Code: Select all
date | Out-File "C:\Program Files\NSClient++\scripts\powershell\topcpu.txt" -append
Get-Process | Sort WS | Select -last 10 | Out-File "C:\Program Files\NSClient++\scripts\powershell\topcpu.txt" -append
Code: Select all
;topcpu external script
topcpu = cmd /c echo scripts\powershell\topcpu.ps1; exit(0) | powershell.exe -command -
Code: Select all
#!/bin/bash
date=$(date)
echo -e "$date" >> checktopcpu.txt
ps -eo pcpu,args --sort=-%cpu|head >> checktopcpu.txt
echo -e "\n" >> checktopcpu.txt
Former Nagios Employee
Re: script to show top processes of high CPU load
[quote="rkennedy"]I wrote a couple lines to do this a while back, while it's not pretty, and I wouldn't call it a script - it will do what you're looking for. You'll want to set up an event_handler which will trigger this each time a state change occurs on the cpu check. The file it logs to is C:\Program Files\NSClient++\scripts\powershell\topcpu.txt.
I had to read this post to understand how to execute the topcpu script on remote machine via NRPE.
https://blog.karssen.org/2010/09/14/nag ... -machines/
I had to read this post to understand how to execute the topcpu script on remote machine via NRPE.
https://blog.karssen.org/2010/09/14/nag ... -machines/
Re: script to show top processes of high CPU load
Ah - I didn't write much instructions as I didn't know if you needed them or not.
Are you using windows or linux? Using the guide posted, were you able to get this working?
Are you using windows or linux? Using the guide posted, were you able to get this working?
Former Nagios Employee
Re: script to show top processes of high CPU load
I have both windows and Unix clients. I will test this approach in my test lab first.rkennedy wrote:Ah - I didn't write much instructions as I didn't know if you needed them or not.
Are you using windows or linux? Using the guide posted, were you able to get this working?
Also I am thinking of inserting the login of picking out top process into following script
https://github.com/shamil/nagios-plugin ... eck_cpu.sh
This ticket can be closed, I just need to pick the approach with less impact.
Thanks again.
Re: script to show top processes of high CPU load
Sounds good! Glad to see this will work out for you.
I'll close this out now, but feel free to open a new thread if you ever need assistance in the future!
I'll close this out now, but feel free to open a new thread if you ever need assistance in the future!
Former Nagios Employee