Search in sources :

Example 1 with ControlMetricType

use of org.onosproject.cpman.ControlMetricType 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 ControlMetricType

use of org.onosproject.cpman.ControlMetricType 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)

Example 3 with ControlMetricType

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

the class SystemMetricsAggregator method getMeterMap.

private Map<ControlMetricType, Meter> getMeterMap(Set<ControlMetricType> types, MetricsComponent component, MetricsService service) {
    Map<ControlMetricType, Meter> meterMap = Maps.newHashMap();
    types.forEach(type -> {
        MetricsFeature metricsFeature = component.registerFeature(type.toString());
        Meter meter = service.createMeter(component, metricsFeature, DEFAULT_METER_SUFFIX);
        meterMap.putIfAbsent(type, meter);
    });
    return meterMap;
}
Also used : ControlMetricType(org.onosproject.cpman.ControlMetricType) Meter(com.codahale.metrics.Meter) MetricsFeature(org.onlab.metrics.MetricsFeature)

Example 4 with ControlMetricType

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

the class SystemMetricsAggregator method addMetrics.

/**
 * Adds a set of new monitoring metric types.
 *
 * @param optResourceName optional resource name, null denotes system metric
 * @param resType         resource type
 */
public void addMetrics(Optional<String> optResourceName, String resType) {
    Set<ControlMetricType> metricTypeSet = Sets.newHashSet();
    String resourceName = optResourceName.isPresent() ? optResourceName.get() : DEFAULT_RESOURCE_NAME;
    MetricsComponent metricsComponent = metricsService.registerComponent(resourceName);
    if (optResourceName.isPresent()) {
        if (!diskMap.containsKey(resourceName) && DISK_RESOURCE_TYPE.equals(resType)) {
            metricTypeSet.addAll(ControlResource.DISK_METRICS);
            diskMap.putIfAbsent(resourceName, getMeterMap(metricTypeSet, metricsComponent, metricsService));
            metricsService.notifyReporters();
        } else if (!networkMap.containsKey(resourceName) && NETWORK_RESOURCE_TYPE.equals(resType)) {
            metricTypeSet.addAll(ControlResource.NETWORK_METRICS);
            networkMap.putIfAbsent(resourceName, getMeterMap(metricTypeSet, metricsComponent, metricsService));
            metricsService.notifyReporters();
        } else {
            return;
        }
    } else {
        if (systemMap.isEmpty()) {
            metricTypeSet.addAll(ControlResource.MEMORY_METRICS);
            metricTypeSet.addAll(ControlResource.CPU_METRICS);
            systemMap.putAll(getMeterMap(metricTypeSet, metricsComponent, metricsService));
            metricsService.notifyReporters();
        }
    }
}
Also used : ControlMetricType(org.onosproject.cpman.ControlMetricType) MetricsComponent(org.onlab.metrics.MetricsComponent)

Aggregations

ControlMetricType (org.onosproject.cpman.ControlMetricType)4 Optional (java.util.Optional)2 Set (java.util.Set)2 NodeId (org.onosproject.cluster.NodeId)2 ControlLoadSnapshot (org.onosproject.cpman.ControlLoadSnapshot)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 Meter (com.codahale.metrics.Meter)1 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