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;
}
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));
}
}
Aggregations