@Override public ObjectNode encode(PortStatistics entry, CodecContext context) { checkNotNull(entry, "Port Statistics cannot be null"); final ObjectNode result = context.mapper().createObjectNode() .put("port", entry.port()) .put("packetsReceived", entry.packetsReceived()) .put("packetsSent", entry.packetsSent()) .put("bytesReceived", entry.bytesReceived()) .put("bytesSent", entry.bytesSent()) .put("packetsRxDropped", entry.packetsRxDropped()) .put("packetsTxDropped", entry.packetsTxDropped()) .put("packetsRxErrors", entry.packetsRxErrors()) .put("packetsTxErrors", entry.packetsTxErrors()) .put("durationSec", entry.durationSec()); return annotate(result, entry, context); }
private long getEgressValue(PortStatistics stats, MetricType metricType) { return metricType == MetricType.BYTES ? stats.bytesSent() : stats.packetsSent(); }
private long getIngressValue(PortStatistics stats, MetricType metricType) { return metricType == MetricType.BYTES ? stats.bytesReceived() : stats.packetsReceived(); }
/** * Prints Port Statistics. * * @param deviceId * @param portStats */ private void printPortStats(DeviceId deviceId, Iterable<PortStatistics> portStats) { print("deviceId=%s", deviceId); for (PortStatistics stat : sortByPort(portStats)) { if (isIrrelevant(stat)) { continue; } if (nonzero && stat.isZero()) { continue; } print(FORMAT, stat.portNumber(), stat.packetsReceived(), stat.packetsSent(), stat.bytesReceived(), stat.bytesSent(), stat.packetsRxDropped(), stat.packetsTxDropped(), stat.durationSec(), annotations(stat.annotations())); } }
private String getPortStatStr(PortStatistics stat, Port port) { final String portName = port.annotations().value(AnnotationKeys.PORT_NAME); return String.format("port: %s(%s), ", stat.portNumber(), portName) + String.format("enabled: %b, ", port.isEnabled()) + String.format("pktRx: %d, ", stat.packetsReceived()) + String.format("pktTx: %d, ", stat.packetsSent()) + String.format("pktRxErr: %d, ", stat.packetsRxErrors()) + String.format("pktTxErr: %d, ", stat.packetsTxErrors()) + String.format("pktRxDrp: %d, ", stat.packetsRxDropped()) + String.format("pktTxDrp: %d", stat.packetsTxDropped()); }
@Override public DeviceEvent updatePortStatistics(ProviderId providerId, DeviceId deviceId, Collection<PortStatistics> portStats) { ConcurrentMap<PortNumber, PortStatistics> statsMap = devicePortStats.get(deviceId); if (statsMap == null) { statsMap = Maps.newConcurrentMap(); devicePortStats.put(deviceId, statsMap); } for (PortStatistics stat: portStats) { PortNumber portNumber = PortNumber.portNumber(stat.port()); statsMap.put(portNumber, stat); } return new DeviceEvent(PORT_STATS_UPDATED, devices.get(deviceId), null); }
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; print(formatDelta, stat.portNumber(), stat.packetsReceived(), stat.packetsSent(), stat.bytesReceived(), stat.bytesSent(), String.format("%.1f", rateRx), String.format("%.1f", rateTx), stat.packetsRxDropped(), stat.packetsTxDropped(), String.format("%.3f", duration));
private void updatePortData(DeviceId deviceId, PortStatistics stats) { ConnectPoint cp = new ConnectPoint(deviceId, portNumber(stats.port())); DataPoint c = current.get(cp); // Create a new data point and make it the current one current.put(cp, new DataPoint(stats)); // If we have a current data point, demote it to previous if (c != null) { previous.put(cp, c); } }
continue; if (nonzero && stat.isZero()) { continue; float duration = ((float) stat.durationSec()) + (((float) stat.durationNano()) / TimeUnit.SECONDS.toNanos(1)); float rateRx = duration > 0 ? stat.bytesReceived() * 8 / duration : 0; float rateTx = duration > 0 ? stat.bytesSent() * 8 / duration : 0; print(formatDeltaTable, stat.portNumber(), humanReadable(stat.packetsReceived()), humanReadable(stat.bytesReceived()), humanReadableBps(rateRx), humanReadable(stat.packetsRxDropped()), humanReadable(stat.packetsSent()), humanReadable(stat.bytesSent()), humanReadableBps(rateTx), humanReadable(stat.packetsTxDropped()), String.format("%.3f", duration));