我正在尝试存储我的路由器的 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
答案1
从错误消息的损坏程度来看:
conversion of '12.0' to float not complete: tail '...'
您的数据可能在行尾有回车符。 unix 上的 awk 不会将这些字符视为空格。最简单的解决方案是将数据通过管道传输
sed 's/\r$//'
例如,在将其传递给 awk 之前。