use of org.opennms.netmgt.rrd.RrdDataSource in project opennms by OpenNMS.
the class SnmpCollectorIT method testUsingFetch.
@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));
}
use of org.opennms.netmgt.rrd.RrdDataSource in project opennms by OpenNMS.
the class JRobinRrdStrategy method createDefinition.
/**
* {@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;
}
use of org.opennms.netmgt.rrd.RrdDataSource in project opennms by OpenNMS.
the class JniRrdStrategy method createDefinition.
/**
* {@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;
}
final StringBuilder parameter = new StringBuilder();
parameter.append(" --start=" + (System.currentTimeMillis() / 1000L - 10L));
parameter.append(" --step=" + step);
for (RrdDataSource dataSource : dataSources) {
parameter.append(" DS:");
parameter.append(dataSource.getName()).append(':');
parameter.append(dataSource.getType()).append(":");
parameter.append(dataSource.getHeartBeat()).append(':');
parameter.append(dataSource.getMin()).append(':');
parameter.append(dataSource.getMax());
}
for (String rra : rraList) {
parameter.append(' ');
parameter.append(rra);
}
return new CreateCommand(fileName, parameter.toString());
}
use of org.opennms.netmgt.rrd.RrdDataSource in project opennms by OpenNMS.
the class MultithreadedJniRrdStrategy method createDefinition.
/**
* {@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);
}
Aggregations