use of org.opennms.netmgt.model.RrdGraphAttribute in project opennms by OpenNMS.
the class Graph method getRequiredRrGraphdAttributes.
/**
* <p>getRequiredRrGraphdAttributes</p>
*
* @return a {@link java.util.Collection} object.
*/
public Collection<RrdGraphAttribute> getRequiredRrGraphdAttributes() {
Map<String, RrdGraphAttribute> available = m_resource.getRrdGraphAttributes();
Set<RrdGraphAttribute> reqAttrs = new LinkedHashSet<RrdGraphAttribute>();
for (String attrName : m_graph.getColumns()) {
RrdGraphAttribute attr = available.get(attrName);
if (attr != null) {
reqAttrs.add(attr);
}
}
return reqAttrs;
}
use of org.opennms.netmgt.model.RrdGraphAttribute in project opennms by OpenNMS.
the class DefaultRrdDao method getPrintValues.
/**
* <p>getPrintValues</p>
*
* @param attribute a {@link org.opennms.netmgt.model.OnmsAttribute} object.
* @param rraConsolidationFunction a {@link java.lang.String} object.
* @param startTimeInMillis a long.
* @param endTimeInMillis a long.
* @param printFunctions a {@link java.lang.String} object.
* @return an array of double.
*/
@Override
public double[] getPrintValues(OnmsAttribute attribute, String rraConsolidationFunction, long startTimeInMillis, long endTimeInMillis, String... printFunctions) {
Assert.notNull(attribute, "attribute argument must not be null");
Assert.notNull(rraConsolidationFunction, "rraConsolicationFunction argument must not be null");
Assert.isTrue(endTimeInMillis > startTimeInMillis, "end argument must be after start argument");
Assert.isAssignable(attribute.getClass(), RrdGraphAttribute.class, "attribute argument must be assignable to RrdGraphAttribute");
// if no printFunctions are given just use the rraConsolidationFunction
if (printFunctions.length < 1) {
printFunctions = new String[] { rraConsolidationFunction };
}
RrdGraphAttribute rrdAttribute = (RrdGraphAttribute) attribute;
String[] command = new String[] { m_rrdBinaryPath, "graph", "-", "--start=" + (startTimeInMillis / 1000), "--end=" + (endTimeInMillis / 1000), "DEF:ds1=" + RrdFileConstants.escapeForGraphing(rrdAttribute.getRrdRelativePath()) + ":" + attribute.getName() + ":" + rraConsolidationFunction };
String[] printDefs = new String[printFunctions.length];
for (int i = 0; i < printFunctions.length; i++) {
printDefs[i] = "PRINT:ds1:" + printFunctions[i] + ":\"%le\"";
}
String commandString = StringUtils.arrayToDelimitedString(command, " ") + ' ' + StringUtils.arrayToDelimitedString(printDefs, " ");
LOG.debug("commandString: {}", commandString);
RrdGraphDetails graphDetails;
try {
graphDetails = m_rrdStrategy.createGraphReturnDetails(commandString, m_rrdBaseDirectory);
} catch (Throwable e) {
throw new DataAccessResourceFailureException("Failure when generating graph to get data with command '" + commandString + "'", e);
}
String[] printLines;
try {
printLines = graphDetails.getPrintLines();
} catch (Throwable e) {
throw new DataAccessResourceFailureException("Failure to get print lines from graph after graphing with command '" + commandString + "'", e);
}
if (printLines.length != printFunctions.length) {
throw new DataAccessResourceFailureException("Returned number of print lines should be " + printFunctions.length + ", but was " + printLines.length + " from command: " + commandString);
}
double[] values = new double[printLines.length];
for (int i = 0; i < printLines.length; i++) {
if (printLines[i].toLowerCase().endsWith("nan")) {
values[i] = Double.NaN;
} else {
try {
// To avoid NMS-5592 ~ 2,670374e+03 floating point issue.
values[i] = Double.parseDouble(printLines[i].replace(",", "."));
} catch (NumberFormatException e) {
throw new DataAccessResourceFailureException("Value of line " + (i + 1) + " of output from RRD is not a valid floating point number: '" + printLines[i] + "'");
}
}
}
return values;
}
use of org.opennms.netmgt.model.RrdGraphAttribute in project opennms by OpenNMS.
the class AttributeMatchingResourceVisitorTest method testVisitWithMatch.
public void testVisitWithMatch() throws Exception {
AttributeMatchingResourceVisitor resourceVisitor = new AttributeMatchingResourceVisitor();
resourceVisitor.setAttributeVisitor(m_attributeVisitor);
resourceVisitor.setAttributeMatch("ifInOctets");
resourceVisitor.afterPropertiesSet();
MockResourceType resourceType = new MockResourceType();
resourceType.setName("interfaceSnmp");
OnmsAttribute attribute = new RrdGraphAttribute("ifInOctets", "something", "something else");
OnmsResource resource = new OnmsResource("1", "Node One", resourceType, Collections.singleton(attribute), ResourcePath.get("foo"));
m_attributeVisitor.visit(attribute);
m_mocks.replayAll();
resourceVisitor.visit(resource);
m_mocks.verifyAll();
}
use of org.opennms.netmgt.model.RrdGraphAttribute in project opennms by OpenNMS.
the class ReportDefinitionTest method testUnfilteredResourceAttributeFilteringWithMatch.
public void testUnfilteredResourceAttributeFilteringWithMatch() throws Exception {
OnmsAttribute rrdAttribute = new RrdGraphAttribute("IfInOctets", "something", "something else");
ExternalValueAttribute externalValueAttribute = new ExternalValueAttribute("ifSpeed", "100000000");
Set<OnmsAttribute> attributes = new HashSet<OnmsAttribute>();
attributes.add(rrdAttribute);
attributes.add(externalValueAttribute);
MockResourceType resourceType = new MockResourceType();
resourceType.setName("interfaceSnmp");
OnmsResource resource = new OnmsResource("1", "Node One", resourceType, attributes, ResourcePath.get("foo"));
EasyMock.expect(m_resourceDao.findTopLevelResources()).andReturn(Collections.singletonList(resource));
ReportDefinition def = createReportDefinition();
def.setResourceAttributeKey(externalValueAttribute.getName());
def.setResourceAttributeValueMatch(externalValueAttribute.getValue());
ReportInstance report = def.createReport(m_nodeDao, m_resourceDao, m_fetchStrategy, m_filterDao);
rrdAttribute.setResource(new OnmsResource("1", "Node One", resourceType, Collections.singleton(rrdAttribute), ResourcePath.get("foo")));
Source source = new Source();
source.setLabel("result");
source.setResourceId(rrdAttribute.getResource().getId().toString());
source.setAttribute(rrdAttribute.getName());
source.setAggregation("AVERAGE");
FetchResults results = new FetchResults(new long[] { report.getStartTime() }, Collections.singletonMap("result", new double[] { 100.0 }), report.getEndTime() - report.getStartTime(), Collections.emptyMap());
EasyMock.expect(m_fetchStrategy.fetch(report.getStartTime(), report.getEndTime(), 1, 0, null, null, Collections.singletonList(source), false)).andReturn(results);
m_mocks.replayAll();
report.walk();
m_mocks.verifyAll();
assertEquals("results size", 1, report.getResults().size());
m_mocks.replayAll();
}
use of org.opennms.netmgt.model.RrdGraphAttribute 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");
}
}
Aggregations