use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.
the class GossipDeviceStore 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 ECDeviceStore method updatePortStatistics.
@Override
public DeviceEvent updatePortStatistics(ProviderId providerId, DeviceId deviceId, Collection<PortStatistics> newStatsCollection) {
Map<PortNumber, PortStatistics> prvStatsMap = devicePortStats.get(deviceId);
Map<PortNumber, PortStatistics> newStatsMap = Maps.newHashMap();
Map<PortNumber, PortStatistics> deltaStatsMap = Maps.newHashMap();
if (prvStatsMap != null) {
for (PortStatistics newStats : newStatsCollection) {
PortNumber port = newStats.portNumber();
PortStatistics prvStats = prvStatsMap.get(port);
DefaultPortStatistics.Builder builder = DefaultPortStatistics.builder();
PortStatistics deltaStats = builder.build();
if (prvStats != null) {
deltaStats = calcDeltaStats(deviceId, prvStats, newStats);
}
deltaStatsMap.put(port, deltaStats);
newStatsMap.put(port, newStats);
}
} else {
for (PortStatistics newStats : newStatsCollection) {
PortNumber port = newStats.portNumber();
newStatsMap.put(port, newStats);
}
}
devicePortDeltaStats.put(deviceId, deltaStatsMap);
devicePortStats.put(deviceId, newStatsMap);
// DeviceEvent returns null because of InternalPortStatsListener usage
return null;
}
use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.
the class IntentsDiagnosisCommand method dumpCpStatistics.
private void dumpCpStatistics(ConnectPoint cp, Collection<PortStatistics> devPortStats, Collection<PortStatistics> devPortDeltaStats, String direction, ServiceRefs svcs) {
if (cp == null) {
return;
}
dump(" %s:", direction);
if (cp.port().isLogical()) {
dump(" - logical: device: %s, port: %s", cp.deviceId(), cp.port());
return;
}
Port port = svcs.deviceService.getPort(cp.deviceId(), cp.port());
if (port == null) {
return;
}
try {
devPortStats.stream().filter(stat -> stat.portNumber().equals(cp.port())).forEach(stat -> dump(" - stat : %s:", getPortStatStr(stat, port)));
} catch (IllegalStateException e) {
error("error: " + e);
return;
}
try {
devPortDeltaStats.stream().filter(stat -> stat.portNumber().equals(cp.port())).forEach(stat -> dump(" - delta : %s:", getPortStatStr(stat, port)));
} catch (IllegalStateException e) {
error("error: " + e);
}
}
use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.
the class DevicePortStatsCommand method jsonPortStats.
/**
* Produces JSON array containing portstats of the specified device.
*
* @param deviceId device id
* @param portStats collection of port statistics
* @return JSON array
*/
private JsonNode jsonPortStats(DeviceId deviceId, ObjectMapper mapper, Iterable<PortStatistics> portStats) {
ObjectNode result = mapper.createObjectNode();
ArrayNode portStatsNode = mapper.createArrayNode();
for (PortStatistics stat : sortByPort(portStats)) {
if (isIrrelevant(stat)) {
continue;
}
if (nonzero && stat.isZero()) {
continue;
}
portStatsNode.add(mapper.createObjectNode().put("port", stat.portNumber().toString()).put("pktRx", stat.packetsReceived()).put("pktTx", stat.packetsSent()).put("bytesRx", stat.bytesReceived()).put("bytesTx", stat.bytesSent()).put("pktRxDrp", stat.packetsRxDropped()).put("pktTxDrp", stat.packetsTxDropped()).put("Dur", stat.durationSec()).set("annotations", annotations(mapper, stat.annotations())));
}
result.put("deviceId", deviceId.toString());
result.set("portStats", portStatsNode);
return result;
}
use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.
the class DevicePortStatsCommand method jsonPortStatsDelta.
/**
* Produces JSON array containing delta portstats of the specified device id.
*
* @param deviceId device id
* @param portStats collection of port statistics
* @return JSON array
*/
private JsonNode jsonPortStatsDelta(DeviceId deviceId, ObjectMapper mapper, Iterable<PortStatistics> portStats) {
ObjectNode result = mapper.createObjectNode();
ArrayNode portStatsNode = mapper.createArrayNode();
for (PortStatistics stat : sortByPort(portStats)) {
if (isIrrelevant(stat)) {
continue;
}
if (nonzero && stat.isZero()) {
continue;
}
float duration = ((float) stat.durationSec()) + (((float) stat.durationNano()) / TimeUnit.SECONDS.toNanos(1));
float rateRx = stat.bytesReceived() * 8 / duration;
float rateTx = stat.bytesSent() * 8 / duration;
portStatsNode.add(mapper.createObjectNode().put("port", stat.portNumber().toString()).put("pktRx", stat.packetsReceived()).put("pktTx", stat.packetsSent()).put("bytesRx", stat.bytesReceived()).put("bytesTx", stat.bytesSent()).put("rateRx", String.format("%.1f", rateRx)).put("rateTx", String.format("%.1f", rateTx)).put("pktRxDrp", stat.packetsRxDropped()).put("pktTxDrp", stat.packetsTxDropped()).put("interval", String.format("%.3f", duration)));
}
result.put("deviceId", deviceId.toString());
result.set("portStats", portStatsNode);
return result;
}
Aggregations