Search in sources :

Example 1 with ControlLoadSnapshot

use of org.onosproject.cpman.ControlLoadSnapshot 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 2 with ControlLoadSnapshot

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

the class ControlPlaneMonitor method handleMetricsRequest.

/**
 * Handles control metric request from remote node.
 *
 * @param request control metric request
 * @return completable future object of control load snapshot
 */
private CompletableFuture<ControlLoadSnapshot> handleMetricsRequest(ControlMetricsRequest request) {
    checkArgument(request.getType() != null, METRIC_TYPE_NULL);
    ControlLoad load;
    if (request.getResourceName() != null && request.getUnit() != null) {
        load = getLocalLoad(request.getType(), request.getResourceName());
    } else {
        load = getLocalLoad(request.getType(), request.getDeviceId());
    }
    long average;
    if (request.getUnit() != null) {
        average = load.average(request.getDuration(), request.getUnit());
    } else {
        average = load.average();
    }
    ControlLoadSnapshot resp = new ControlLoadSnapshot(load.latest(), average, load.time());
    return CompletableFuture.completedFuture(resp);
}
Also used : ControlLoadSnapshot(org.onosproject.cpman.ControlLoadSnapshot) ControlLoad(org.onosproject.cpman.ControlLoad)

Example 3 with ControlLoadSnapshot

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

the class ControlMetricsWebResource method metricsStats.

/**
 * Returns a collection of control loads of the given control metric types.
 *
 * @param service control plane monitoring service
 * @param nodeId  node identification
 * @param typeSet a group of control metric types
 * @param name    resource name
 * @param did     device identification
 * @return a collection of control loads
 */
private ArrayNode metricsStats(ControlPlaneMonitorService service, NodeId nodeId, Set<ControlMetricType> typeSet, String name, DeviceId did, ObjectNode node) {
    ArrayNode metricsNode = node.putArray("metrics");
    if (name == null && did == null) {
        typeSet.forEach(type -> {
            ControlLoadSnapshot cls = service.getLoadSync(nodeId, type, Optional.empty());
            processRest(cls, type, metricsNode);
        });
    } else if (name == null) {
        typeSet.forEach(type -> {
            ControlLoadSnapshot cls = service.getLoadSync(nodeId, type, Optional.of(did));
            processRest(cls, type, metricsNode);
        });
    } else if (did == null) {
        typeSet.forEach(type -> {
            ControlLoadSnapshot cls = service.getLoadSync(nodeId, type, name);
            processRest(cls, type, metricsNode);
        });
    }
    return metricsNode;
}
Also used : PathParam(javax.ws.rs.PathParam) AbstractWebResource(org.onosproject.rest.AbstractWebResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CONTROL_MESSAGE_METRICS(org.onosproject.cpman.ControlResource.CONTROL_MESSAGE_METRICS) Path(javax.ws.rs.Path) StringUtils(org.apache.commons.lang3.StringUtils) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) NETWORK(org.onosproject.cpman.ControlResource.Type.NETWORK) MediaType(javax.ws.rs.core.MediaType) MEMORY_METRICS(org.onosproject.cpman.ControlResource.MEMORY_METRICS) CPU_METRICS(org.onosproject.cpman.ControlResource.CPU_METRICS) NodeId(org.onosproject.cluster.NodeId) DISK(org.onosproject.cpman.ControlResource.Type.DISK) ControlMetricType(org.onosproject.cpman.ControlMetricType) NETWORK_METRICS(org.onosproject.cpman.ControlResource.NETWORK_METRICS) Set(java.util.Set) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ControlLoadSnapshot(org.onosproject.cpman.ControlLoadSnapshot) Response(javax.ws.rs.core.Response) Optional(java.util.Optional) DISK_METRICS(org.onosproject.cpman.ControlResource.DISK_METRICS) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) CONTROL_MESSAGE(org.onosproject.cpman.ControlResource.Type.CONTROL_MESSAGE) ControlPlaneMonitorService(org.onosproject.cpman.ControlPlaneMonitorService) ControlLoadSnapshot(org.onosproject.cpman.ControlLoadSnapshot) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

ControlLoadSnapshot (org.onosproject.cpman.ControlLoadSnapshot)3 Optional (java.util.Optional)2 Set (java.util.Set)2 NodeId (org.onosproject.cluster.NodeId)2 ControlMetricType (org.onosproject.cpman.ControlMetricType)2 ControlPlaneMonitorService (org.onosproject.cpman.ControlPlaneMonitorService)2 CONTROL_MESSAGE_METRICS (org.onosproject.cpman.ControlResource.CONTROL_MESSAGE_METRICS)2 CPU_METRICS (org.onosproject.cpman.ControlResource.CPU_METRICS)2 DISK_METRICS (org.onosproject.cpman.ControlResource.DISK_METRICS)2 MEMORY_METRICS (org.onosproject.cpman.ControlResource.MEMORY_METRICS)2 NETWORK_METRICS (org.onosproject.cpman.ControlResource.NETWORK_METRICS)2 DeviceId (org.onosproject.net.DeviceId)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 PathParam (javax.ws.rs.PathParam)1 Produces (javax.ws.rs.Produces)1 MediaType (javax.ws.rs.core.MediaType)1 Response (javax.ws.rs.core.Response)1