Page 1 of 1

how to see CPU usage consumption of a particular service

Posted: Fri Jan 14, 2022 3:34 pm
by rnjie
i have fireeye installed on all my linux machines and we monitore the service (xagt) on nagios with no issue. Recently we noticed this service uses alot of CPU which has caused some problems so i was wondering if there is a way to monitor the cpu used by this service and get an alert? We are already monitoring general CPU of course but it does not tell which service causes it to rise.

Re: how to see CPU usage consumption of a particular service

Posted: Mon Jan 17, 2022 5:13 pm
by pbroste
Hello @rnjie

Thanks for reaching out, to do this you want to create a plugin script, and here is an example to edit from:
#!/bin/bash
used_cpu=`ps -C xagt -o %cpu`
case $used_cpu in
[1-84]*)
echo "OK - $used_cpu% CPU used."
exit 0
;;
[85]*)
echo "WARNING - $used_cpu% CPU used."
exit 1
;;
[86-100]*)
echo "CRITICAL - $used_cpu% CPU used."
exit 2
;;
*)
echo "UNKNOWN - $used_cpu% CPU used."
exit 3.............etc....
Thanks,
Perry

Re: how to see CPU usage consumption of a particular service

Posted: Mon Jan 17, 2022 5:23 pm
by gsmith
Hi

Here's some more information

You could create a custom plugin as a shell script, something like:

Code: Select all

#!/bin/sh
mypid=`pidof $1`
ps -p $mypid -o %cpu
If the above script was called proc_cpu.sh you could get the cpu % used by mysqld by running

Code: Select all

./proc_cpu mysqld
You would have to format the output so it matches the standard plugin output format.

Here are some docs on plugins:
https://assets.nagios.com/downloads/nag ... ugins.html
https://assets.nagios.com/downloads/nag ... inapi.html

Once you have the plugin created you can run it on a remote system using NCPA:
https://www.nagios.org/ncpa/help.php?v= ... the-plugin
https://support.nagios.com/kb/article/n ... a-722.html

Thanks