use of org.opennms.netmgt.rrd.RrdDataSource in project opennms by OpenNMS.
the class RrdPersistOperationBuilder method commit.
/**
* <p>commit</p>
*
* @throws org.opennms.netmgt.collection.api.PersistException if any.
*/
public void commit() throws PersistException {
if (m_declarations.size() == 0) {
// Nothing to do. In fact, we'll get an error if we try to create an RRD file with no data sources
return;
}
try {
final String ownerName = m_resource.getOwnerName();
final String absolutePath = getResourceDir(m_resource);
RrdMetaDataUtils.createMetaDataFile(absolutePath, m_rrdName, m_metaData);
List<RrdDataSource> dataSources = getDataSources();
if (dataSources != null && dataSources.size() > 0) {
createRRD(m_rrdStrategy, ownerName, absolutePath, m_rrdName, getRepository().getStep(), dataSources, getRepository().getRraList());
updateRRD(m_rrdStrategy, ownerName, absolutePath, m_rrdName, m_timeKeeper.getCurrentTime(), getValues());
}
} catch (FileNotFoundException e) {
LoggerFactory.getLogger(getClass()).warn("Could not get resource directory: " + e.getMessage(), e);
return;
} catch (RrdException e) {
throw new PersistException(e);
}
}
use of org.opennms.netmgt.rrd.RrdDataSource 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.opennms.netmgt.rrd.RrdDataSource in project opennms by OpenNMS.
the class TcpRrdStrategyTest method createRrdFile.
public File createRrdFile() throws Exception {
String rrdFileBase = "foo";
m_fileAnticipator.initialize();
// This is so the RrdUtils.getExtension() call in the strategy works
// Properties properties = new Properties();
// properties.setProperty("org.opennms.rrd.fileExtension", rrdExtension);
// RrdConfig.getInstance().setProperties(properties);
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");
File tempDir = m_fileAnticipator.getTempDir();
// Create an '/rrd/snmp/1' directory in the temp directory so that the
// RRDs created by the test will have a realistic path
File rrdDir = m_fileAnticipator.tempDir(m_fileAnticipator.tempDir(m_fileAnticipator.tempDir(tempDir, "rrd"), "snmp"), "1");
RrdDefinition def = m_strategy.createDefinition("hello!", rrdDir.getAbsolutePath(), rrdFileBase, 300, dataSources, rraList);
m_strategy.createFile(def);
return m_fileAnticipator.expecting(rrdDir, rrdFileBase + RRD_EXTENSION);
}
use of org.opennms.netmgt.rrd.RrdDataSource in project opennms by OpenNMS.
the class RrdPersistOperationBuilder method getDataSources.
private List<RrdDataSource> getDataSources() {
List<RrdDataSource> dataSources = new ArrayList<RrdDataSource>(m_declarations.size());
for (CollectionAttributeType attrDef : m_declarations.keySet()) {
String minval = "U";
String maxval = "U";
if (attrDef instanceof NumericCollectionAttributeType) {
minval = ((NumericCollectionAttributeType) attrDef).getMinval() != null ? ((NumericCollectionAttributeType) attrDef).getMinval() : "U";
maxval = ((NumericCollectionAttributeType) attrDef).getMaxval() != null ? ((NumericCollectionAttributeType) attrDef).getMaxval() : "U";
}
final RrdAttributeType type = RrdPersistOperationBuilder.mapType(attrDef.getType());
// If the type is supported by RRD...
if (type != null) {
if (attrDef.getName().length() > MAX_DS_NAME_LENGTH) {
LOG.warn("Mib object name/alias '{}' exceeds 19 char maximum for RRD data source names, truncating.", attrDef.getName());
}
RrdDataSource rrdDataSource = new RrdDataSource(StringUtils.truncate(attrDef.getName(), RrdPersistOperationBuilder.MAX_DS_NAME_LENGTH), type, getRepository().getHeartBeat(), minval, maxval);
dataSources.add(rrdDataSource);
}
}
return dataSources;
}
use of org.opennms.netmgt.rrd.RrdDataSource in project opennms by OpenNMS.
the class DefaultRrdDaoIntegrationTest method testPrintValue.
public void testPrintValue() throws Exception {
long start = System.currentTimeMillis();
long end = start + (24 * 60 * 60 * 1000);
OnmsResource topResource = new OnmsResource("1", "Node One", new MockResourceType(), new HashSet<OnmsAttribute>(0), new ResourcePath("foo"));
OnmsAttribute attribute = new RrdGraphAttribute("ifInOctets", "snmp/1/eth0", "ifInOctets.jrb");
HashSet<OnmsAttribute> attributeSet = new HashSet<OnmsAttribute>(1);
attributeSet.add(attribute);
MockResourceType childResourceType = new MockResourceType();
OnmsResource childResource = new OnmsResource("eth0", "Interface One: eth0", childResourceType, attributeSet, new ResourcePath("foo"));
childResource.setParent(topResource);
File snmp = m_fileAnticipator.tempDir(ResourceTypeUtils.SNMP_DIRECTORY);
File node = m_fileAnticipator.tempDir(snmp, topResource.getName());
File intf = m_fileAnticipator.tempDir(node, childResource.getName());
RrdDataSource rrdDataSource = new RrdDataSource(attribute.getName(), RrdAttributeType.GAUGE, 600, "U", "U");
RrdDef def = m_rrdStrategy.createDefinition("test", intf.getAbsolutePath(), attribute.getName(), 600, Collections.singletonList(rrdDataSource), Collections.singletonList("RRA:AVERAGE:0.5:1:100"));
m_rrdStrategy.createFile(def);
File rrdFile = m_fileAnticipator.expecting(intf, attribute.getName() + m_rrdStrategy.getDefaultFileExtension());
RrdDb rrdFileObject = m_rrdStrategy.openFile(rrdFile.getAbsolutePath());
for (int i = 0; i < 10; i++) {
m_rrdStrategy.updateFile(rrdFileObject, "test", (start / 1000 + 300 * i) + ":1");
}
m_rrdStrategy.closeFile(rrdFileObject);
Double value = m_dao.getPrintValue(childResource.getAttributes().iterator().next(), "AVERAGE", start, end);
assertNotNull("value should not be null", value);
assertEquals("value", 1.0, value);
}
Aggregations