use of org.jrobin.core.RrdDb 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;
}
use of org.jrobin.core.RrdDb in project jmxtrans by jmxtrans.
the class RRDWriter method internalWrite.
@Override
public void internalWrite(Server server, Query query, ImmutableList<Result> results) throws Exception {
RrdDb db = null;
try {
db = createOrOpenDatabase();
Sample sample = db.createSample();
List<String> dsNames = Arrays.asList(db.getDsNames());
// keys from the result values
for (Result res : results) {
for (Entry<String, Object> entry : res.getValues().entrySet()) {
if (dsNames.contains(entry.getKey()) && isNumeric(entry.getValue())) {
sample.setValue(entry.getKey(), Double.valueOf(entry.getValue().toString()));
}
}
}
sample.update();
} finally {
if (db != null) {
db.close();
}
}
}
use of org.jrobin.core.RrdDb in project opennms by OpenNMS.
the class JmxRrdMigratorOfflineTest method testUpgradeMultiMetric.
/**
* Test upgrade (multi-metric JRBs, i.e. storeByGroup=true).
*
* @throws Exception the exception
*/
@Test
public void testUpgradeMultiMetric() throws Exception {
FileUtils.copyDirectory(new File("src/test/resources/rrd2"), new File("target/home/rrd"));
File config = new File("target/home/etc/opennms.properties");
Properties p = new Properties();
p.load(new FileReader(config));
p.setProperty("org.opennms.rrd.storeByGroup", "true");
p.store(new FileWriter(config), null);
executeMigrator();
File jrbFile = new File("target/home/rrd/1/opennms-jvm/java_lang_type_MemoryPool_name_Survivor_Space.jrb");
Assert.assertTrue(jrbFile.exists());
RrdDb jrb = new RrdDb(jrbFile, true);
String[] dataSources = jrb.getDsNames();
jrb.close();
Properties dsProp = new Properties();
dsProp.load(new FileReader("target/home/rrd/1/opennms-jvm/ds.properties"));
Properties meta = new Properties();
meta.load(new FileReader("target/home/rrd/1/opennms-jvm/java_lang_type_MemoryPool_name_Survivor_Space.meta"));
for (String ds : dataSources) {
Assert.assertFalse(ds.contains("."));
Assert.assertEquals("java_lang_type_MemoryPool_name_Survivor_Space", dsProp.getProperty(ds));
Assert.assertEquals(ds, meta.getProperty("JMX_java.lang:type=MemoryPool.name.Survivor Space." + ds));
}
}
use of org.jrobin.core.RrdDb in project opennms by OpenNMS.
the class AbstractVTDXmlCollectorTest method validateJrb.
/**
* Validates a JRB.
* <p>It assumes storeByGroup=true</p>
*
* @param file the JRB file instance
* @param dsnames the array of data source names
* @param dsvalues the array of data source values
* @throws Exception the exception
*/
public void validateJrb(File file, String[] dsnames, Double[] dsvalues) throws Exception {
Assert.assertTrue(file.exists());
RrdDb jrb = new RrdDb(file);
Assert.assertEquals(dsnames.length, jrb.getDsCount());
for (int i = 0; i < dsnames.length; i++) {
Datasource ds = jrb.getDatasource(dsnames[i]);
Assert.assertNotNull(ds);
Assert.assertEquals(dsvalues[i], Double.valueOf(ds.getLastValue()));
}
}
use of org.jrobin.core.RrdDb in project opennms by OpenNMS.
the class NMS7963IT method testHttpCollection.
/**
* Test HTTP Data Collection with XPath
*
* @throws Exception the exception
*/
@Test
@JUnitHttpServer(port = 10342, https = false, webapps = { @Webapp(context = "/junit", path = "src/test/resources/test-webapp") })
public void testHttpCollection() throws Exception {
File configFile = new File("src/test/resources/http-datacollection-config.xml");
XmlDataCollectionConfig config = JaxbUtils.unmarshal(XmlDataCollectionConfig.class, configFile);
XmlDataCollection collection = config.getDataCollectionByName("NMS-7963");
RrdRepository repository = createRrdRepository(collection.getXmlRrd());
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("collection", "NMS-7963");
DefaultXmlCollectionHandler collector = new DefaultXmlCollectionHandler();
collector.setRrdRepository(repository);
collector.setServiceName("HTTP");
CollectionSet collectionSet = XmlCollectorTestUtils.doCollect(m_nodeDao, collector, m_collectionAgent, collection, parameters);
Assert.assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
ServiceParameters serviceParams = new ServiceParameters(new HashMap<String, Object>());
CollectionSetVisitor persister = m_persisterFactory.createGroupPersister(serviceParams, repository, false, false);
collectionSet.visit(persister);
RrdDb jrb = new RrdDb(new File(getSnmpRoot(), "1/xml-retrv-wipo-data.jrb"));
Assert.assertNotNull(jrb);
Assert.assertEquals(1, jrb.getDsCount());
Datasource ds = jrb.getDatasource("xml-wipo-paco");
Assert.assertNotNull(ds);
Assert.assertEquals(new Double(903), Double.valueOf(ds.getLastValue()));
}
Aggregations