Search in sources :

Example 1 with RrdDef

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

the class JRobinConverterTest method initializeRrd.

private void initializeRrd(final File fileName, final String[] dsNames, final String[] archives) throws RrdException, IOException {
    final RrdDef rrdDef = new RrdDef(fileName.getAbsolutePath());
    rrdDef.setStartTime(0);
    final DsDef[] dsDefs = new DsDef[dsNames.length];
    for (int i = 0; i < dsNames.length; i++) {
        dsDefs[i] = new DsDef(dsNames[i], "COUNTER", 600, 0, Double.NaN);
    }
    rrdDef.addDatasource(dsDefs);
    final ArcDef[] arcDefs = new ArcDef[archives.length];
    for (int i = 0; i < archives.length; i++) {
        String[] entry = archives[i].split(":");
        Integer steps = Integer.valueOf(entry[0]);
        Integer rows = Integer.valueOf(entry[1]);
        arcDefs[i] = new ArcDef("AVERAGE", 0.5D, steps, rows);
    }
    rrdDef.addArchive(arcDefs);
    final RrdDb db = new RrdDb(rrdDef);
    db.close();
}
Also used : RrdDef(org.jrobin.core.RrdDef) DsDef(org.jrobin.core.DsDef) RrdDb(org.jrobin.core.RrdDb) ArcDef(org.jrobin.core.ArcDef)

Example 2 with RrdDef

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

the class JRobinConverter method createTempRrd.

public File createTempRrd(final File rrdFile) throws IOException, RrdException {
    final File parentFile = rrdFile.getParentFile();
    final File outputFile = new File(parentFile, rrdFile.getName() + ".temp");
    // just in case there's an old one lying around
    outputFile.delete();
    parentFile.mkdirs();
    // LogUtils.debugf(this, "created temporary RRD: %s", outputFile);
    final RrdDb oldRrd = new RrdDb(rrdFile.getAbsolutePath(), true);
    final RrdDef rrdDef = oldRrd.getRrdDef();
    rrdDef.setPath(outputFile.getAbsolutePath());
    rrdDef.setStartTime(0);
    final RrdDb newRrd = new RrdDb(rrdDef);
    newRrd.close();
    return outputFile;
}
Also used : RrdDef(org.jrobin.core.RrdDef) RrdDb(org.jrobin.core.RrdDb) File(java.io.File)

Example 3 with RrdDef

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

the class JRobinRrdStrategyTest method createRrdFile.

public File createRrdFile() throws Exception {
    String rrdFileBase = "foo";
    m_fileAnticipator.initialize();
    String rrdExtension = m_strategy.getDefaultFileExtension();
    List<RrdDataSource> dataSources = new ArrayList<>();
    dataSources.add(new RrdDataSource("bar", RrdAttributeType.GAUGE, 3000, "U", "U"));
    List<String> rraList = new ArrayList<>();
    rraList.add("RRA:AVERAGE:0.5:1:2016");
    RrdDef def = m_strategy.createDefinition("hello!", m_fileAnticipator.getTempDir().getAbsolutePath(), rrdFileBase, 300, dataSources, rraList);
    m_strategy.createFile(def);
    return m_fileAnticipator.expecting(rrdFileBase + rrdExtension);
}
Also used : RrdDef(org.jrobin.core.RrdDef) ArrayList(java.util.ArrayList) RrdDataSource(org.opennms.netmgt.rrd.RrdDataSource)

Example 4 with RrdDef

use of org.jrobin.core.RrdDef 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 5 with RrdDef

use of org.jrobin.core.RrdDef in project jmxtrans by jmxtrans.

the class RRDWriter method createOrOpenDatabase.

/**
 * If the database file doesn't exist, it'll get created, otherwise, it'll
 * be returned in r/w mode.
 */
protected RrdDb createOrOpenDatabase() throws Exception {
    RrdDb result;
    if (!this.outputFile.exists()) {
        FileUtils.forceMkdir(this.outputFile.getParentFile());
        RrdDefTemplate t = new RrdDefTemplate(this.templateFile);
        t.setVariable("database", this.outputFile.getCanonicalPath());
        RrdDef def = t.getRrdDef();
        result = new RrdDb(def);
    } else {
        result = new RrdDb(this.outputFile.getCanonicalPath());
    }
    return result;
}
Also used : RrdDefTemplate(org.jrobin.core.RrdDefTemplate) RrdDef(org.jrobin.core.RrdDef) RrdDb(org.jrobin.core.RrdDb)

Aggregations

RrdDef (org.jrobin.core.RrdDef)11 RrdDb (org.jrobin.core.RrdDb)7 File (java.io.File)6 RrdDataSource (org.opennms.netmgt.rrd.RrdDataSource)4 IOException (java.io.IOException)2 RrdDefTemplate (org.jrobin.core.RrdDefTemplate)2 Result (com.googlecode.jmxtrans.model.Result)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 TreeMap (java.util.TreeMap)1 RateStat (net.i2p.stat.RateStat)1 SecureFile (net.i2p.util.SecureFile)1 ArcDef (org.jrobin.core.ArcDef)1 Archive (org.jrobin.core.Archive)1 DsDef (org.jrobin.core.DsDef)1 RrdBackendFactory (org.jrobin.core.RrdBackendFactory)1 RrdException (org.jrobin.core.RrdException)1 Test (org.junit.Test)1 JUnitCollector (org.opennms.core.collection.test.JUnitCollector)1