Search in sources :

Example 11 with ControlPlaneMonitorService

use of org.onosproject.cpman.ControlPlaneMonitorService in project onos by opennetworkinglab.

the class ControlMetricsWebResource method controlMessageMetrics.

/**
 * Returns control message metrics of a given device.
 *
 * @param deviceId device identification
 * @return control message metrics of a given device
 * @onos.rsModel ControlMessageMetric
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("messages/{deviceId}")
public Response controlMessageMetrics(@PathParam("deviceId") String deviceId) {
    ObjectNode root = mapper().createObjectNode();
    ControlPlaneMonitorService monitorService = get(ControlPlaneMonitorService.class);
    ClusterService clusterService = get(ClusterService.class);
    NodeId localNodeId = clusterService.getLocalNode().id();
    metricsStats(monitorService, localNodeId, CONTROL_MESSAGE_METRICS, DeviceId.deviceId(deviceId), root);
    return ok(root).build();
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ControlPlaneMonitorService(org.onosproject.cpman.ControlPlaneMonitorService) NodeId(org.onosproject.cluster.NodeId) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 12 with ControlPlaneMonitorService

use of org.onosproject.cpman.ControlPlaneMonitorService 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 13 with ControlPlaneMonitorService

use of org.onosproject.cpman.ControlPlaneMonitorService in project onos by opennetworkinglab.

the class ControlMetricsStatsListCommand method printMetricsStats.

/**
 * Prints control plane metric statistic information.
 *
 * @param service monitor service
 * @param nodeId  node identifier
 * @param typeSet control metric type
 * @param resName resource name
 * @param did     device identifier
 */
private void printMetricsStats(ControlPlaneMonitorService service, NodeId nodeId, Set<ControlMetricType> typeSet, String resName, DeviceId did) {
    if (resName == null && did == null) {
        typeSet.forEach(s -> {
            ControlLoadSnapshot cls = service.getLoadSync(nodeId, s, Optional.empty());
            printControlLoadSnapshot(s, cls);
        });
    } else if (resName == null) {
        typeSet.forEach(s -> {
            ControlLoadSnapshot cls = service.getLoadSync(nodeId, s, Optional.of(did));
            printControlLoadSnapshot(s, cls);
        });
    } else if (did == null) {
        typeSet.forEach(s -> {
            ControlLoadSnapshot cls = service.getLoadSync(nodeId, s, resName);
            printControlLoadSnapshot(s, cls);
        });
    }
}
Also used : NodeId(org.onosproject.cluster.NodeId) ControlMetricType(org.onosproject.cpman.ControlMetricType) CONTROL_MESSAGE_METRICS(org.onosproject.cpman.ControlResource.CONTROL_MESSAGE_METRICS) NETWORK_METRICS(org.onosproject.cpman.ControlResource.NETWORK_METRICS) Set(java.util.Set) Argument(org.apache.karaf.shell.api.action.Argument) Command(org.apache.karaf.shell.api.action.Command) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) ControlLoadSnapshot(org.onosproject.cpman.ControlLoadSnapshot) NodeIdCompleter(org.onosproject.cli.NodeIdCompleter) MEMORY_METRICS(org.onosproject.cpman.ControlResource.MEMORY_METRICS) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Optional(java.util.Optional) DISK_METRICS(org.onosproject.cpman.ControlResource.DISK_METRICS) Completion(org.apache.karaf.shell.api.action.Completion) DeviceId(org.onosproject.net.DeviceId) ControlPlaneMonitorService(org.onosproject.cpman.ControlPlaneMonitorService) CPU_METRICS(org.onosproject.cpman.ControlResource.CPU_METRICS) ControlLoadSnapshot(org.onosproject.cpman.ControlLoadSnapshot)

Example 14 with ControlPlaneMonitorService

use of org.onosproject.cpman.ControlPlaneMonitorService in project onos by opennetworkinglab.

the class ResourceNameCompleter method complete.

@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    // delegate string completer
    StringsCompleter delegate = new StringsCompleter();
    // Resource type is the second argument.
    String nodeId = commandLine.getArguments()[1];
    String type = commandLine.getArguments()[2];
    if (resourceTypes.contains(type)) {
        ControlPlaneMonitorService monitorService = AbstractShellCommand.get(ControlPlaneMonitorService.class);
        Set<String> set = Sets.newHashSet();
        switch(type) {
            case NETWORK:
                set = monitorService.availableResourcesSync(NodeId.nodeId(nodeId), ControlResource.Type.NETWORK);
                break;
            case DISK:
                set = monitorService.availableResourcesSync(NodeId.nodeId(nodeId), ControlResource.Type.DISK);
                break;
            case CONTROL_MESSAGE:
                set = monitorService.availableResourcesSync(NodeId.nodeId(nodeId), ControlResource.Type.CONTROL_MESSAGE);
                break;
            default:
                log.warn(INVALID_MSG);
                break;
        }
        SortedSet<String> strings = delegate.getStrings();
        if (!set.isEmpty()) {
            set.forEach(strings::add);
        }
    }
    return delegate.complete(session, commandLine, candidates);
}
Also used : StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) ControlPlaneMonitorService(org.onosproject.cpman.ControlPlaneMonitorService)

Aggregations

ControlPlaneMonitorService (org.onosproject.cpman.ControlPlaneMonitorService)14 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)11 Path (javax.ws.rs.Path)11 NodeId (org.onosproject.cluster.NodeId)9 GET (javax.ws.rs.GET)7 Produces (javax.ws.rs.Produces)7 ClusterService (org.onosproject.cluster.ClusterService)7 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)6 IOException (java.io.IOException)4 Consumes (javax.ws.rs.Consumes)4 POST (javax.ws.rs.POST)4 MetricsService (org.onlab.metrics.MetricsService)4 ControlMetric (org.onosproject.cpman.ControlMetric)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Optional (java.util.Optional)2 Set (java.util.Set)2 ControlLoadSnapshot (org.onosproject.cpman.ControlLoadSnapshot)2 ControlMetricType (org.onosproject.cpman.ControlMetricType)2 CONTROL_MESSAGE_METRICS (org.onosproject.cpman.ControlResource.CONTROL_MESSAGE_METRICS)2 CPU_METRICS (org.onosproject.cpman.ControlResource.CPU_METRICS)2