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;
}
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;
}
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;
}
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();
}
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();
}
Aggregations