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

Bash does not return values on my PRTG script

Votes:

0

Hi Forum,

I have the below written script that I would like to return values on PRTG, I can successfully display some values, however some don't display because they are not integers I guess.

#!/bin/bash
app_name="ListenerService" #App Name

app_id=`ps aux | grep $app_name | grep -v grep | awk {'print $2'}`  #Process ID
app_cpu=`ps aux | grep $app_name | grep -v grep | awk {'print $3'}` #CPU% Used
app_mem=`ps aux | grep $app_name | grep -v grep | awk {'print $4'}` #MEM% Used
app_res=`ps aux | grep $app_name | grep -v grep | awk {'print $5'}` #RES is the amount of RAM currently used by the process
app_virt=`ps aux | grep $app_name | grep -v grep | awk {'print $6'}` #VIRT is the full size of all memory the process is using
app_shar=`ps aux | grep $app_name | grep -v grep | awk {'print $7'}` #SHR, Shared Mem size (kb) The amount of shared memory used by a task

app_stat=`ps -q $app_id -o state --no-headers` #Process status 
app_threads=`sudo cat /proc/$app_id/status | grep Threads | grep -v grep | awk {'print $2'}` # Process thread count

#Check if the process is still alive and running
if [ "$app_stat" != "D" ] && [ "$app_stat" != "Z" ] && [ "$app_stat" != "X" ]
then
  app_stat="UP"
else
  app_stat="DOWN"
fi

#PRTG Sensor Output
result="<?xml version='1.0' encoding='Windows-1252' ?>\n"
result+="<prtg>\n"
result+="   \t<result>\n"
result+="   	\t\t<channel>CPU Usage %</channel>\n"
result+="   	\t\t<value>${app_cpu}</value>\n"
result+="   	\t\t<unit>custom</unit>\n"
result+="   	\t\t<customunit>%</customunit>\n"
result+="	\t</result>\n"
result+="   \t<result>\n"
result+="   	\t\t<channel>Memory %</channel>\n"
result+="   	\t\t<value>${app_mem}</value>\n"
result+="   	\t\t<unit>custom</unit>\n"
result+="   	\t\t<customunit>%</customunit>\n"
result+="   \t</result>\n"
result+="   \t<result>\n"
result+="   	\t\t<channel>Threads</channel>\n"
result+="   	\t\t<value>${app_threads}</value>\n"
result+="   	\t\t<unit>custom</unit>\n"
result+="   	\t\t<customunit>#</customunit>\n"
result+="   \t</result>\n"
result+="   \t<result>\n"
result+="       \t\t<channel>RES(RAM currently in use)</channel>\n"
result+="       \t\t<value>${app_res}</value>\n"
result+="       \t\t<unit>custom</unit>\n"
result+="       \t\t<customunit>KiB</customunit>\n"
result+="   \t</result>\n"
result+="   \t<result>\n"
result+="       \t\t<channel>VIRT(Virtual Memory Size)</channel>\n"
result+="       \t\t<value>${app_virt}</value>\n"
result+="       \t\t<unit>custom</unit>\n"
result+="       \t\t<customunit>KiB</customunit>\n"
result+="   \t</result>\n"
result+="   \t<result>\n"
result+="   	\t\t<channel>Status</channel>\n"
result+="   	\t\t<value>${app_stat}</value>\n"
result+="   	\t\t<unit>custom</unit>\n"
result+="   	\t\t<customunit></customunit>\n"
result+="   \t</result>\n"
result+="</prtg>\n"

echo -e $result

The values not displaying are app_cpu and app_mem. Am I doing something wrong on the bash script?

Looking forward to any help on the same.

advanced custom-sensor linux prtg snmp

Created on May 24, 2021 2:05:58 PM



2 Replies

Votes:

0

Hi Brian,

Make sure the <Float> setting matches the kind of value provided. With <Float> you can define if the value is a float. The default is 0 (no). If set to 1 (yes), use a dot as decimal separator in values. If you don't define this and your value is a float PRTG shows 0 as values.

This means the output should look like this:

<prtg>
           <result>
           <channel>channel</channel>
           <value>10.3</value>
           <float>1</float>
           </result>
</prtg>

Kind regards

Felix Wiesneth - Team Tech Support

Created on May 26, 2021 7:07:28 PM by  Felix Wiesneth [Paessler Support]



Votes:

0

Hi Felix,

Work perfectly now, thank you for the great help.

Created on May 28, 2021 6:47:31 AM




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.