use of org.onosproject.net.device.DefaultPortStatistics in project onos by opennetworkinglab.
the class GossipDeviceStore method calcDeltaStats.
/**
* Calculate delta statistics by subtracting previous from new statistics.
*
* @param deviceId device identifier
* @param prvStats previous port statistics
* @param newStats new port statistics
* @return PortStatistics
*/
public PortStatistics calcDeltaStats(DeviceId deviceId, PortStatistics prvStats, PortStatistics newStats) {
// calculate time difference
long deltaStatsSec, deltaStatsNano;
if (newStats.durationNano() < prvStats.durationNano()) {
deltaStatsNano = newStats.durationNano() - prvStats.durationNano() + TimeUnit.SECONDS.toNanos(1);
deltaStatsSec = newStats.durationSec() - prvStats.durationSec() - 1L;
} else {
deltaStatsNano = newStats.durationNano() - prvStats.durationNano();
deltaStatsSec = newStats.durationSec() - prvStats.durationSec();
}
DefaultPortStatistics.Builder builder = DefaultPortStatistics.builder();
DefaultPortStatistics deltaStats = builder.setDeviceId(deviceId).setPort(newStats.portNumber()).setPacketsReceived(newStats.packetsReceived() - prvStats.packetsReceived()).setPacketsSent(newStats.packetsSent() - prvStats.packetsSent()).setBytesReceived(newStats.bytesReceived() - prvStats.bytesReceived()).setBytesSent(newStats.bytesSent() - prvStats.bytesSent()).setPacketsRxDropped(newStats.packetsRxDropped() - prvStats.packetsRxDropped()).setPacketsTxDropped(newStats.packetsTxDropped() - prvStats.packetsTxDropped()).setPacketsRxErrors(newStats.packetsRxErrors() - prvStats.packetsRxErrors()).setPacketsTxErrors(newStats.packetsTxErrors() - prvStats.packetsTxErrors()).setDurationSec(deltaStatsSec).setDurationNano(deltaStatsNano).build();
return deltaStats;
}
Aggregations