Search in sources :

Example 1 with RrdBackendFactory

use of org.jrobin.core.RrdBackendFactory in project i2p.i2p by i2p.

the class SummaryListener method startListening.

/**
 *  @return success
 */
public boolean startListening() {
    RateStat rs = _rate.getRateStat();
    long period = _rate.getPeriod();
    String baseName = rs.getName() + "." + period;
    _name = createName(_context, baseName);
    _eventName = createName(_context, baseName + ".events");
    File rrdFile = null;
    try {
        RrdBackendFactory factory = RrdBackendFactory.getFactory(getBackendName());
        String rrdDefName;
        if (_isPersistent) {
            // generate full path for persistent RRD files
            File rrdDir = new SecureFile(_context.getRouterDir(), RRD_DIR);
            rrdFile = new File(rrdDir, RRD_PREFIX + _name + RRD_SUFFIX);
            rrdDefName = rrdFile.getAbsolutePath();
            if (rrdFile.exists()) {
                _db = new RrdDb(rrdDefName, factory);
                Archive arch = _db.getArchive(CF, STEPS);
                if (arch == null)
                    throw new IOException("No average CF in " + rrdDefName);
                _rows = arch.getRows();
                if (_log.shouldLog(Log.INFO))
                    _log.info("Existing RRD " + baseName + " (" + rrdDefName + ") with " + _rows + " rows consuming " + _db.getRrdBackend().getLength() + " bytes");
            } else {
                rrdDir.mkdir();
            }
        } else {
            rrdDefName = _name;
        }
        if (_db == null) {
            // not persistent or not previously existing
            RrdDef def = new RrdDef(rrdDefName, now() / 1000, period / 1000);
            // for info on the heartbeat, xff, steps, etc, see the rrdcreate man page, aka
            // http://www.jrobin.org/support/man/rrdcreate.html
            long heartbeat = period * 10 / 1000;
            def.addDatasource(_name, "GAUGE", heartbeat, Double.NaN, Double.NaN);
            def.addDatasource(_eventName, "GAUGE", heartbeat, 0, Double.NaN);
            if (_isPersistent) {
                _rows = (int) Math.max(MIN_ROWS, Math.min(MAX_ROWS, THREE_MONTHS / period));
            } else {
                _rows = MIN_ROWS;
            }
            def.addArchive(CF, XFF, STEPS, _rows);
            _db = new RrdDb(def, factory);
            if (_isPersistent)
                SecureFileOutputStream.setPerms(new File(rrdDefName));
            if (_log.shouldLog(Log.INFO))
                _log.info("New RRD " + baseName + " (" + rrdDefName + ") with " + _rows + " rows consuming " + _db.getRrdBackend().getLength() + " bytes");
        }
        _sample = _db.createSample();
        _renderer = new SummaryRenderer(_context, this);
        _rate.setSummaryListener(this);
        return true;
    } catch (OutOfMemoryError oom) {
        _log.error("Error starting RRD for stat " + baseName, oom);
    } catch (RrdException re) {
        _log.error("Error starting RRD for stat " + baseName, re);
        // corrupt file?
        if (_isPersistent && rrdFile != null)
            rrdFile.delete();
    } catch (IOException ioe) {
        _log.error("Error starting RRD for stat " + baseName, ioe);
    } catch (Throwable t) {
        _log.error("Error starting RRD for stat " + baseName, t);
    }
    return false;
}
Also used : Archive(org.jrobin.core.Archive) RrdDef(org.jrobin.core.RrdDef) SecureFile(net.i2p.util.SecureFile) IOException(java.io.IOException) RateStat(net.i2p.stat.RateStat) RrdBackendFactory(org.jrobin.core.RrdBackendFactory) RrdDb(org.jrobin.core.RrdDb) RrdException(org.jrobin.core.RrdException) SecureFile(net.i2p.util.SecureFile) File(java.io.File)

Example 2 with RrdBackendFactory

use of org.jrobin.core.RrdBackendFactory in project opennms by OpenNMS.

the class JRobinConverterTest method testBackends.

@Test
public void testBackends() throws Exception {
    final RrdBackendFactory[] factories = new RrdBackendFactory[] { new RrdFileBackendFactory(), new RrdNioBackendFactory(), new RrdNioByteBufferBackendFactory(), new RrdJRobin14FileBackendFactory(LockMode.EXCEPTION_IF_LOCKED), new RrdJRobin14FileBackendFactory(LockMode.WAIT_IF_LOCKED), new RrdJRobin14FileBackendFactory(LockMode.NO_LOCKS) };
    for (final RrdBackendFactory factory : factories) {
        // LogUtils.infof(this, "starting with backend factory %s", factory);
        m_sineFull.delete();
        m_sineSourceA.delete();
        long factoryStart = System.nanoTime();
        createMockSineRrds(factory);
        for (int i = 0; i < 10; i++) {
            final File newFile = m_converter.createTempRrd(m_sineFull);
            try {
                m_converter.consolidateRrdFile(m_sineSourceA, newFile);
            } finally {
                newFile.delete();
            }
        }
        long nanos = System.nanoTime() - factoryStart;
        LogUtils.infof(this, "factory %s took %f seconds", factory, (nanos / 1000000000D));
    }
}
Also used : RrdBackendFactory(org.jrobin.core.RrdBackendFactory) RrdNioBackendFactory(org.jrobin.core.RrdNioBackendFactory) RrdNioByteBufferBackendFactory(org.jrobin.core.RrdNioByteBufferBackendFactory) RrdFileBackendFactory(org.jrobin.core.RrdFileBackendFactory) File(java.io.File) RrdJRobin14FileBackendFactory(org.jrobin.core.RrdJRobin14FileBackendFactory) Test(org.junit.Test)

Aggregations

File (java.io.File)2 RrdBackendFactory (org.jrobin.core.RrdBackendFactory)2 IOException (java.io.IOException)1 RateStat (net.i2p.stat.RateStat)1 SecureFile (net.i2p.util.SecureFile)1 Archive (org.jrobin.core.Archive)1 RrdDb (org.jrobin.core.RrdDb)1 RrdDef (org.jrobin.core.RrdDef)1 RrdException (org.jrobin.core.RrdException)1 RrdFileBackendFactory (org.jrobin.core.RrdFileBackendFactory)1 RrdJRobin14FileBackendFactory (org.jrobin.core.RrdJRobin14FileBackendFactory)1 RrdNioBackendFactory (org.jrobin.core.RrdNioBackendFactory)1 RrdNioByteBufferBackendFactory (org.jrobin.core.RrdNioByteBufferBackendFactory)1 Test (org.junit.Test)1