/** * Queries the Measuement Api for the last value found in a given timeframe. * * @param resource the resource to be used * @param attribute the attribute to query for * @return the last known value */ public double getLastValue(final String resource, final String attribute) throws MeasurementException { return getLastValue(resource, attribute, "AVERAGE"); }
private Map<String, Object> createContext(final GraphContainer container) { final Map<String, Object> context = Maps.newHashMap(); Optional.ofNullable(Iterables.getOnlyElement(container.getSelectionManager().getSelectedEdgeRefs(), null)) .map(this::createEdgeContext) .ifPresent(context::putAll); Optional.ofNullable(Iterables.getOnlyElement(container.getSelectionManager().getSelectedVertexRefs(), null)) .map(this::createVertexContext) .ifPresent(context::putAll); context.put("measurements", new MeasurementsWrapper(measurementsService)); return context; }
public double getLastValue(final String resource, final String attribute, final String aggregation, boolean relaxed) throws MeasurementException { long end = System.currentTimeMillis(); long start = end - (15 * 60 * 1000); QueryResponse.WrappedPrimitive[] columns = queryInt(resource, attribute, start, end, 300000, aggregation, relaxed).getColumns(); if (columns.length > 0) { double[] values = columns[0].getList(); if (values.length > 0) { for(int i = values.length-1; i >= 0; i--) { if (!Double.isNaN(values[i])) { return values[i]; } } } } return Double.NaN; }
/** * This method computes the utilization of a given interface resource. The method returns two double values * encapsulated in a list. It uses the HC attributes for the computation and non-HC as fallback attributes. * * @param node the node to be used * @param ifName the inteface of the node * @return the in/out percentage utilization encapsulated in a list */ public List<Double> computeUtilization(final OnmsNode node, final String ifName) throws MeasurementException { long end = System.currentTimeMillis(); long start = end - (15 * 60 * 1000); for(OnmsSnmpInterface snmpInterface : node.getSnmpInterfaces()) { if (ifName.equals(snmpInterface.getIfName())) { String resourceId = "node[" + node.getId() + "].interfaceSnmp[" + snmpInterface.computeLabelForRRD() + "]"; return computeUtilization(resourceId, start, end, 300000, "AVERAGE"); } } return Arrays.asList(Double.NaN, Double.NaN); }
private Map<String, Object> createContext(final GraphContainer container) { final Map<String, Object> context = Maps.newHashMap(); Optional.ofNullable(Iterables.getOnlyElement(container.getSelectionManager().getSelectedEdgeRefs(), null)) .map(this::createEdgeContext) .ifPresent(context::putAll); Optional.ofNullable(Iterables.getOnlyElement(container.getSelectionManager().getSelectedVertexRefs(), null)) .map(this::createVertexContext) .ifPresent(context::putAll); context.put("measurements", new MeasurementsWrapper(measurementsService)); return context; }
public double getLastValue(final String resource, final String attribute, final String aggregation, boolean relaxed) throws MeasurementException { long end = System.currentTimeMillis(); long start = end - (15 * 60 * 1000); QueryResponse.WrappedPrimitive[] columns = queryInt(resource, attribute, start, end, 300000, aggregation, relaxed).getColumns(); if (columns.length > 0) { double[] values = columns[0].getList(); if (values.length > 0) { for(int i = values.length-1; i >= 0; i--) { if (!Double.isNaN(values[i])) { return values[i]; } } } } return Double.NaN; }
/** * This method computes the utilization of a given interface resource. The method returns two double values * encapsulated in a list. It uses the HC attributes for the computation and non-HC as fallback attributes. * * @param node the node to be used * @param ifName the inteface of the node * @return the in/out percentage utilization encapsulated in a list */ public List<Double> computeUtilization(final OnmsNode node, final String ifName) throws MeasurementException { long end = System.currentTimeMillis(); long start = end - (15 * 60 * 1000); for(OnmsSnmpInterface snmpInterface : node.getSnmpInterfaces()) { if (ifName.equals(snmpInterface.getIfName())) { String resourceId = "node[" + node.getId() + "].interfaceSnmp[" + snmpInterface.computeLabelForRRD() + "]"; return computeUtilization(resourceId, start, end, 300000, "AVERAGE"); } } return Arrays.asList(Double.NaN, Double.NaN); }
@Override public Map<? extends VertexRef, ? extends Status> getStatusForVertices(final VertexProvider vertexProvider, final Collection<VertexRef> vertices, final Criteria[] criteria) { // All vertices for the current vertexProvider final List<GraphMLVertex> graphMLVertices = vertices.stream() .filter(eachVertex -> contributesTo(eachVertex.getNamespace()) && eachVertex instanceof GraphMLVertex) .map(eachVertex -> (GraphMLVertex) eachVertex) .collect(Collectors.toList()); // Alarm summary for each node id final Map<Integer, AlarmSummary> nodeIdToAlarmSummaryMap = alarmSummaryWrapper.getAlarmSummaries(Lists.transform(graphMLVertices, AbstractVertex::getNodeID)) .stream() .collect(Collectors.toMap(AlarmSummary::getNodeId, Function.identity())); // Calculate status via scripts return serviceAccessor.getTransactionOperations().execute( t -> this.scripting.compute(graphMLVertices.stream(), (vertex) -> { final SimpleBindings bindings = new SimpleBindings(); bindings.put("vertex", vertex); if (vertex.getNodeID() != null) { bindings.put("node", serviceAccessor.getNodeDao().get(vertex.getNodeID())); bindings.put("alarmSummary", nodeIdToAlarmSummaryMap.get(vertex.getNodeID())); } bindings.put("measurements", new MeasurementsWrapper(serviceAccessor.getMeasurementsService())); bindings.put("nodeDao", serviceAccessor.getNodeDao()); bindings.put("snmpInterfaceDao", serviceAccessor.getSnmpInterfaceDao()); return bindings; })); }
/** * Queries the Measurement Api for the last value found in a given timeframe. * * @param resource the resource to be used * @param attribute the attribute to query for * @param aggregation the aggregation method * @return the last known value */ public double getLastValue(final String resource, final String attribute, final String aggregation) throws MeasurementException { return getLastValue(resource, attribute, aggregation, true); }
/** * A method to query the Measurements Api for a given resource/attribute. * * @param resource the resource to be used * @param attribute the attribute to query for * @param start the start timestamp * @param end the end timestamp * @param step the step size * @param aggregation the aggregation method * @return the list of double values */ public List<Double> query(final String resource, final String attribute, final long start, final long end, final long step, final String aggregation, final boolean relaxed) throws MeasurementException { QueryResponse.WrappedPrimitive[] columns = queryInt(resource, attribute, start, end, step, aggregation, relaxed).getColumns(); if (columns.length > 0) { return Doubles.asList(columns[0].getList()); } return Collections.emptyList(); }
@Override public Map<? extends VertexRef, ? extends Status> getStatusForVertices(final VertexProvider vertexProvider, final Collection<VertexRef> vertices, final Criteria[] criteria) { // All vertices for the current vertexProvider final List<GraphMLVertex> graphMLVertices = vertices.stream() .filter(eachVertex -> contributesTo(eachVertex.getNamespace()) && eachVertex instanceof GraphMLVertex) .map(eachVertex -> (GraphMLVertex) eachVertex) .collect(Collectors.toList()); // Alarm summary for each node id final Map<Integer, AlarmSummary> nodeIdToAlarmSummaryMap = alarmSummaryWrapper.getAlarmSummaries(Lists.transform(graphMLVertices, AbstractVertex::getNodeID)) .stream() .collect(Collectors.toMap(AlarmSummary::getNodeId, Function.identity())); // Calculate status via scripts return serviceAccessor.getTransactionOperations().execute( t -> this.scripting.compute(graphMLVertices.stream(), (vertex) -> { final SimpleBindings bindings = new SimpleBindings(); bindings.put("vertex", vertex); if (vertex.getNodeID() != null) { bindings.put("node", serviceAccessor.getNodeDao().get(vertex.getNodeID())); bindings.put("alarmSummary", nodeIdToAlarmSummaryMap.get(vertex.getNodeID())); } bindings.put("measurements", new MeasurementsWrapper(serviceAccessor.getMeasurementsService())); bindings.put("nodeDao", serviceAccessor.getNodeDao()); bindings.put("snmpInterfaceDao", serviceAccessor.getSnmpInterfaceDao()); return bindings; })); }
/** * Queries the Measuement Api for the last value found in a given timeframe. * * @param resource the resource to be used * @param attribute the attribute to query for * @return the last known value */ public double getLastValue(final String resource, final String attribute) throws MeasurementException { return getLastValue(resource, attribute, "AVERAGE"); }
/** * A method to query the Measurements Api for a given resource/attribute. * * @param resource the resource to be used * @param attribute the attribute to query for * @param start the start timestamp * @param end the end timestamp * @param step the step size * @param aggregation the aggregation method * @return the list of double values */ public List<Double> query(final String resource, final String attribute, final long start, final long end, final long step, final String aggregation, final boolean relaxed) throws MeasurementException { QueryResponse.WrappedPrimitive[] columns = queryInt(resource, attribute, start, end, step, aggregation, relaxed).getColumns(); if (columns.length > 0) { return Doubles.asList(columns[0].getList()); } return Collections.emptyList(); }
@Override public Map<? extends EdgeRef, ? extends Status> getStatusForEdges(EdgeProvider edgeProvider, Collection<EdgeRef> edges, Criteria[] criteria) { return serviceAccessor.getTransactionOperations().execute( t -> this.scripting.compute(edges.stream() .filter(edge -> edge instanceof GraphMLEdge) .map(edge -> (GraphMLEdge) edge), (edge) -> { final SimpleBindings bindings = new SimpleBindings(); bindings.put("edge", edge); bindings.put("sourceNode", getNodeForEdgeVertexConnector(edge.getSource())); bindings.put("targetNode", getNodeForEdgeVertexConnector(edge.getTarget())); bindings.put("measurements", new MeasurementsWrapper(serviceAccessor.getMeasurementsService())); bindings.put("nodeDao", serviceAccessor.getNodeDao()); bindings.put("snmpInterfaceDao", serviceAccessor.getSnmpInterfaceDao()); return bindings; })); }
/** * Queries the Measurement Api for the last value found in a given timeframe. * * @param resource the resource to be used * @param attribute the attribute to query for * @param aggregation the aggregation method * @return the last known value */ public double getLastValue(final String resource, final String attribute, final String aggregation) throws MeasurementException { return getLastValue(resource, attribute, aggregation, true); }
@Override public Map<? extends EdgeRef, ? extends Status> getStatusForEdges(EdgeProvider edgeProvider, Collection<EdgeRef> edges, Criteria[] criteria) { return serviceAccessor.getTransactionOperations().execute( t -> this.scripting.compute(edges.stream() .filter(edge -> edge instanceof GraphMLEdge) .map(edge -> (GraphMLEdge) edge), (edge) -> { final SimpleBindings bindings = new SimpleBindings(); bindings.put("edge", edge); bindings.put("sourceNode", getNodeForEdgeVertexConnector(edge.getSource())); bindings.put("targetNode", getNodeForEdgeVertexConnector(edge.getTarget())); bindings.put("measurements", new MeasurementsWrapper(serviceAccessor.getMeasurementsService())); bindings.put("nodeDao", serviceAccessor.getNodeDao()); bindings.put("snmpInterfaceDao", serviceAccessor.getSnmpInterfaceDao()); return bindings; })); }