自訂 PRTG Sensor 設定

shell script example 2018/12/13 

all.sh (20240 20242 20244 20246)

 內容抓取以上資料夾的 ServiceIndicator2018????txt 的值( 0x1007 and 0x000b)

mlb.sh (IOTC_MLB) 

 內容抓取以上資料夾的 ServiceIndicator2018????txt 的值( 0x0001)

更新如下:

增加欄位<float></float> 

增加功能

分開值類別 0x1007 ,0x000b 分開

調整prtg選項

注意事項:

  • 每台伺服器log資訊tail會有點差異,需要重新設定,資料抓取才會正確。

all.sh

#!/bin/bash
DATE=`date +%Y%m%d`
#ServiceIndicator$DATE
Name="20240 20242 20244 20246"
echo "&lt;prtg>"
for Master in $Name
do
cd /root/log/$Master/
#!/bin/bash
DATE=`date +%Y%m%d`
#ServiceIndicator$DATE
 
    #drop
                mlb153=`tail  ServiceIndicator"$DATE".txt | grep 0x1007 |  cut -d , -f 15 | sed -n "2,1p"`
                mlb152=`tail  ServiceIndicator"$DATE".txt | grep 0x1007 |  cut -d , -f 15 | sed -n "1,1p"`
                mlbtotal15=`expr $mlb153 - $mlb152 `
                mlbtotal15_=`expr $mlb152 - $mlb153 `
function drop_statu {
                if [[ "$mlbtotal15" &lt; "$mlbtotal15_" ]]; then
                        echo -n "$mlbtotal15"      
                else
                        echo -n "$?"
                fi
}
    #received
                mlb133=`tail  ServiceIndicator"$DATE".txt | grep 0x1007 | cut -d , -f 13 | sed -n "2,1p"`
                mlb132=`tail  ServiceIndicator"$DATE".txt | grep 0x1007 | cut -d , -f 13 | sed -n "1,1p"`
                mlbtotal13=`expr $mlb133 - $mlb132 `
                mlbtotal131024=`expr $mlbtotal13 / 1024`
                mlbtotal13_=`expr $mlb132 - $mlb133 `
                mlbtotal131024_=`expr $mlbtotal13_ / 1024`
function received_statu {
                if [[ "$mlbtotal131024" &lt; "$mlbtotal131024_" ]]; then
                        echo -n "$mlbtotal131024"             
                else
                        echo -n "$?"              
                fi
}
    #queue
                #mlb143=`tail  ServiceIndicator"$DATE".txt | grep 0x1007 | cut -d , -f 14 | sed -n "2,1p"`
              #  echo "0:$((0x$mlb143)):ok"
        #amount)
                #mlb33=`grep "0x1007\|0x000b" ServiceIndicator20181210.txt|  cut -d , -f 3| tail -2`
                mlb43=`grep "0x1007" ServiceIndicator"$DATE".txt |  cut -d , -f 3| tail -1`
                mlb44=`grep "0x1007" ServiceIndicator"$DATE".txt |  cut -d , -f 4| tail -1`
                mlb43b=`grep "0x000b" ServiceIndicator"$DATE".txt |  cut -d , -f 3| tail -1`
                mlb44b=`grep "0x000b" ServiceIndicator"$DATE".txt |  cut -d , -f 4| tail -1`
                #count3=`tail  ServiceIndicator"$DATE".txt | grep "0x0003\|0x8003\|0x0011\|0x000b\|0x1007\|0x0009" | cut -d , -f 3 |  sed -n '4,12p'`
                #declare -i SUM=0
                #for i in $mlb33
        #do
                #        let SUM+=$i
                #done
echo -n "&lt;result>
       &lt;channel>"$Master" 0x1007 Request Number&lt;/channel>
         &lt;value>"$mlb43"&lt;/value>
    &lt;/result>"
echo -n "&lt;result>
       &lt;channel>"$Master" 0x1007 Respone Time&lt;/channel>
         &lt;value>"$mlb44"&lt;/value>
         &lt;float>1&lt;/float>
         &lt;DecimalMode>2&lt;/DecimalMode>
        &lt;/result>"
echo -n "&lt;result>
       &lt;channel>"$Master" 0x000b Request Number&lt;/channel>
         &lt;value>"$mlb43b"&lt;/value>
        &lt;/result>"
echo -n "&lt;result>
       &lt;channel>"$Master" 0x000b Respone Time&lt;/channel>
         &lt;value>"$mlb44b"&lt;/value>
     &lt;float>1&lt;/float>
         &lt;DecimalMode>2&lt;/DecimalMode>
        &lt;/result>"
 
echo -n  "&lt;result>
       &lt;channel>"$Master" 0x1007 RX_QUEUE&lt;/channel>
         &lt;value>"$((0x$mlb143))"&lt;/value>
    &lt;/result>"
echo -n "&lt;result>
       &lt;channel>"$Master" 0x1007 Received Bytes&lt;/channel>
        &lt;value>"
received_statu $mlbtotal131024
    echo "&lt;/value>
        &lt;/result>"
echo -n "&lt;result>
       &lt;channel>"$Master" 0x1007 Drop Count&lt;/channel>
        &lt;value>"
drop_statu $mlbtotal15
        echo "&lt;/value>
        &lt;/result>"
done
echo "&lt;/prtg>"

mlb.sh

#!/bin/bash
DATE=`date +%Y%m%d`
#ServiceIndicator$DATE
cd /root/IOTC_MLB/log
    #drop
                mlb153=`tail -n 2 ServiceIndicator"$DATE".txt |   cut -d , -f 15 | sed -n "2,1p"`
                mlb152=`tail -n 2 ServiceIndicator"$DATE".txt |   cut -d , -f 15 | sed -n "1,1p"`
                mlbtotal15=`expr $mlb153 - $mlb152 `
                mlbtotal15_=`expr $mlb152 - $mlb153 `
function drop_statu {
                if [[ "$mlbtotal15" &lt; "$mlbtotal15_" ]]; then
                        echo -n "$mlbtotal15"             
                else
                        echo -n "$?"              
                fi
}
    #received
                mlb133=`tail -n 2 ServiceIndicator"$DATE".txt |   cut -d , -f 13 | sed -n "2,1p"`
                mlb132=`tail -n 2 ServiceIndicator"$DATE".txt |   cut -d , -f 13 | sed -n "1,1p"`
                mlbtotal13=`expr $mlb133 - $mlb132 `
                mlbtotal131024=`expr $mlbtotal13 / 1024`
                mlbtotal13_=`expr $mlb132 - $mlb133 `
                mlbtotal131024_=`expr $mlbtotal13_ / 1024`
function received_statu {
                if [[ "$mlbtotal131024" &lt; "$mlbtotal131024_" ]]; then
                        echo -n "$mlbtotal131024"             
                else
                        echo -n "$?"              
                fi
}
    #queue
                mlb143=`tail -n 2 ServiceIndicator"$DATE".txt |  cut -d , -f 14 | sed -n "2,1p"`
              #  echo "0:$((0x$mlb143)):ok"
                 
        #amount)
                mlb33=`tail -n 2  ServiceIndicator"$DATE".txt | cut -d , -f 3| sed -n "2,1p"`
                mlb34=`tail -n 2  ServiceIndicator"$DATE".txt | cut -d , -f 4| sed -n "2,1p"`
                #count3=`tail  ServiceIndicator"$DATE".txt | grep "0x0003\|0x8003\|0x0011\|0x000b\|0x1007\|0x0009" | cut -d , -f 3 |  sed -n '4,12p'`
               # declare -i SUM=0
                #for i in $count3
                #do
                #        let SUM+=$i
                #done
               # echo "0:$count3:ok"
##############################################
echo "&lt;prtg>"
echo -n "&lt;result>
       &lt;channel>0x0001 Request Number&lt;/channel>
         &lt;value>"$mlb33"&lt;/value>
    &lt;/result>"
echo -n "&lt;result>
       &lt;channel>0x0001 Response Time &lt;/channel>
         &lt;value>"$mlb34"&lt;/value>
     &lt;float>1&lt;/float>
         &lt;DecimalMode>2&lt;/DecimalMode>
        &lt;/result>"
echo -n  "&lt;result>
       &lt;channel>0x0001 RX_QUEUE&lt;/channel>
         &lt;value>"$((0x$mlb143))"&lt;/value>
    &lt;/result>"
echo -n "&lt;result>
       &lt;channel>0x0001 Received Bytes&lt;/channel>
        &lt;value>"
received_statu $mlbtotal131024
    echo "&lt;/value>
        &lt;/result>"
echo -n "&lt;result>
       &lt;channel>0x0001 Drop Count&lt;/channel>
        &lt;value>"
drop_statu $mlbtotal15
        echo "&lt;/value>
        &lt;/result>"
echo "&lt;/prtg>"

shell script example 2018/12/05 

only all shell script

#!/bin/bash
DATE=`date +%Y%m%d`
#ServiceIndicator$DATE
Name="20240 20242 20244 20246"
echo "&lt;prtg>"
for Master in $Name
do
cd /root/log/$Master/
#!/bin/bash
DATE=`date +%Y%m%d`
#ServiceIndicator$DATE
 
    #drop
                mlb153=`tail  ServiceIndicator"$DATE".txt | grep 0x1007 |  cut -d , -f 15 | sed -n "2,1p"`
                mlb152=`tail  ServiceIndicator"$DATE".txt | grep 0x1007 |  cut -d , -f 15 | sed -n "1,1p"`
                mlbtotal15=`expr $mlb153 - $mlb152 `
                mlbtotal15_=`expr $mlb152 - $mlb153 `
function drop_statu {
                if [[ "$mlbtotal15" &lt; "$mlbtotal15_" ]]; then
                        echo -n "$mlbtotal15"      
                else
                        echo -n "$?"
                fi
}
    #received
                mlb133=`tail  ServiceIndicator"$DATE".txt | grep 0x1007 | cut -d , -f 13 | sed -n "2,1p"`
                mlb132=`tail  ServiceIndicator"$DATE".txt | grep 0x1007 | cut -d , -f 13 | sed -n "1,1p"`
                mlbtotal13=`expr $mlb133 - $mlb132 `
                mlbtotal131024=`expr $mlbtotal13 / 1024`
                mlbtotal13_=`expr $mlb132 - $mlb133 `
                mlbtotal131024_=`expr $mlbtotal13_ / 1024`
function received_statu {
                if [[ "$mlbtotal131024" &lt; "$mlbtotal131024_" ]]; then
                        echo -n "$mlbtotal131024"             
                else
                        echo -n "$?"              
                fi
}
    #queue
                mlb143=`tail  ServiceIndicator"$DATE".txt | grep 0x1007 | cut -d , -f 14 | sed -n "2,1p"`
              #  echo "0:$((0x$mlb143)):ok"
                 
        #amount)
                mlb33=`tail   ServiceIndicator"$DATE".txt | grep 0x1007 | cut -d , -f 3| sed -n "2,1p"`
                #count3=`tail  ServiceIndicator"$DATE".txt | grep "0x0003\|0x8003\|0x0011\|0x000b\|0x1007\|0x0009" | cut -d , -f 3 |  sed -n '4,12p'`
               # declare -i SUM=0
                #for i in $count3
                #do
                #        let SUM+=$i
                #done
               # echo "0:$count3:ok"
 
echo -n "&lt;result>
       &lt;channel>"$Master" Request Number&lt;/channel>
         &lt;value>"$mlb33"&lt;/value>
    &lt;/result>"
echo -n  "&lt;result>
       &lt;channel>"$Master" RX_QUEUE&lt;/channel>
         &lt;value>"$((0x$mlb143))"&lt;/value>
    &lt;/result>"
echo -n "&lt;result>
       &lt;channel>"$Master" Received Bytes&lt;/channel>
        &lt;value>"
received_statu $mlbtotal131024
    echo "&lt;/value>
        &lt;/result>"
echo -n "&lt;result>
       &lt;channel>"$Master" Drop Count&lt;/channel>
        &lt;value>"
drop_statu $mlbtotal15
        echo "&lt;/value>
        &lt;/result>"
done
echo "&lt;/prtg>"

shell script example 2018/12/04

This is one scripts

#!/bin/bash
DATE=`date +%Y%m%d`
#ServiceIndicator$DATE

cd /root/log/20240

	#drop
                mlb153=`tail  ServiceIndicator"$DATE".txt | grep 0x1007 |  cut -d , -f 15 | sed -n "2,1p"`
                mlb152=`tail  ServiceIndicator"$DATE".txt | grep 0x1007 |  cut -d , -f 15 | sed -n "1,1p"`
                mlbtotal15=`expr $mlb153 - $mlb152 `
                mlbtotal15_=`expr $mlb152 - $mlb153 `

function drop_statu {
                if [[ "$mlbtotal15" > "$mlbtotal15_" ]]; then
                        echo -n "$mlbtotal15"       
                else
                        echo -n "$?"
                fi
}
	#received
                mlb133=`tail  ServiceIndicator"$DATE".txt | grep 0x1007 | cut -d , -f 13 | sed -n "2,1p"`
                mlb132=`tail  ServiceIndicator"$DATE".txt | grep 0x1007 | cut -d , -f 13 | sed -n "1,1p"`
                mlbtotal13=`expr $mlb133 - $mlb132 `
                mlbtotal131024=`expr $mlbtotal13 / 1024`
                mlbtotal13_=`expr $mlb132 - $mlb133 `
                mlbtotal131024_=`expr $mlbtotal13_ / 1024`

function received_statu {
                if [[ "$mlbtotal131024" &lt; "$mlbtotal131024_" ]]; then
                        echo -n "$mlbtotal131024"              
                else
                        echo -n "$?"               
                fi
}
	#queue
                mlb143=`tail  ServiceIndicator"$DATE".txt | grep 0x1007 | cut -d , -f 14 | sed -n "2,1p"`
              #  echo "0:$((0x$mlb143)):ok"
                

        #amount)
                mlb33=`tail   ServiceIndicator"$DATE".txt | grep 0x1007 | cut -d , -f 3| sed -n "2,1p"`
                #count3=`tail  ServiceIndicator"$DATE".txt | grep "0x0003\|0x8003\|0x0011\|0x000b\|0x1007\|0x0009" | cut -d , -f 3 |  sed -n '4,12p'`

               # declare -i SUM=0
                #for i in $count3

                #do
                #        let SUM+=$i
                #done

               # echo "0:$count3:ok"
##############################################
echo "&lt;prtg>"
echo -n "&lt;result>
       &lt;channel>Request Number&lt;/channel>
         &lt;value>"$mlb33"&lt;/value>
  	&lt;/result>"

echo -n  "&lt;result>
       &lt;channel>RX_QUEUE&lt;/channel>
         &lt;value>"$((0x$mlb143))"&lt;/value>
   	&lt;/result>"

echo -n	"&lt;result>
       &lt;channel>Received Bytes&lt;/channel>
        &lt;value>" 
received_statu $mlbtotal131024
	echo "&lt;/value>
        &lt;/result>"

echo -n "&lt;result>
       &lt;channel>Drop Count&lt;/channel>
        &lt;value>" 
drop_statu $mlbtotal15
        echo "&lt;/value>
        &lt;/result>"



echo "&lt;/prtg>"