use of org.onlab.metrics.MetricsService in project onos by opennetworkinglab.
the class PacketStatisticsShowCommand method doExecute.
@Override
protected void doExecute() {
MetricsService service = get(MetricsService.class);
Map<String, Counter> counters = service.getCounters(filter);
Counter arpCounter = counters.get("packetStatisticsComponent.arpFeature.arpPC");
Counter lldpCounter = counters.get("packetStatisticsComponent.lldpFeature.lldpPC");
Counter nsCounter = counters.get("packetStatisticsComponent.nbrSolicitFeature.nbrSolicitPC");
Counter naCounter = counters.get("packetStatisticsComponent.nbrAdvertFeature.nbrAdvertPC");
print(FORMAT, "ARP ", arpCounter.getCount());
print(FORMAT, "LLDP ", lldpCounter.getCount());
print(FORMAT, "Neighbor Solicitation ", nsCounter.getCount());
print(FORMAT, "Neighbor Advertisement ", naCounter.getCount());
}
use of org.onlab.metrics.MetricsService in project onos by opennetworkinglab.
the class SystemMetricsCollectorWebResource method networkMetrics.
/**
* Collects network metrics.
*
* @param stream JSON stream
* @return 200 OK
* @onos.rsModel NetworkMetricsPost
*/
@POST
@Path("network_metrics")
@Consumes(MediaType.APPLICATION_JSON)
public Response networkMetrics(InputStream stream) {
ObjectNode root = mapper().createObjectNode();
ControlPlaneMonitorService monitorService = get(ControlPlaneMonitorService.class);
MetricsService metricsService = get(MetricsService.class);
ControlMetric cm;
try {
ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
ArrayNode networkRes = jsonTree.get("networks") == null ? mapper().createArrayNode() : (ArrayNode) jsonTree.get("networks");
for (JsonNode node : networkRes) {
JsonNode resourceName = node.get("resourceName");
nullIsIllegal(resourceName, INVALID_RESOURCE_NAME);
aggregator.setMetricsService(metricsService);
aggregator.addMetrics(Optional.of(resourceName.asText()), NETWORK_TYPE);
long inBytes = nullIsIllegal(node.get("incomingBytes").asLong(), INVALID_REQUEST);
long outBytes = nullIsIllegal(node.get("outgoingBytes").asLong(), INVALID_REQUEST);
long inPackets = nullIsIllegal(node.get("incomingPackets").asLong(), INVALID_REQUEST);
long outPackets = nullIsIllegal(node.get("outgoingPackets").asLong(), INVALID_REQUEST);
cm = new ControlMetric(ControlMetricType.NW_INCOMING_BYTES, new MetricValue.Builder().load(inBytes).add());
monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, resourceName.asText());
aggregator.increment(resourceName.asText(), NETWORK_TYPE, ControlMetricType.NW_INCOMING_BYTES, inBytes);
cm = new ControlMetric(ControlMetricType.NW_OUTGOING_BYTES, new MetricValue.Builder().load(outBytes).add());
monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, resourceName.asText());
aggregator.increment(resourceName.asText(), NETWORK_TYPE, ControlMetricType.NW_OUTGOING_BYTES, outBytes);
cm = new ControlMetric(ControlMetricType.NW_INCOMING_PACKETS, new MetricValue.Builder().load(inPackets).add());
monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, resourceName.asText());
aggregator.increment(resourceName.asText(), NETWORK_TYPE, ControlMetricType.NW_INCOMING_PACKETS, inPackets);
cm = new ControlMetric(ControlMetricType.NW_OUTGOING_PACKETS, new MetricValue.Builder().load(outPackets).add());
monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, resourceName.asText());
aggregator.increment(resourceName.asText(), NETWORK_TYPE, ControlMetricType.NW_OUTGOING_PACKETS, outPackets);
}
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
return ok(root).build();
}
use of org.onlab.metrics.MetricsService in project onos by opennetworkinglab.
the class MetricsListCommand method doExecute.
@Override
protected void doExecute() {
MetricsService metricsService = get(MetricsService.class);
MetricFilter filter = metricName != null ? (name, metric) -> name.equals(metricName) : MetricFilter.ALL;
TreeMultimap<String, Metric> matched = listMetrics(metricsService, filter);
matched.asMap().forEach((name, metrics) -> {
if (outputJson()) {
metrics.forEach(metric -> print("%s", json(metric)));
} else {
metrics.forEach(metric -> printMetric(name, metric));
}
});
}
Aggregations