Search in sources :

Example 36 with PortStatistics

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

the class SimpleDeviceStore method getDeltaStatisticsForPort.

@Override
public PortStatistics getDeltaStatisticsForPort(DeviceId deviceId, PortNumber portNumber) {
    Map<PortNumber, PortStatistics> portStatsMap = devicePortDeltaStats.get(deviceId);
    if (portStatsMap == null) {
        return null;
    }
    PortStatistics portStats = portStatsMap.get(portNumber);
    return portStats;
}
Also used : PortNumber(org.onosproject.net.PortNumber) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) PortStatistics(org.onosproject.net.device.PortStatistics)

Example 37 with PortStatistics

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

the class ServerDevicesDiscovery method parseNicStatistics.

/**
 * Parse the input JSON object, looking for NIC-related
 * statistics. Upon success, construct and return a list
 * of NIC statistics objects.
 *
 * @param deviceId the device ID that sent the JSON object
 * @param objNode input JSON node with NIC statistics information
 * @return list of (per port) PortStatistics
 */
private Collection<PortStatistics> parseNicStatistics(DeviceId deviceId, JsonNode objNode) {
    if ((deviceId == null) || (objNode == null)) {
        return Collections.EMPTY_LIST;
    }
    RestServerSBDevice device = null;
    try {
        device = (RestServerSBDevice) getDevice(deviceId);
    } catch (ClassCastException ccEx) {
        return Collections.EMPTY_LIST;
    }
    if (device == null) {
        return Collections.EMPTY_LIST;
    }
    Collection<PortStatistics> nicStats = Lists.newArrayList();
    JsonNode nicNode = objNode.path(PARAM_NICS);
    if (nicNode.isMissingNode()) {
        return nicStats;
    }
    for (JsonNode nn : nicNode) {
        ObjectNode nicObjNode = (ObjectNode) nn;
        // All the NIC attributes
        String nicName = get(nn, PARAM_NAME);
        checkArgument(!Strings.isNullOrEmpty(nicName), MSG_NIC_NAME_NULL);
        long portNumber = device.portNumberFromName(nicName);
        checkArgument(portNumber >= 0, MSG_NIC_PORT_NUMBER_NEGATIVE);
        long rxCount = nicObjNode.path(PARAM_NIC_STATS_RX_COUNT).asLong();
        long rxBytes = nicObjNode.path(PARAM_NIC_STATS_RX_BYTES).asLong();
        long rxDropped = nicObjNode.path(PARAM_NIC_STATS_RX_DROPS).asLong();
        long rxErrors = nicObjNode.path(PARAM_NIC_STATS_RX_ERRORS).asLong();
        long txCount = nicObjNode.path(PARAM_NIC_STATS_TX_COUNT).asLong();
        long txBytes = nicObjNode.path(PARAM_NIC_STATS_TX_BYTES).asLong();
        long txDropped = nicObjNode.path(PARAM_NIC_STATS_TX_DROPS).asLong();
        long txErrors = nicObjNode.path(PARAM_NIC_STATS_TX_ERRORS).asLong();
        // Construct a NIC statistics object and add it to the set
        nicStats.add(DefaultPortStatistics.builder().setDeviceId(deviceId).setPort(PortNumber.portNumber(portNumber)).setPacketsReceived(rxCount).setPacketsSent(txCount).setBytesReceived(rxBytes).setBytesSent(txBytes).setPacketsRxDropped(rxDropped).setPacketsRxErrors(rxErrors).setPacketsTxDropped(txDropped).setPacketsTxErrors(txErrors).build());
    }
    return nicStats;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) 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)

Example 38 with PortStatistics

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

the class ServerDevicesDiscovery method getPortStatistics.

/**
 * Query a server to retrieve its port statistics.
 *
 * @param deviceId the device ID to be queried
 * @return list of (per port) PortStatistics
 */
private Collection<PortStatistics> getPortStatistics(DeviceId deviceId) {
    // Get global monitoring statistics
    MonitoringStatistics monStats = getGlobalMonitoringStatistics(deviceId);
    if (monStats == null) {
        return Collections.EMPTY_LIST;
    }
    // Filter out the NIC statistics
    Collection<PortStatistics> portStats = monStats.nicStatisticsAll();
    if (portStats == null) {
        return Collections.EMPTY_LIST;
    }
    log.debug("Port statistics: {}", portStats.toString());
    return portStats;
}
Also used : DefaultMonitoringStatistics(org.onosproject.drivers.server.impl.stats.DefaultMonitoringStatistics) MonitoringStatistics(org.onosproject.drivers.server.stats.MonitoringStatistics) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) PortStatistics(org.onosproject.net.device.PortStatistics)

Example 39 with PortStatistics

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

the class StatisticsWebResource method getPortDeltaStatisticsByDeviceId.

/**
 * Gets port delta statistics of a specified devices.
 * @onos.rsModel StatisticsPorts
 * @param deviceId device ID
 * @return 200 OK with JSON encoded array of port delta statistics
 */
@GET
@Path("delta/ports/{deviceId}")
@Produces(MediaType.APPLICATION_JSON)
public Response getPortDeltaStatisticsByDeviceId(@PathParam("deviceId") String deviceId) {
    final DeviceService service = get(DeviceService.class);
    final Iterable<PortStatistics> portStatsEntries = service.getPortDeltaStatistics(DeviceId.deviceId(deviceId));
    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 (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) 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 40 with PortStatistics

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

the class StatisticsWebResource method getPortStatisticsByDeviceId.

/**
 * Gets port statistics of a specified devices.
 * @onos.rsModel StatisticsPorts
 * @param deviceId device ID
 * @return 200 OK with JSON encoded array of port statistics
 */
@GET
@Path("ports/{deviceId}")
@Produces(MediaType.APPLICATION_JSON)
public Response getPortStatisticsByDeviceId(@PathParam("deviceId") String deviceId) {
    final DeviceService service = get(DeviceService.class);
    final Iterable<PortStatistics> portStatsEntries = service.getPortStatistics(DeviceId.deviceId(deviceId));
    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 (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) 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)

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