What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Custom sensor to monitor the CPU process

Votes:

0

Hello,

I have created a custom sensor to monitor the CPU process. It is running fine on CentOS 6.x however on CentOS Linux release 7.4.1708 (Core) we are seeing errors like: 0 % (Idle Percent) is below the error limit of 5 % in Idle Percent

If I go and refresh it manually it is working. The code is given below:

+++++++++++++++++++++++++++++++++++++++++++++++++++++++
#!/bin/bash
cpuinfo="/usr/bin/top"

xmlresult=`cat <<EOF
<?xml version="1.0" encoding='UTF-8'?>
<prtg>
EOF
`
if [ -f $cpuinfo ]; then
  result=`/usr/bin/top -b -n 1 | grep 'Cpu(s)'`
if [[ $result == %Cpu* ]]; then
 user=`echo $result | awk '{print $2}'| awk '{print int($0)}'`
 system=`echo $result | awk '{print $4}'| awk '{print int($0)}'`
 nice=`echo $result | awk '{print $6}'| awk '{print int($0)}'`
 idle=`echo $result | awk '{print $8}'| awk '{print int($0)}'`
 wait=`echo $result | awk '{print $10}'| awk '{print int($0)}'`
fi
  xmlresult=$xmlresult`cat <<EOF
  <result>
    <channel>User Percent</channel>
    <float>1</float>
    <unit>Percent</unit>
    <value>$user</value>
  </result>
EOF
`
  xmlresult=$xmlresult`cat <<EOF

  <result>
    <channel>System Percent</channel>
    <float>1</float>
    <unit>Percent</unit>
    <value>$system</value>
  </result>
EOF
`
  xmlresult=$xmlresult`cat <<EOF
  <result>
    <channel>Nice Percent</channel>
    <float>1</float>
    <unit>Percent</unit>
    <value>$nice</value>
  </result>
EOF
`
  xmlresult=$xmlresult`cat <<EOF
  <result>
    <channel>Idle Percent</channel>
    <float>1</float>
    <unit>Percent</unit>
    <value>$idle</value>
    <LimitMinWarning>10</LimitMinWarning>
    <LimitMinError>5</LimitMinError>
    <LimitMode>1</LimitMode>
  </result>
EOF
`
  xmlresult=$xmlresult`cat <<EOF
  <result>
    <channel>Wait Percent</channel>
    <float>1</float>
    <unit>Percent</unit>
    <value>$wait</value>
  </result>
EOF
`
  xmlresult=$xmlresult`cat <<EOF

  <text>OK</text>
</prtg>
EOF
`
else
  xmlresult=$xmlresult`cat <<EOF
  <error>1</error>
  <text>This sensor is not supported by your system, missing $cpuinfo</text>
</prtg>
EOF
`
fi
echo "$xmlresult"
exit 0
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Please let me know what is wrong??

cpu-load custom-sensor load-average

Created on Nov 29, 2017 11:18:12 AM

Last change on Nov 30, 2017 12:35:57 PM by  Stephan Linke [Paessler Support]



Best Answer

Accepted Answer

Votes:

1

Hello,

I think I found the issue it's because of the command awk '{print int($0)}':

[root@test~]# /usr/bin/top -b -n 1 | grep 'Cpu(s)'
%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
[root@test~]#  /usr/bin/top -b -n 1 | grep 'Cpu(s)'| awk '{print $8}'| awk '{print int($0)}'
0
[root@SLYNLUBAOS01 ~]# /usr/bin/top -b -n 1 | grep 'Cpu(s)'
%Cpu(s):  0.0 us,  3.1 sy,  0.0 ni, 96.9 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
[root@SLYNLUBAOS01 ~]#  /usr/bin/top -b -n 1 | grep 'Cpu(s)'| awk '{print $8}'| awk '{print int($0)}'
96

If the idle goes 100.0 its taking the value as 0 that's why we are getting the alerts.

Created on Nov 30, 2017 12:22:06 PM

Last change on Nov 30, 2017 12:35:37 PM by  Stephan Linke [Paessler Support]



3 Replies

Votes:

0

You have these two entries for the Idle Percentage.

<LimitMinWarning>10</LimitMinWarning> <LimitMinError>5</LimitMinError>

They are establishing lower thresholds. So when it hits 0, it's triggering the Error threshold.

Created on Nov 29, 2017 11:38:15 PM by  Benjamin Day [Paessler Support] (1,441) 2 1



Votes:

0

Hello,

Yes, these limits are perfectly working on CentOS 6.x but I am not sure why we are getting issues with CentOS 7.x servers.

Thanks

Created on Nov 30, 2017 11:58:01 AM



Accepted Answer

Votes:

1

Hello,

I think I found the issue it's because of the command awk '{print int($0)}':

[root@test~]# /usr/bin/top -b -n 1 | grep 'Cpu(s)'
%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
[root@test~]#  /usr/bin/top -b -n 1 | grep 'Cpu(s)'| awk '{print $8}'| awk '{print int($0)}'
0
[root@SLYNLUBAOS01 ~]# /usr/bin/top -b -n 1 | grep 'Cpu(s)'
%Cpu(s):  0.0 us,  3.1 sy,  0.0 ni, 96.9 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
[root@SLYNLUBAOS01 ~]#  /usr/bin/top -b -n 1 | grep 'Cpu(s)'| awk '{print $8}'| awk '{print int($0)}'
96

If the idle goes 100.0 its taking the value as 0 that's why we are getting the alerts.

Created on Nov 30, 2017 12:22:06 PM

Last change on Nov 30, 2017 12:35:37 PM by  Stephan Linke [Paessler Support]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.