How does NCPA calculate the percentage of cpu and its cores?
Output NCPA: OK: Percent was 10.00 %, 14.00 %, 12.50 %, 29.40 %
Because with different value is obtained when we consult the proc/stat whit this command:
awk '$1~/cpu[0-9]/{usage=($2+$4)*100/($2+$4+$5); print $1": "usage"%"}' /proc/stat
Output command:
[root@MXAP-ITOCZCCS01 plugins]# awk '$1~/cpu[0-9]/{usage=($2+$4)*100/($2+$4+$5); print $1": "usage"%"}' /proc/stat
cpu0: 16.4363%
cpu1: 17.9964%
cpu2: 17.5832%
cpu3: 16.7218%
Regards
How does NCPA calculate the percentage of cpu?
-
ingenieria.itoc
- Posts: 10
- Joined: Mon Oct 10, 2016 1:46 pm
How does NCPA calculate the percentage of cpu?
Last edited by ingenieria.itoc on Thu Aug 02, 2018 12:38 pm, edited 1 time in total.
Re: How does NCPA calculate the percentage of cpu?
There is no way to change the output of the plugin the way you want it to be, unless you come up with some kind of wrapper script that would do it.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: How does NCPA calculate the percentage of cpu?
You could raise a GitHub issue for this functionality. It's totally doable:
https://github.com/NagiosEnterprises/ncpa/issues
More info:
https://github.com/NagiosEnterprises/nc ... #L124-L130
https://psutil.readthedocs.io/en/latest ... pu_percent
https://psutil.readthedocs.io/en/latest ... .cpu_times
It's worth mentioning that running a plugin's output through sed / awk needs to be done with care because this by itself can strip out the exit code.
https://github.com/NagiosEnterprises/ncpa/issues
More info:
https://github.com/NagiosEnterprises/nc ... #L124-L130
https://psutil.readthedocs.io/en/latest ... pu_percent
https://psutil.readthedocs.io/en/latest ... .cpu_times
Based on my reading of the implementation, your assumption is correct that the first value is cpu0, second cpu1, third cpu2, etc etc.When percpu is True return a list of named tuples for each logical CPU on the system. First element of the list refers to first CPU, second element to second CPU and so on.
It's worth mentioning that running a plugin's output through sed / awk needs to be done with care because this by itself can strip out the exit code.
Former Nagios employee
https://www.mcapra.com/
https://www.mcapra.com/
-
ingenieria.itoc
- Posts: 10
- Joined: Mon Oct 10, 2016 1:46 pm
Re: How does NCPA calculate the percentage of cpu?
Tnks for answer me
But I still have doubt
I found other commands, but all of them give me different outputs:
grep -Ei "cpu\s+" </proc/stat ; sleep 1 ; grep -Ei "cpu\s+" </proc/stat
top -b -n1 | grep "Cpu(s)" | awk '{print $2 + $4}'
top -b -n2 -d 1 | awk "/^top/{i++}i--2" | grep -Ei "cpu\(s\)\s*:"
cat <(grep 'cpu ' /proc/stat) <(sleep 1 && grep 'cpu ' /proc/stat) | awk -v RS="" '{print ($13-$2+$15-$4)*100/($13-$2+$15-$4+$16-$5)}'[/list]
What is the best options for monitoring the cpu cores in percent ?
How konw if NCPA is the best practice for cpu cores?
Regards
But I still have doubt
I found other commands, but all of them give me different outputs:
grep -Ei "cpu\s+" </proc/stat ; sleep 1 ; grep -Ei "cpu\s+" </proc/stat
top -b -n1 | grep "Cpu(s)" | awk '{print $2 + $4}'
top -b -n2 -d 1 | awk "/^top/{i++}i--2" | grep -Ei "cpu\(s\)\s*:"
cat <(grep 'cpu ' /proc/stat) <(sleep 1 && grep 'cpu ' /proc/stat) | awk -v RS="" '{print ($13-$2+$15-$4)*100/($13-$2+$15-$4+$16-$5)}'[/list]
What is the best options for monitoring the cpu cores in percent ?
How konw if NCPA is the best practice for cpu cores?
Regards
Re: How does NCPA calculate the percentage of cpu?
It's hard to say what is "the best option" for monitoring the cpu cores in percent... The "supported" way is using NCPA, however you are free to use a shell script if you wish. Nagios gives you a flexibility to do the same thing in many different ways. It is a user's choice.
Be sure to check out our Knowledgebase for helpful articles and solutions!
- rexconsulting
- Posts: 60
- Joined: Fri May 04, 2012 4:27 pm
- Location: Oakland, CA
- Contact:
Re: How does NCPA calculate the percentage of cpu?
Note for /proc/stat, "All of the numbers reported in this file are aggregates since the system first booted" (http://www.linuxhowtos.org/System/procstat.htm).
Whereas /usr/local/nagios/libexec/check_ncpa.py seems to be a real-time sampling of each CPU. But then that does beg the question: a CPU average must be an average of utilization over some span of time, right? So what is the span of time that check_ncpa, or rather the ncpa_listener returns when queried by the check_ncpa?
Well I guess I could go read the code couldn't I?
Whereas /usr/local/nagios/libexec/check_ncpa.py seems to be a real-time sampling of each CPU. But then that does beg the question: a CPU average must be an average of utilization over some span of time, right? So what is the span of time that check_ncpa, or rather the ncpa_listener returns when queried by the check_ncpa?
Well I guess I could go read the code couldn't I?
CP
--
Chris Paul
Rex Consulting, Inc
5652 Florence Terrace, Oakland, CA 94611
email: [email protected]
web: http://www.rexconsulting.net
phone, toll-free: +1 (888) 403-8996 ext 1
--
Chris Paul
Rex Consulting, Inc
5652 Florence Terrace, Oakland, CA 94611
email: [email protected]
web: http://www.rexconsulting.net
phone, toll-free: +1 (888) 403-8996 ext 1
Re: How does NCPA calculate the percentage of cpu?
0.5 secSo what is the span of time that check_ncpa, or rather the ncpa_listener returns when queried by the check_ncpa?
Be sure to check out our Knowledgebase for helpful articles and solutions!
- rexconsulting
- Posts: 60
- Joined: Fri May 04, 2012 4:27 pm
- Location: Oakland, CA
- Contact:
Re: How does NCPA calculate the percentage of cpu?
Thanks lmiltchev
CP
--
Chris Paul
Rex Consulting, Inc
5652 Florence Terrace, Oakland, CA 94611
email: [email protected]
web: http://www.rexconsulting.net
phone, toll-free: +1 (888) 403-8996 ext 1
--
Chris Paul
Rex Consulting, Inc
5652 Florence Terrace, Oakland, CA 94611
email: [email protected]
web: http://www.rexconsulting.net
phone, toll-free: +1 (888) 403-8996 ext 1
Re: How does NCPA calculate the percentage of cpu?
You are welcome!
Be sure to check out our Knowledgebase for helpful articles and solutions!