Search in sources :

Example 16 with PortStatistics

use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.

the class ServerDevicesDiscovery method getGlobalMonitoringStatistics.

/**
 * Query a server to retrieve its global monitoring statistics.
 *
 * @param deviceId the device ID to be queried
 * @return global monitoring statistics
 */
public MonitoringStatistics getGlobalMonitoringStatistics(DeviceId deviceId) {
    // Monitoring statistics to return
    MonitoringStatistics monStats = null;
    RestServerSBDevice device = null;
    try {
        device = (RestServerSBDevice) getDevice(deviceId);
    } catch (ClassCastException ccEx) {
        log.error("Failed to retrieve global monitoring statistics from device {}", deviceId);
        return monStats;
    }
    if ((device == null) || (!device.isActive())) {
        return monStats;
    }
    // Hit the path that provides the server's global resources
    InputStream response = null;
    try {
        response = getController().get(deviceId, URL_SRV_GLOBAL_STATS, JSON);
    } catch (ProcessingException pEx) {
        log.error("Failed to retrieve global monitoring statistics from device {}", deviceId);
        raiseDeviceDisconnect(device);
        return monStats;
    }
    // Load the JSON into objects
    ObjectMapper mapper = new ObjectMapper();
    Map<String, Object> jsonMap = null;
    ObjectNode objNode = null;
    try {
        jsonMap = mapper.readValue(response, Map.class);
        JsonNode jsonNode = mapper.convertValue(jsonMap, JsonNode.class);
        objNode = (ObjectNode) jsonNode;
    } catch (IOException ioEx) {
        log.error("Failed to retrieve global monitoring statistics from device {}", deviceId);
        raiseDeviceDisconnect(device);
        return monStats;
    }
    if (jsonMap == null) {
        log.error("Failed to retrieve global monitoring statistics from device {}", deviceId);
        raiseDeviceDisconnect(device);
        return monStats;
    }
    // Get high-level CPU statistics
    int busyCpus = objNode.path(PARAM_MON_BUSY_CPUS).asInt();
    int freeCpus = objNode.path(PARAM_MON_FREE_CPUS).asInt();
    // Get a list of CPU statistics per core
    Collection<CpuStatistics> cpuStats = parseCpuStatistics(deviceId, objNode);
    // Get main memory statistics
    MemoryStatistics memStats = parseMemoryStatistics(deviceId, objNode);
    // Get a list of port statistics
    Collection<PortStatistics> nicStats = parseNicStatistics(deviceId, objNode);
    // Get zero timing statistics
    TimingStatistics timinsgStats = getZeroTimingStatistics();
    // Construct a global monitoring statistics object out of smaller ones
    monStats = DefaultMonitoringStatistics.builder().setDeviceId(deviceId).setTimingStatistics(timinsgStats).setCpuStatistics(cpuStats).setMemoryStatistics(memStats).setNicStatistics(nicStats).build();
    // When a device reports monitoring data, it means it is alive
    raiseDeviceReconnect(device);
    log.debug("Global monitoring statistics: {}", monStats.toString());
    return monStats;
}
Also used : DefaultTimingStatistics(org.onosproject.drivers.server.impl.stats.DefaultTimingStatistics) TimingStatistics(org.onosproject.drivers.server.stats.TimingStatistics) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DefaultMonitoringStatistics(org.onosproject.drivers.server.impl.stats.DefaultMonitoringStatistics) MonitoringStatistics(org.onosproject.drivers.server.stats.MonitoringStatistics) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) DefaultRestServerSBDevice(org.onosproject.drivers.server.impl.devices.DefaultRestServerSBDevice) RestServerSBDevice(org.onosproject.drivers.server.devices.RestServerSBDevice) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) PortStatistics(org.onosproject.net.device.PortStatistics) MemoryStatistics(org.onosproject.drivers.server.stats.MemoryStatistics) DefaultMemoryStatistics(org.onosproject.drivers.server.impl.stats.DefaultMemoryStatistics) DefaultCpuStatistics(org.onosproject.drivers.server.impl.stats.DefaultCpuStatistics) CpuStatistics(org.onosproject.drivers.server.stats.CpuStatistics) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProcessingException(javax.ws.rs.ProcessingException)

Example 17 with PortStatistics

use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.

the class PortStatisticsDiscoveryImpl method discoverPortStatistics.

@Override
public Collection<PortStatistics> discoverPortStatistics() {
    DeviceService deviceService = this.handler().get(DeviceService.class);
    DeviceId deviceId = this.data().deviceId();
    PiPipeconfService piPipeconfService = handler().get(PiPipeconfService.class);
    if (!piPipeconfService.ofDevice(deviceId).isPresent() || !piPipeconfService.getPipeconf(piPipeconfService.ofDevice(deviceId).get()).isPresent()) {
        log.warn("Unable to get the pipeconf of {}, aborting operation", deviceId);
        return Collections.emptyList();
    }
    PiPipeconf pipeconf = piPipeconfService.getPipeconf(piPipeconfService.ofDevice(deviceId).get()).get();
    P4RuntimeController controller = handler().get(P4RuntimeController.class);
    P4RuntimeClient client = controller.get(deviceId);
    if (client == null) {
        log.warn("Unable to find client for {}, aborting operation", deviceId);
        return Collections.emptyList();
    }
    Map<Long, DefaultPortStatistics.Builder> portStatBuilders = Maps.newHashMap();
    deviceService.getPorts(deviceId).forEach(p -> portStatBuilders.put(p.number().toLong(), DefaultPortStatistics.builder().setPort(p.number()).setDeviceId(deviceId).setDurationSec(getDuration(p.number()))));
    Set<PiCounterCellId> counterCellIds = Sets.newHashSet();
    portStatBuilders.keySet().forEach(p -> {
        // Counter cell/index = port number.
        counterCellIds.add(PiCounterCellId.ofIndirect(ingressCounterId(), p));
        counterCellIds.add(PiCounterCellId.ofIndirect(egressCounterId(), p));
    });
    Set<PiCounterCellHandle> counterCellHandles = counterCellIds.stream().map(id -> PiCounterCellHandle.of(deviceId, id)).collect(Collectors.toSet());
    // Query the device.
    Collection<PiCounterCell> counterEntryResponse = client.read(DEFAULT_P4_DEVICE_ID, pipeconf).handles(counterCellHandles).submitSync().all(PiCounterCell.class);
    counterEntryResponse.forEach(counterCell -> {
        if (counterCell.cellId().counterType() != INDIRECT) {
            log.warn("Invalid counter data type {}, skipping", counterCell.cellId().counterType());
            return;
        }
        PiCounterCellId indCellId = counterCell.cellId();
        if (!portStatBuilders.containsKey(indCellId.index())) {
            log.warn("Unrecognized counter index {}, skipping", counterCell);
            return;
        }
        DefaultPortStatistics.Builder statsBuilder = portStatBuilders.get(indCellId.index());
        if (counterCell.cellId().counterId().equals(ingressCounterId())) {
            statsBuilder.setPacketsReceived(counterCell.data().packets());
            statsBuilder.setBytesReceived(counterCell.data().bytes());
        } else if (counterCell.cellId().counterId().equals(egressCounterId())) {
            statsBuilder.setPacketsSent(counterCell.data().packets());
            statsBuilder.setBytesSent(counterCell.data().bytes());
        } else {
            log.warn("Unrecognized counter ID {}, skipping", counterCell);
        }
    });
    return portStatBuilders.values().stream().map(DefaultPortStatistics.Builder::build).collect(Collectors.toList());
}
Also used : INGRESS_PORT_COUNTERS_INGRESS_INGRESS_PORT_COUNTER(org.onosproject.pipelines.basic.BasicConstants.INGRESS_PORT_COUNTERS_INGRESS_INGRESS_PORT_COUNTER) PiPipeconfService(org.onosproject.net.pi.service.PiPipeconfService) PortStatistics(org.onosproject.net.device.PortStatistics) PiCounterId(org.onosproject.net.pi.model.PiCounterId) PiPipeconf(org.onosproject.net.pi.model.PiPipeconf) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) PiCounterCellHandle(org.onosproject.net.pi.runtime.PiCounterCellHandle) Pair(org.apache.commons.lang3.tuple.Pair) P4RuntimeController(org.onosproject.p4runtime.api.P4RuntimeController) Map(java.util.Map) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) PortStatisticsDiscovery(org.onosproject.net.device.PortStatisticsDiscovery) PiCounterCellId(org.onosproject.net.pi.runtime.PiCounterCellId) Logger(org.slf4j.Logger) INDIRECT(org.onosproject.net.pi.model.PiCounterType.INDIRECT) P4RuntimeClient(org.onosproject.p4runtime.api.P4RuntimeClient) Collection(java.util.Collection) Set(java.util.Set) PiCounterCell(org.onosproject.net.pi.runtime.PiCounterCell) EGRESS_PORT_COUNTERS_EGRESS_EGRESS_PORT_COUNTER(org.onosproject.pipelines.basic.BasicConstants.EGRESS_PORT_COUNTERS_EGRESS_EGRESS_PORT_COUNTER) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) PiCounterCellId(org.onosproject.net.pi.runtime.PiCounterCellId) PiCounterCellHandle(org.onosproject.net.pi.runtime.PiCounterCellHandle) DeviceId(org.onosproject.net.DeviceId) PiPipeconf(org.onosproject.net.pi.model.PiPipeconf) DeviceService(org.onosproject.net.device.DeviceService) PiPipeconfService(org.onosproject.net.pi.service.PiPipeconfService) P4RuntimeClient(org.onosproject.p4runtime.api.P4RuntimeClient) P4RuntimeController(org.onosproject.p4runtime.api.P4RuntimeController) PiCounterCell(org.onosproject.net.pi.runtime.PiCounterCell)

Example 18 with PortStatistics

use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.

the class StatisticsWebResource method getPortStatistics.

/**
 * Gets port statistics of all devices.
 * @onos.rsModel StatisticsPorts
 * @return 200 OK with JSON encoded array of port statistics
 */
@GET
@Path("ports")
@Produces(MediaType.APPLICATION_JSON)
public Response getPortStatistics() {
    final DeviceService service = get(DeviceService.class);
    final Iterable<Device> devices = service.getDevices();
    final ObjectNode root = mapper().createObjectNode();
    final ArrayNode rootArrayNode = root.putArray("statistics");
    for (final Device device : devices) {
        final ObjectNode deviceStatsNode = mapper().createObjectNode();
        deviceStatsNode.put("device", device.id().toString());
        final ArrayNode statisticsNode = deviceStatsNode.putArray("ports");
        final Iterable<PortStatistics> portStatsEntries = service.getPortStatistics(device.id());
        if (portStatsEntries != null) {
            for (final PortStatistics entry : portStatsEntries) {
                statisticsNode.add(codec(PortStatistics.class).encode(entry, this));
            }
        }
        rootArrayNode.add(deviceStatsNode);
    }
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PortStatistics(org.onosproject.net.device.PortStatistics) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 19 with PortStatistics

use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.

the class StatisticsWebResource method getPortDeltaStatistics.

/**
 * Gets port delta statistics of all devices.
 * @onos.rsModel StatisticsPorts
 * @return 200 OK with JSON encoded array of port delta statistics
 */
@GET
@Path("delta/ports")
@Produces(MediaType.APPLICATION_JSON)
public Response getPortDeltaStatistics() {
    final DeviceService service = get(DeviceService.class);
    final Iterable<Device> devices = service.getDevices();
    final ObjectNode root = mapper().createObjectNode();
    final ArrayNode rootArrayNode = root.putArray("statistics");
    for (final Device device : devices) {
        final ObjectNode deviceStatsNode = mapper().createObjectNode();
        deviceStatsNode.put("device", device.id().toString());
        final ArrayNode statisticsNode = deviceStatsNode.putArray("ports");
        final Iterable<PortStatistics> portStatsEntries = service.getPortDeltaStatistics(device.id());
        if (portStatsEntries != null) {
            for (final PortStatistics entry : portStatsEntries) {
                statisticsNode.add(codec(PortStatistics.class).encode(entry, this));
            }
        }
        rootArrayNode.add(deviceStatsNode);
    }
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PortStatistics(org.onosproject.net.device.PortStatistics) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 20 with PortStatistics

use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.

the class StatisticsWebResource method getPortDeltaStatisticsByDeviceIdAndPort.

/**
 * Gets port delta statistics of a specified device and port.
 * @onos.rsModel StatisticsPorts
 * @param deviceId device ID
 * @param port port
 * @return 200 OK with JSON encoded array of port delta statistics for the specified port
 */
@GET
@Path("delta/ports/{deviceId}/{port}")
@Produces(MediaType.APPLICATION_JSON)
public Response getPortDeltaStatisticsByDeviceIdAndPort(@PathParam("deviceId") String deviceId, @PathParam("port") String port) {
    final DeviceService service = get(DeviceService.class);
    final PortNumber portNumber = portNumber(port);
    final PortStatistics portStatsEntry = service.getDeltaStatisticsForPort(DeviceId.deviceId(deviceId), portNumber);
    final ObjectNode root = mapper().createObjectNode();
    final ArrayNode rootArrayNode = root.putArray("statistics");
    final ObjectNode deviceStatsNode = mapper().createObjectNode();
    deviceStatsNode.put("device", deviceId);
    final ArrayNode statisticsNode = deviceStatsNode.putArray("ports");
    if (portStatsEntry != null) {
        statisticsNode.add(codec(PortStatistics.class).encode(portStatsEntry, this));
    }
    rootArrayNode.add(deviceStatsNode);
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceService(org.onosproject.net.device.DeviceService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PortNumber(org.onosproject.net.PortNumber) PortStatistics(org.onosproject.net.device.PortStatistics) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

PortStatistics (org.onosproject.net.device.PortStatistics)52 DefaultPortStatistics (org.onosproject.net.device.DefaultPortStatistics)26 DeviceId (org.onosproject.net.DeviceId)14 PortNumber (org.onosproject.net.PortNumber)14 DeviceService (org.onosproject.net.device.DeviceService)14 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)11 Device (org.onosproject.net.Device)10 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)8 ArrayList (java.util.ArrayList)8 Map (java.util.Map)8 Port (org.onosproject.net.Port)7 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 PortStatisticsDiscovery (org.onosproject.net.device.PortStatisticsDiscovery)6 ConnectPoint (org.onosproject.net.ConnectPoint)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Maps (com.google.common.collect.Maps)4 Collection (java.util.Collection)4 Set (java.util.Set)4