how to see CPU usage consumption of a particular service

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
rnjie
Posts: 157
Joined: Wed Mar 20, 2019 4:59 pm

how to see CPU usage consumption of a particular service

Post 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.
User avatar
pbroste
Posts: 1288
Joined: Tue Jun 01, 2021 1:27 pm

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

Post 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
gsmith
Posts: 1253
Joined: Tue Mar 02, 2021 11:15 am

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

Post 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
Locked