@Override public boolean contributesTo(GraphContainer container) { T ref = findSingleSelectedItem(container); if (ref != null) { return contributesTo(ref, container); } return false; }
/** * 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"); }
@Override public Component getComponent(GraphContainer container) { T ref = findSingleSelectedItem(container); Preconditions.checkState(ref != null, NOTHING_SELECTED); return getComponent(ref, container); }
@Override public Collection<InfoPanelItem> getContributions(GraphContainer container) { return InfoPanelItemProvider.contributeIf( SimulationAwareStateMachineFactory.isInSimulationMode(container.getCriteria()), () -> new DefaultInfoPanelItem() .withOrder(Integer.MIN_VALUE) .withComponent(createComponent())); } }
@Override public Collection<? extends InfoPanelItem> getContributions(GraphContainer container) { return findSingleSelectedItem(container) .filter(ref -> contributeTo(ref, container)) .map(ref -> Collections.singleton(createInfoPanelItem(ref, container))) .orElseGet(Collections::emptySet); }
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; }
@Override public String getTitle(GraphContainer container) { T ref = findSingleSelectedItem(container); Preconditions.checkState(ref != null, NOTHING_SELECTED); return getTitle(ref); }
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 Collection<? extends InfoPanelItem> getContributions(GraphContainer container) { return findSingleSelectedItem(container) .filter(ref -> contributeTo(ref, container)) .map(ref -> Collections.singleton(createInfoPanelItem(ref, container))) .orElseGet(Collections::emptySet); }
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; }
/** * 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); }
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 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 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(); }
/** * 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(); }