Search code examples
rrdtoolmrtg

MRTG and/or rrdtool - one minute interval not working


I am testing MRTG 2.17.4 on Ubuntu 16.04. I configured it to use rrdtool to log data. I have "Interval: 1" in my /etc/mrtg.cfg. I edited the cron job at /etc/cron.d/mrtg to be:

*/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

Please note that I added debug option "time,log" to help troubleshoot. In my /var/log/mrtg/mrtg.log, I see the data is logged every one minute as expected, however it does not try to calculate the throughput every minute. Instead, it does it every 5 minutes. For the other times, it just says "got ???/???"

--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: ???/???

I am not particularly worried that it does not calculate the rate every minute however I need the data to be stored in the rrd database. But when I tried with the rrdtool fetch, it still shows 5 minute data.. Where did I do wrong?

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

Thanks! Difan


Solution

  • It might help to see the MRTG config file, and the output of rrdtool info in the RRD file.

    However, the likely cause is that you originally created the RRD file with a 5min interval, and then changed to a 1min interval later. If you do this, then MRTG will not recreate the RRD file, though it will change to collecting data every 1min. Mrtg is only able to change the MaxBytes of an RRD if it is modified after creation; other settings (RRDRowCount, Interval) can only be used at initial creation time, and subsequently changing them in the MRTG cfg file will not cause the RRD file to alter.

    If you use rrdtool info on your RRD file, you will likely see that it has a 5min (300s) step size. The only way to change this is to delete the RRD file (losing your historical data) and allow MRTG to re-create it with the 60s interval specified in your cfg file.

    Note that, if you have a lot of valuable historical data in your 5min RRD file that you absolutely must keep, then there are third-party utilities available to dump this to XML and recreate a new RRD but the task is a bit complex. Look for rrdmigrate or rrdmerge. The latest RRDtool also has some abilities in this area.