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