Shell-Script

當整數和浮點數混合時,RRDtool 更新不起作用

  • September 5, 2015

我正在嘗試為我的路由器儲存 ADSL 統計資訊。我沒有對其他人做 rrdtool 資訊,因為他們現在在使用與腳本中相同的命令進行更新後顯示正確的值。奇怪的是,實際的浮點值儲存得很好。

這兩個值都是 GAUGE。

root@pi:/scripts# ./routerstats.sh&&rrdtool info rrd/attn.rrd|grep last 
+ awk ' /^Max/      { maxup = $5; maxdown = $10; }
   /^Channel/  { curup = $6; curdown = $11; }
   /^SNR/      { snrdown = $3; snrup = $4; }
   /^Attn/     { attndown = $2; attnup = $3; }
   /^Pwr/      { pwrdown = $2; pwrup = $3; }
   END     { up = sprintf("N:%s:%s", maxup, curup);
             down = sprintf("N:%s:%s", maxdown, curdown);
             snr = sprintf("N:%s:%s", snrdown, snrup);
             attn = sprintf("N:%s:%s", attndown, attnup);
             pwr = sprintf("N:%s:%s", pwrdown, pwrup);
             system("echo up " up);
             system("echo down " down);
             system("echo snr " snr);
             system("echo attn " attn);
             system("echo pwr " pwr);
             system("rrdtool update /scripts/rrd/up.rrd -t max N:" maxup);
             system("rrdtool update /scripts/rrd/down.rrd -t max N:" maxdown);
             system("rrdtool update /scripts/rrd/snr.rrd -t down N:" snrdown);
             system("rrdtool update /scripts/rrd/attn.rrd -t down N:" attndown);
             system("rrdtool update /scripts/rrd/pwr.rrd -t down N:" pwrdown);
             system("rrdtool update /scripts/rrd/up.rrd -t current N:" curup);
             system("rrdtool update /scripts/rrd/down.rrd -t current N:" curdown);
             system("rrdtool update /scripts/rrd/snr.rrd -t up N:" snrup);
             system("rrdtool update /scripts/rrd/attn.rrd -t up N:" attnup);
             system("rrdtool update /scripts/rrd/pwr.rrd -t up N:" pwrup);
           }'
up N:1080:512
down N:10788:2048
snr N:20.4:12.0
attn N:26.0:15.0
pwr N:5.1:4.0
' to float not complete: tail 'nversion of '12.0
' to float not complete: tail 'onversion of '15.0
' to float not complete: tail 'nversion of '4.0
last_update = 1441477923
ds[down].last_ds = "U"
ds[up].last_ds = "U"

傳入awk的數據:

Status: Showtime
Last Retrain Reason:    0
Last initialization procedure status:   0
Max:    Upstream rate = 1120 Kbps, Downstream rate = 10816 Kbps
Channel:        FAST, Upstream rate = 512 Kbps, Downstream rate = 2048 Kbps

Link Power State:       L0
Mode:                   G.DMT 
TPS-TC:                 ATM Mode
Trellis:                ON
Line Status:            No Defect
Training Status:        Showtime
               Down            Up
SNR (dB):        21.4            12.0
Attn(dB):        26.0            15.0
Pwr(dBm):        5.0             2.9

從錯誤資訊的損壞情況來看:

conversion of '12.0' to float not complete: tail '...'

可能是您的數據在行尾有輸入。在 unix 上,awk 不會將這些視為空格。最簡單的解決方案是通過管道傳輸數據

sed 's/\r$//'

例如,在通過 awk 之前。

引用自:https://unix.stackexchange.com/questions/227749