#include #include #include #include #include #include #include using namespace std; //**************************************************** class BadConversionRT : public std::runtime_error { public: BadConversionRT(const std::string& s) : std::runtime_error(s) { } }; inline double getRTInput(const std::string& s) { std::istringstream ia(s); double Rb; if (!(ia >> Rb)) throw BadConversionRT("convertToDouble(\"" + s + "\")"); return Rb; } //****************************************************Structure struct RXTX { double findrx; double findtx; }; //============================================== prototypes double toRXbytes(RXTX now); double toTXbytes(RXTX txout); //============================================== MAIN int main() { RXTX findrx, findtx; while(true){ int loops = 4; // loops me 0.25 sec melllomrom. LOOPER FAKTISK 1.25 SEK,.. OG ER OK. int i; double numinRT[10]; //double numinTx[4]; for(i = 0; i <= loops; i++) { usleep(250000); numinRT[i] = toRXbytes(findrx); numinRT[i+5] = toTXbytes(findtx); } // MAIN LOOPS double sampRX[4]; sampRX[0] = (numinRT[1] - numinRT[0]); sampRX[1] = (numinRT[2] - numinRT[1]); sampRX[2] = (numinRT[3] - numinRT[2]); sampRX[3] = (numinRT[4] - numinRT[3]); double sampTX[4]; sampTX[0] = (numinRT[6] - numinRT[5]); sampTX[1] = (numinRT[7] - numinRT[6]); sampTX[2] = (numinRT[8] - numinRT[7]); sampTX[3] = (numinRT[9] - numinRT[8]); int peakrx = 0; int minrx = 0; int peaktx = 0; int mintx = 0; for (int x=0; x <= 3 ; x++) { if(sampRX[peakrx] < sampRX[x]) { peakrx = x; } if(sampRX[minrx] > sampRX[x]) { minrx = x; } if(sampTX[peaktx] < sampTX[x]) { peaktx = x; } if(sampTX[mintx] > sampTX[x]) { mintx = x; } } double sampRXtot; sampRXtot = ((((sampRX[0] + sampRX[1]) + sampRX[2]) + sampRX[3])); double sampRTtot; sampRTtot = ((((sampTX[0] + sampTX[1]) + sampTX[2]) + sampTX[3])); system("clear"); cout << "-------------------------INPUT-------------------------\n\n"; cout.precision( 2 ); cout << "Total input: " << toRXbytes(findrx) / 1024 << " MB" << endl; cout.precision( 3 ); cout << "Max burst: " << sampRX[peakrx] *4 << " KB :: Min burst: " << sampRX[minrx] * 4 << " KB" << endl ; cout.setf(ios::fixed, ios::floatfield); cout << "Average input: " << sampRXtot << " KB/sec" << endl;; cout << "\n-------------------------OUTPUT-------------------------\n\n"; cout.precision( 2 ); cout << "Total output: " << toTXbytes(findtx) / 1024 << " MB" << endl; cout.precision( 3 ); cout << "Max burst: " << sampTX[peaktx] *4 << " KB :: Min burst: " << sampTX[mintx] * 4 << " KB" << endl ; cout << "Average input: " << sampRTtot << " KB/sec" << endl;; } } // ### MAIN //============================================== MAIN double toRXbytes(RXTX now) { ifstream in("/proc/net/dev"); vector words; string line, rxstr, s0; while(in >> line) words.push_back(line); if(words[36].size() > words[37].size()) { rxstr = words[36]; s0 = std::string(rxstr.begin() + 5, rxstr.end()); now.findrx = getRTInput(s0); now.findrx = now.findrx / 1024; // returns KB instead of Bytes return now.findrx; } else { rxstr = words[37]; s0 = std::string(rxstr.begin() + 5, rxstr.end()); now.findrx = getRTInput(s0); now.findrx = now.findrx / 1024; // returns KB instead of Bytes return now.findrx; } } double toTXbytes(RXTX txout) { ifstream in("/proc/net/dev"); vector words; string line, txstr, s1; while(in >> line) words.push_back(line); if(words[44].size() > words[45].size()) { txstr = words[44]; s1 = std::string(txstr.begin() + 0, txstr.end()); txout.findtx = getRTInput(s1); txout.findtx = txout.findtx / 1024; // returns KB instead of Bytes return txout.findtx; } else { txstr = words[45]; s1 = std::string(txstr.begin() + 0, txstr.end()); txout.findtx = getRTInput(s1); txout.findtx = txout.findtx / 1024; // returns KB instead of Bytes return txout.findtx; } }