Search in sources :

Example 6 with MetricsService

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());
}
Also used : Counter(com.codahale.metrics.Counter) MetricsService(org.onlab.metrics.MetricsService)

Example 7 with MetricsService

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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ControlPlaneMonitorService(org.onosproject.cpman.ControlPlaneMonitorService) MetricsService(org.onlab.metrics.MetricsService) ControlMetric(org.onosproject.cpman.ControlMetric) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 8 with MetricsService

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));
        }
    });
}
Also used : MetricFilter(com.codahale.metrics.MetricFilter) MetricsService(org.onlab.metrics.MetricsService) Metric(com.codahale.metrics.Metric)

Aggregations

MetricsService (org.onlab.metrics.MetricsService)8 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 IOException (java.io.IOException)4 Consumes (javax.ws.rs.Consumes)4 POST (javax.ws.rs.POST)4 Path (javax.ws.rs.Path)4 ControlMetric (org.onosproject.cpman.ControlMetric)4 ControlPlaneMonitorService (org.onosproject.cpman.ControlPlaneMonitorService)4 Counter (com.codahale.metrics.Counter)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 Metric (com.codahale.metrics.Metric)1 MetricFilter (com.codahale.metrics.MetricFilter)1 MetricsComponent (org.onlab.metrics.MetricsComponent)1 MetricsFeature (org.onlab.metrics.MetricsFeature)1