我正在Ubuntu 16.04上测试MRTG 2.17.4。我将其配置为使用rrdtool来记录数据。我的/etc/mrtg.cfg中有“Interval:1”。我在/etc/cron.d/mrtg编辑了cron作业:
*/1 * * * * root if [ -x /usr/bin/mrtg ] && [ -r /etc/mrtg.cfg ] && [ -d "$(grep '^[[:space:]]*[^#]*[[:space:]]*WorkDir' /etc/mrtg.cfg | awk '{ print $NF }')" ]; then mkdir -p /var/log/mrtg ; env LANG=C /usr/bin/mrtg /etc/mrtg.cfg --debug="time,log" 2>&1 | tee -a /var/log/mrtg/mrtg.log ; fi
请注意我添加了调试选项“time,log”以帮助排除故障。在我的/var/log/mrtg/mrtg.log中,我看到数据按预期每隔一分钟记录一次,但它不会尝试每分钟计算吞吐量。相反,它每5分钟一次。在其他时候,它只是说“得到??? / ???”
--time: prog start Sat Nov 12 21:54:01 2016
--time: loop start Sat Nov 12 21:54:01 2016
--time: snmp read start Sat Nov 12 21:54:01 2016
--time: target loop start Sat Nov 12 21:54:01 2016
--log: RRDs::tune(/var/mrtg/192.168.1.40_24.rrd -a ds0:125000000 -a ds1:125000000 -d ds0:COUNTER -d ds1:COUNTER)
--log: RRDs::update(/var/mrtg/192.168.1.40_24.rrd, '1479012841:171337092:172912456')
--log: got: ???/???
--time: prog start Sat Nov 12 21:55:01 2016
--time: loop start Sat Nov 12 21:55:01 2016
--time: snmp read start Sat Nov 12 21:55:01 2016
--time: target loop start Sat Nov 12 21:55:01 2016
--log: RRDs::tune(/var/mrtg/192.168.1.40_24.rrd -a ds0:125000000 -a ds1:125000000 -d ds0:COUNTER -d ds1:COUNTER)
--log: RRDs::update(/var/mrtg/192.168.1.40_24.rrd, '1479012901:171686542:173262414')
--log: got: 5804.75277777778/5813.21944444444
--time: prog start Sat Nov 12 21:56:02 2016
--time: loop start Sat Nov 12 21:56:02 2016
--time: snmp read start Sat Nov 12 21:56:02 2016
--time: target loop start Sat Nov 12 21:56:02 2016
--log: RRDs::tune(/var/mrtg/192.168.1.40_24.rrd -a ds0:125000000 -a ds1:125000000 -d ds0:COUNTER -d ds1:COUNTER)
--log: RRDs::update(/var/mrtg/192.168.1.40_24.rrd, '1479012962:172034542:173610922')
--log: got: ???/???
--time: prog start Sat Nov 12 21:57:01 2016
--time: loop start Sat Nov 12 21:57:01 2016
--time: snmp read start Sat Nov 12 21:57:01 2016
--time: target loop start Sat Nov 12 21:57:01 2016
--log: RRDs::tune(/var/mrtg/192.168.1.40_24.rrd -a ds0:125000000 -a ds1:125000000 -d ds0:COUNTER -d ds1:COUNTER)
--log: RRDs::update(/var/mrtg/192.168.1.40_24.rrd, '1479013021:172376742:173953630')
--log: got: ???/???
--time: prog start Sat Nov 12 21:58:01 2016
--time: loop start Sat Nov 12 21:58:01 2016
--time: snmp read start Sat Nov 12 21:58:01 2016
--time: target loop start Sat Nov 12 21:58:01 2016
--log: RRDs::tune(/var/mrtg/192.168.1.40_24.rrd -a ds0:125000000 -a ds1:125000000 -d ds0:COUNTER -d ds1:COUNTER)
--log: RRDs::update(/var/mrtg/192.168.1.40_24.rrd, '1479013081:172724742:174302138')
--log: got: ???/???
--time: prog start Sat Nov 12 21:59:01 2016
--time: loop start Sat Nov 12 21:59:01 2016
--time: snmp read start Sat Nov 12 21:59:01 2016
--time: target loop start Sat Nov 12 21:59:01 2016
--log: RRDs::tune(/var/mrtg/192.168.1.40_24.rrd -a ds0:125000000 -a ds1:125000000 -d ds0:COUNTER -d ds1:COUNTER)
--log: RRDs::update(/var/mrtg/192.168.1.40_24.rrd, '1479013141:173077092:174654996')
--log: got: ???/???
--time: prog start Sat Nov 12 22:00:02 2016
--time: loop start Sat Nov 12 22:00:02 2016
--time: snmp read start Sat Nov 12 22:00:02 2016
--time: target loop start Sat Nov 12 22:00:02 2016
--log: RRDs::tune(/var/mrtg/192.168.1.40_24.rrd -a ds0:125000000 -a ds1:125000000 -d ds0:COUNTER -d ds1:COUNTER)
--log: RRDs::update(/var/mrtg/192.168.1.40_24.rrd, '1479013202:173426542:175004954')
--log: got: 5781.22263205829/5789.66200182149
--time: prog start Sat Nov 12 22:01:01 2016
--time: loop start Sat Nov 12 22:01:01 2016
--time: snmp read start Sat Nov 12 22:01:01 2016
--time: target loop start Sat Nov 12 22:01:01 2016
--log: RRDs::tune(/var/mrtg/192.168.1.40_24.rrd -a ds0:125000000 -a ds1:125000000 -d ds0:COUNTER -d ds1:COUNTER)
--log: RRDs::update(/var/mrtg/192.168.1.40_24.rrd, '1479013261:173768742:175347662')
--log: got: ???/???
我并不特别担心它不会每分钟计算一次,但是我需要将数据存储在rrd数据库中。但是当我尝试使用rrdtool fetch时,它仍显示5分钟的数据..我在哪里做错了?
rrdtool fetch 192.168.1.40_24.rrd AVERAGE -a -s -1h -r 1m -a
ds0 ds1
1479010500: 1.0150000000e+04 1.0158466667e+04
1479010800: 1.0150000000e+04 1.0158466667e+04
1479011100: 1.0145166667e+04 1.0153661556e+04
1479011400: 1.0021447006e+04 1.0029884972e+04
1479011700: 5.8127796610e+03 5.8212468060e+03
1479012000: 5.7859754098e+03 5.7944147796e+03
1479012300: 5.8089454941e+03 5.8174389793e+03
1479012600: 5.8006990960e+03 5.8091662411e+03
1479012900: 5.8047527778e+03 5.8132194444e+03
1479013200: 5.7812226321e+03 5.7896620018e+03
1479013500: 5.7946912568e+03 5.8031847421e+03
1479013800: 5.8049794444e+03 5.8134465895e+03
1479014100: -nan -nan
谢谢! 荻帆
答案 0 :(得分:3)
可能有助于查看MRTG配置文件以及RRD文件中rrdtool info
的输出。
但是,可能的原因是您最初以5分钟的间隔创建了RRD文件,然后稍后更改为1分钟。如果您这样做,那么MRTG将不会重新创建RRD文件,尽管它将更改为每1分钟收集一次数据。如果在创建后修改了RRD,Mrtg只能更改它的MaxBytes;其他设置(RRDRowCount,Interval)只能在初始创建时使用,随后在MRTG cfg文件中更改它们不会导致RRD文件改变。
如果您在RRD文件上使用rrdtool info
,您可能会发现它的步长为5分钟(300秒)。更改此设置的唯一方法是删除RRD文件(丢失历史数据)并允许MRTG以cfg文件中指定的60s间隔重新创建它。
请注意,如果您的5min RRD文件中有许多有价值的历史数据,您绝对必须保留,那么可以使用第三方实用程序将其转储到XML并重新创建新的RRD,但任务有点复杂。查找rrdmigrate
或rrdmerge
。最新的RRDtool在这方面也有一些能力。