From 88cb2945674d9c7db3109c2c640c3c12a68a9695 Mon Sep 17 00:00:00 2001 From: "Srivats P." Date: Wed, 8 Feb 2012 22:14:20 +0530 Subject: [PATCH] Added support for rx error stats on Linux. Updates issue 28 --- client/portstatsmodel.cpp | 5 +++++ client/portstatsmodel.h | 12 +++++++++++- common/protocol.proto | 5 +++++ server/abstractport.cpp | 5 +++++ server/abstractport.h | 5 +++++ server/linuxport.cpp | 16 ++++++++++++---- server/myservice.cpp | 5 +++++ 7 files changed, 48 insertions(+), 5 deletions(-) diff --git a/client/portstatsmodel.cpp b/client/portstatsmodel.cpp index 92e6a24..ff9d7b7 100644 --- a/client/portstatsmodel.cpp +++ b/client/portstatsmodel.cpp @@ -166,6 +166,11 @@ QVariant PortStatsModel::data(const QModelIndex &index, int role) const case e_STAT_BYTES_SENT_NIC: return stats.tx_bytes_nic(); #endif + case e_STAT_RX_DROPS : return quint64(stats.rx_drops()); + case e_STAT_RX_ERRORS: return quint64(stats.rx_errors()); + case e_STAT_RX_FIFO_ERRORS: return quint64(stats.rx_fifo_errors()); + case e_STAT_RX_FRAME_ERRORS: return quint64(stats.rx_frame_errors()); + default: qWarning("%s: Unhandled stats id %d\n", __FUNCTION__, index.row()); diff --git a/client/portstatsmodel.h b/client/portstatsmodel.h index d50508b..a0d6868 100644 --- a/client/portstatsmodel.h +++ b/client/portstatsmodel.h @@ -53,7 +53,13 @@ typedef enum { e_STAT_BYTES_SENT_NIC, #endif - e_STATISTICS_END = e_STAT_BYTE_RECV_RATE, + // Rx Errors + e_STAT_RX_DROPS, + e_STAT_RX_ERRORS, + e_STAT_RX_FIFO_ERRORS, + e_STAT_RX_FRAME_ERRORS, + + e_STATISTICS_END = e_STAT_RX_FRAME_ERRORS, e_STAT_MAX } PortStat; @@ -77,6 +83,10 @@ static QStringList PortStatName = (QStringList() << "Bytes Received (NIC)" << "Bytes Sent (NIC)" #endif + << "Receive Drops" + << "Receive Errors" + << "Receive Fifo Errors" + << "Receive Frame Errors" ); static QStringList LinkStateName = (QStringList() diff --git a/common/protocol.proto b/common/protocol.proto index c902610..9a74654 100644 --- a/common/protocol.proto +++ b/common/protocol.proto @@ -214,6 +214,11 @@ message PortStats { optional uint64 tx_bytes_nic = 24; optional uint64 tx_pps = 25; optional uint64 tx_bps = 26; + + optional uint64 rx_drops = 100; + optional uint64 rx_errors = 101; + optional uint64 rx_fifo_errors = 102; + optional uint64 rx_frame_errors = 103; } message PortStatsList { diff --git a/server/abstractport.cpp b/server/abstractport.cpp index 178338a..c210e56 100644 --- a/server/abstractport.cpp +++ b/server/abstractport.cpp @@ -551,4 +551,9 @@ void AbstractPort::stats(PortStats *stats) stats->txBytes = stats_.txBytes - epochStats_.txBytes; stats->txPps = stats_.txPps; stats->txBps = stats_.txBps; + + stats->rxDrops = stats_.rxDrops - epochStats_.rxDrops; + stats->rxErrors = stats_.rxErrors - epochStats_.rxErrors; + stats->rxFifoErrors = stats_.rxFifoErrors - epochStats_.rxFifoErrors; + stats->rxFrameErrors = stats_.rxFrameErrors - epochStats_.rxFrameErrors; } diff --git a/server/abstractport.h b/server/abstractport.h index f531e26..288f898 100644 --- a/server/abstractport.h +++ b/server/abstractport.h @@ -38,6 +38,11 @@ public: quint64 rxPps; quint64 rxBps; + quint64 rxDrops; + quint64 rxErrors; + quint64 rxFifoErrors; + quint64 rxFrameErrors; + quint64 txPkts; quint64 txBytes; quint64 txPps; diff --git a/server/linuxport.cpp b/server/linuxport.cpp index 12f5cb3..0f041f1 100644 --- a/server/linuxport.cpp +++ b/server/linuxport.cpp @@ -132,8 +132,8 @@ void LinuxPort::StatsMonitor::run() char *p, *end; int count, index; const char* fmtopt[] = { - "%llu%llu%u%u%u%u%u%u%llu%llu%u%u%u%u%u%u\n", - "%llu%llu%u%u%u%u%n%n%llu%llu%u%u%u%u%u%n\n", + "%llu%llu%llu%llu%llu%llu%u%u%llu%llu%u%u%u%u%u%u\n", + "%llu%llu%llu%llu%llu%llu%n%n%llu%llu%u%u%u%u%u%n\n", }; const char *fmt; struct ifreq ifr; @@ -299,6 +299,7 @@ void LinuxPort::StatsMonitor::run() { uint dummy; quint64 rxBytes, rxPkts; + quint64 rxErrors, rxDrops, rxFifo, rxFrame; quint64 txBytes, txPkts; // Skip interface name - we assume the number and order of ports @@ -315,8 +316,10 @@ void LinuxPort::StatsMonitor::run() p++; sscanf(p, fmt, - &rxBytes, &rxPkts, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, - &txBytes, &txPkts, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy); + &rxBytes, &rxPkts, &rxErrors, &rxDrops, &rxFifo, &rxFrame, + &dummy, &dummy, + &txBytes, &txPkts, &dummy, &dummy, &dummy, &dummy, &dummy, + &dummy); if (index < count) { @@ -331,6 +334,11 @@ void LinuxPort::StatsMonitor::run() stats->txBps = (txBytes - stats->txBytes)/kRefreshFreq_; stats->txPkts = txPkts; stats->txBytes = txBytes; + + stats->rxDrops = rxDrops; + stats->rxErrors = rxErrors; + stats->rxFifoErrors = rxFifo; + stats->rxFrameErrors = rxFrame; } } diff --git a/server/myservice.cpp b/server/myservice.cpp index 424a95a..be0984a 100644 --- a/server/myservice.cpp +++ b/server/myservice.cpp @@ -441,6 +441,11 @@ void MyService::getStats(::google::protobuf::RpcController* /*controller*/, s->set_tx_bytes(stats.txBytes); s->set_tx_pps(stats.txPps); s->set_tx_bps(stats.txBps); + + s->set_rx_drops(stats.rxDrops); + s->set_rx_errors(stats.rxErrors); + s->set_rx_fifo_errors(stats.rxFifoErrors); + s->set_rx_frame_errors(stats.rxFrameErrors); } done->Run();