我正在 Ubuntu 16.04 上测试 MRTG 2.17.4。我将其配置为使用 rrdtool 来记录数据。我的 /etc/mrtg.cfg 中有“间隔: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
请注意,我添加了调试选项“时间,日志”以帮助排除故障。在我的 /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
谢谢!地番