/** {@inheritDoc} */ @Override public CreateCommand createDefinition(String creator, String directory, String rrdName, int step, List<RrdDataSource> dataSources, List<String> rraList) throws Exception { File f = new File(directory); if (!f.exists()) { if (!f.mkdirs()) { LOG.warn("Could not make directory: {}", f.getPath()); } } String fileName = directory + File.separator + rrdName + getDefaultFileExtension(); if (new File(fileName).exists()) { LOG.debug("createDefinition: filename [{}] already exists returning null as definition", fileName); return null; } int k = 0; final String[] arguments = new String[dataSources.size() + rraList.size()]; final long start = (System.currentTimeMillis() / 1000L - 10L); for (RrdDataSource dataSource : dataSources) { arguments[k++] = String.format("DS:%s:%s:%d:%s:%s", dataSource.getName(), dataSource.getType(), dataSource.getHeartBeat(), dataSource.getMin(), dataSource.getMax()); } for (String rra : rraList) { arguments[k++] = rra; } return new CreateCommand(fileName, step, start, arguments); }
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; }
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; }
parameter.append(dataSource.getName()).append(':'); parameter.append(dataSource.getType()).append(":"); parameter.append(dataSource.getHeartBeat()).append(':'); parameter.append(dataSource.getMin()).append(':'); parameter.append(dataSource.getMax());
@Test @Transactional @JUnitCollector( datacollectionConfig = "/org/opennms/netmgt/config/datacollection-config.xml", datacollectionType = "snmp", anticipateRrds = { "test" }, anticipateMetaFiles = false ) public void testUsingFetch() throws Exception { System.err.println("=== testUsingFetch ==="); File snmpDir = (File)m_context.getAttribute("rrdDirectory"); // We initialize an empty attribute map, key=e.g OID; value=e.g. datasource name Map<String,String> attributeMappings = new HashMap<String, String>(); int stepSize = 1; int numUpdates = 2; long start = System.currentTimeMillis(); final int stepSizeInMillis = stepSize*1000; final int rangeSizeInMillis = stepSizeInMillis + 20000; File rrdFile = new File(snmpDir, rrd("test")); RrdStrategy<RrdDef,RrdDb> m_rrdStrategy = new JRobinRrdStrategy(); RrdDataSource rrdDataSource = new RrdDataSource("testAttr", RrdAttributeType.GAUGE, stepSize*2, "U", "U"); RrdDef def = m_rrdStrategy.createDefinition("test", snmpDir.getAbsolutePath(), "test", stepSize, Collections.singletonList(rrdDataSource), Collections.singletonList("RRA:AVERAGE:0.5:1:100")); m_rrdStrategy.createFile(def); RrdDb rrdFileObject = m_rrdStrategy.openFile(rrdFile.getAbsolutePath()); for (int i = 0; i < numUpdates; i++) { m_rrdStrategy.updateFile(rrdFileObject, "test", ((start/1000) - (stepSize*(numUpdates-i))) + ":1"); } m_rrdStrategy.closeFile(rrdFileObject); assertEquals(Double.valueOf(1.0), m_rrdStrategy.fetchLastValueInRange(rrdFile.getAbsolutePath(), "testAttr", stepSizeInMillis, rangeSizeInMillis)); }
/** {@inheritDoc} */ @Override public RrdDef createDefinition(final String creator, final String directory, final String rrdName, int step, final List<RrdDataSource> dataSources, final List<String> rraList) throws Exception { File f = new File(directory); f.mkdirs(); String fileName = directory + File.separator + rrdName + getDefaultFileExtension(); if (new File(fileName).exists()) { LOG.debug("createDefinition: filename [{}] already exists returning null as definition", fileName); return null; } RrdDef def = new RrdDef(fileName); // def.setStartTime(System.currentTimeMillis()/1000L - 2592000L); def.setStartTime(1000); def.setStep(step); for (RrdDataSource dataSource : dataSources) { String dsMin = dataSource.getMin(); String dsMax = dataSource.getMax(); double min = (dsMin == null || "U".equals(dsMin) ? Double.NaN : Double.parseDouble(dsMin)); double max = (dsMax == null || "U".equals(dsMax) ? Double.NaN : Double.parseDouble(dsMax)); def.addDatasource(dataSource.getName(), dataSource.getType().toString(), dataSource.getHeartBeat(), min, max); } for (String rra : rraList) { def.addArchive(rra); } return def; }