Search in sources :

Example 6 with RrdDataSource

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));
}
Also used : RrdDef(org.jrobin.core.RrdDef) HashMap(java.util.HashMap) RrdDb(org.jrobin.core.RrdDb) RrdDataSource(org.opennms.netmgt.rrd.RrdDataSource) JRobinRrdStrategy(org.opennms.netmgt.rrd.jrobin.JRobinRrdStrategy) File(java.io.File) JUnitCollector(org.opennms.core.collection.test.JUnitCollector) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with RrdDataSource

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;
}
Also used : RrdDef(org.jrobin.core.RrdDef) RrdDataSource(org.opennms.netmgt.rrd.RrdDataSource) File(java.io.File)

Example 8 with RrdDataSource

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());
}
Also used : RrdDataSource(org.opennms.netmgt.rrd.RrdDataSource) File(java.io.File)

Example 9 with RrdDataSource

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);
}
Also used : RrdDataSource(org.opennms.netmgt.rrd.RrdDataSource) File(java.io.File)

Aggregations

RrdDataSource (org.opennms.netmgt.rrd.RrdDataSource)9 File (java.io.File)6 RrdDef (org.jrobin.core.RrdDef)4 ArrayList (java.util.ArrayList)3 RrdDb (org.jrobin.core.RrdDb)2 FileNotFoundException (java.io.FileNotFoundException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 JUnitCollector (org.opennms.core.collection.test.JUnitCollector)1 CollectionAttributeType (org.opennms.netmgt.collection.api.CollectionAttributeType)1 NumericCollectionAttributeType (org.opennms.netmgt.collection.api.NumericCollectionAttributeType)1 PersistException (org.opennms.netmgt.collection.api.PersistException)1 MockResourceType (org.opennms.netmgt.mock.MockResourceType)1 OnmsAttribute (org.opennms.netmgt.model.OnmsAttribute)1 OnmsResource (org.opennms.netmgt.model.OnmsResource)1 ResourcePath (org.opennms.netmgt.model.ResourcePath)1 RrdGraphAttribute (org.opennms.netmgt.model.RrdGraphAttribute)1 RrdAttributeType (org.opennms.netmgt.rrd.RrdAttributeType)1 RrdException (org.opennms.netmgt.rrd.RrdException)1