Search in sources :

Example 1 with RrdDataSource

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);
    }
}
Also used : PersistException(org.opennms.netmgt.collection.api.PersistException) FileNotFoundException(java.io.FileNotFoundException) RrdDataSource(org.opennms.netmgt.rrd.RrdDataSource) RrdException(org.opennms.netmgt.rrd.RrdException)

Example 2 with RrdDataSource

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

Example 3 with RrdDataSource

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

Example 4 with RrdDataSource

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;
}
Also used : RrdAttributeType(org.opennms.netmgt.rrd.RrdAttributeType) ArrayList(java.util.ArrayList) RrdDataSource(org.opennms.netmgt.rrd.RrdDataSource) NumericCollectionAttributeType(org.opennms.netmgt.collection.api.NumericCollectionAttributeType) CollectionAttributeType(org.opennms.netmgt.collection.api.CollectionAttributeType) NumericCollectionAttributeType(org.opennms.netmgt.collection.api.NumericCollectionAttributeType)

Example 5 with RrdDataSource

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);
}
Also used : RrdDef(org.jrobin.core.RrdDef) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourcePath(org.opennms.netmgt.model.ResourcePath) RrdDataSource(org.opennms.netmgt.rrd.RrdDataSource) RrdDb(org.jrobin.core.RrdDb) File(java.io.File) MockResourceType(org.opennms.netmgt.mock.MockResourceType) HashSet(java.util.HashSet)

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