Search in sources :

Example 1 with NodeSnmpResourceType

use of org.opennms.netmgt.dao.support.NodeSnmpResourceType in project opennms by OpenNMS.

the class DefaultRrdSummaryService method getSummary.

/**
 * <p>getSummary</p>
 *
 * @param filterRule a {@link java.lang.String} object.
 * @param startTime a long.
 * @param endTime a long.
 * @param attributeSieve a {@link java.lang.String} object.
 * @return a {@link org.opennms.netmgt.config.attrsummary.Summary} object.
 */
public Summary getSummary(String filterRule, final long startTime, final long endTime, final String attributeSieve) {
    m_stats.begin("getSummary");
    try {
        final SummaryBuilder bldr = new SummaryBuilder();
        FilterWalker walker = new FilterWalker();
        walker.setFilterDao(m_filterDao);
        walker.setNodeDao(m_nodeDao);
        walker.setFilter(filterRule);
        walker.setVisitor(new AbstractEntityVisitor() {

            @Override
            public void visitNode(OnmsNode node) {
                OnmsResource nodeResource = getResourceForNode(node);
                bldr.pushResource(node.getLabel());
                for (OnmsResource child : getChildResources1(nodeResource)) {
                    if (child.getResourceType() instanceof NodeSnmpResourceType) {
                        addAttributes(getResourceGraphAttributes(child));
                    }
                }
                for (OnmsResource child : getChildResources2(nodeResource)) {
                    if (!(child.getResourceType() instanceof NodeSnmpResourceType)) {
                        addResource(child);
                    }
                }
                bldr.popResource();
            }

            private Collection<RrdGraphAttribute> getResourceGraphAttributes(OnmsResource child) {
                String op = "getResourceGraphAttributes-" + child.getResourceType().getName();
                m_stats.begin(op);
                try {
                    return child.getRrdGraphAttributes().values();
                } finally {
                    m_stats.end(op);
                }
            }

            private List<OnmsResource> getChildResources1(OnmsResource nodeResource) {
                m_stats.begin("getChildResources1");
                try {
                    return nodeResource.getChildResources();
                } finally {
                    m_stats.end("getChildResources1");
                }
            }

            private List<OnmsResource> getChildResources2(OnmsResource nodeResource) {
                m_stats.begin("getChildResources2");
                try {
                    return nodeResource.getChildResources();
                } finally {
                    m_stats.end("getChildResources2");
                }
            }

            private OnmsResource getResourceForNode(OnmsNode node) {
                m_stats.begin("getResourceForNode");
                try {
                    return m_resourceDao.getResourceForNode(node);
                } finally {
                    m_stats.end("getResourceForNode");
                }
            }

            private void addResource(OnmsResource resource) {
                addResource(resource, resource.getLabel());
            }

            private void addResource(OnmsResource resource, String label) {
                Collection<RrdGraphAttribute> attrs = getResourceGraphAttributes(resource);
                if (attrs.size() > 0) {
                    bldr.pushResource(label);
                    addAttributes(attrs);
                    bldr.popResource();
                }
            }

            private void addAttributes(Collection<RrdGraphAttribute> attrs) {
                m_stats.begin("addAttributes");
                try {
                    for (RrdGraphAttribute attr : attrs) {
                        if (attr.getName().matches(attributeSieve)) {
                            bldr.addAttribute(attr.getName());
                            double[] values = getValues(attr);
                            bldr.setMin(values[0]);
                            bldr.setAverage(values[1]);
                            bldr.setMax(values[2]);
                        }
                    }
                } finally {
                    m_stats.end("addAttributes");
                }
            }

            private double[] getValues(RrdGraphAttribute attr) {
                m_stats.begin("getValues");
                try {
                    return m_rrdDao.getPrintValues(attr, "AVERAGE", startTime * 1000, endTime * 1000, "MIN", "AVERAGE", "MAX");
                } finally {
                    m_stats.end("getValues");
                }
            }
        });
        walker.walk();
        return bldr.getSummary();
    } finally {
        m_stats.end("getSummary");
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsResource(org.opennms.netmgt.model.OnmsResource) FilterWalker(org.opennms.netmgt.dao.support.FilterWalker) Collection(java.util.Collection) AbstractEntityVisitor(org.opennms.netmgt.model.AbstractEntityVisitor) List(java.util.List) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) NodeSnmpResourceType(org.opennms.netmgt.dao.support.NodeSnmpResourceType)

Aggregations

Collection (java.util.Collection)1 List (java.util.List)1 FilterWalker (org.opennms.netmgt.dao.support.FilterWalker)1 NodeSnmpResourceType (org.opennms.netmgt.dao.support.NodeSnmpResourceType)1 AbstractEntityVisitor (org.opennms.netmgt.model.AbstractEntityVisitor)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 OnmsResource (org.opennms.netmgt.model.OnmsResource)1 RrdGraphAttribute (org.opennms.netmgt.model.RrdGraphAttribute)1