use of org.rrd4j.core.RrdDb in project scheduling by ow2-proactive.
the class RRDSigarDataStoreTest method samplesAreCreated_2Beans.
@Test
public void samplesAreCreated_2Beans() throws Exception {
File rrdFile = createTempRRDFile();
Fake fakeBean = new Fake();
Fake fakeBean2 = new Fake();
MBeanServer beanServer = MBeanServerFactory.createMBeanServer();
beanServer.registerMBean(fakeBean, new ObjectName("java.lang:type=Memory"));
beanServer.registerMBean(fakeBean2, new ObjectName("sigar:Type=Mem"));
RRDSigarDataStore store = new RRDSigarDataStore(beanServer, rrdFile.getPath(), 4, Logger.getLogger("test"));
RrdDb dataBase = new RrdDb(rrdFile.getPath());
// sample 5 times every 10 seconds
long firstSampleTime = System.currentTimeMillis();
for (int i = 1; i <= 5; i++) {
store.sample(dataBase, firstSampleTime + i * TEN_SECONDS);
}
assertEquals((firstSampleTime + 5 * TEN_SECONDS) / 1000, dataBase.getLastUpdateTime());
assertEquals(42, dataBase.getDatasource("ValueMemory").getLastValue(), 0.001);
assertEquals(42, dataBase.getDatasource("ValueMem").getLastValue(), 0.001);
}
use of org.rrd4j.core.RrdDb in project scheduling by ow2-proactive.
the class RRDDataStore method initDatabase.
protected void initDatabase() throws IOException {
if (!new File(dataBaseFile).exists()) {
if (step <= 0) {
logger.debug("Provided step is invalid, forcing it to " + DEFAULT_STEP_IN_SECONDS);
step = DEFAULT_STEP_IN_SECONDS;
}
logger.info("Node's statistics are saved in " + dataBaseFile);
RrdDef rrdDef = new RrdDef(dataBaseFile, System.currentTimeMillis() / 1000, step);
for (String dataSource : dataSources.keySet()) {
rrdDef.addDatasource(dataSource, DsType.GAUGE, 600, 0, Double.NaN);
}
// for step equals 4 seconds
// Archive of 10 minutes = 600 seconds (4 * 1 * 150) of completely detailed data
rrdDef.addArchive(ConsolFun.AVERAGE, 0.5, 1, 150);
// An archive of 1 hour = 3600 seconds (4 * 5 * 180) i.e. 180 averages of 5 steps
rrdDef.addArchive(ConsolFun.AVERAGE, 0.5, 5, 180);
// An archive of 4 hours = 14400 seconds (4 * 10 * 360) i.e. 360 averages of 10 steps
rrdDef.addArchive(ConsolFun.AVERAGE, 0.5, 10, 360);
// An archive of 8 hours = 28800 seconds (4 * 20 * 360) i.e. 360 averages of 20 steps
rrdDef.addArchive(ConsolFun.AVERAGE, 0.5, 20, 360);
// An archive of 24 hours = 86400 seconds (4 * 30 * 720) i.e. 720 averages of 30 steps
rrdDef.addArchive(ConsolFun.AVERAGE, 0.5, 30, 720);
// An archive of 1 week = 604800 seconds (4 * 210 * 720) i.e. 720 averages of 210 steps
rrdDef.addArchive(ConsolFun.AVERAGE, 0.5, 210, 720);
// An archive of 1 month ~= 28 days = 604800 seconds (4 * 840 * 720) i.e. 720 averages of 840 steps
rrdDef.addArchive(ConsolFun.AVERAGE, 0.5, 840, 720);
// An archive of 1 year = 364 days = 31449600 seconds (4 * 10920 * 720) i.e. 720 averages of 10920 steps
rrdDef.addArchive(ConsolFun.AVERAGE, 0.5, 10920, 720);
RrdDb dataBase = new RrdDb(rrdDef);
dataBase.close();
} else {
logger.info("Using existing RRD database: " + new File(dataBaseFile).getAbsolutePath());
}
}
use of org.rrd4j.core.RrdDb in project scheduling by ow2-proactive.
the class RRDDataStore method run.
/**
* Periodically dumps the new mbean state to the data base
*/
public void run() {
try {
RrdDb dataBase = new RrdDb(dataBaseFile);
Sample sample = dataBase.createSample();
logger.debug("RRD data base configuration:\n" + dataBase.getRrdDef().dump());
while (!terminate) {
try {
synchronized (dataSources) {
dataSources.wait(step * 1000);
if (terminate) {
break;
}
// updating the data base
for (String dataSource : dataSources.keySet()) {
Object attrValue = mbean.getAttribute(dataSources.get(dataSource));
sample.setValue(dataSource, Double.parseDouble(attrValue.toString()));
logger.debug(System.currentTimeMillis() / 1000 + " sampling: " + dataSource + " " + Double.parseDouble(attrValue.toString()));
}
sample.setTime(System.currentTimeMillis() / 1000);
sample.update();
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
dataBase.close();
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
Aggregations