From 6b28436a5db8b82b644262d4c6aefaa7da3b216d Mon Sep 17 00:00:00 2001 From: Thulinma Date: Sun, 18 Jul 2010 15:06:37 +0200 Subject: [PATCH] Throughput support, connected usercount support --- Admin/main.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/Admin/main.cpp b/Admin/main.cpp index be676432..227aa710 100644 --- a/Admin/main.cpp +++ b/Admin/main.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -24,6 +25,47 @@ std::string getstringparam(std::string input) { return result; } +void GetThroughPut(int * Down, int * Up){ + //deze file bevat o.a. totaal bytes verstuurd/ontvangen sinds de interface up ging, voor alle interfaces. + //voor een snelheidsmeting moet je dus 2X lezen en het verschil gebruiken... + std::ifstream netdev ("/proc/net/dev"); + std::string line; + int tmpDown, tmpUp; + int ret = 0; + *Down = 0; + *Up = 0; + while (netdev.good()){ + getline(netdev, line); + //probeer een geldige interface te parsen - 2 = 2 matches, en dus goed geparsed. + ret = sscanf(line.c_str(), " %*[^:]: %i %*i %*i %*i %*i %*i %*i %*i %i %*i %*i %*i %*i %*i %*i %*i", &tmpDown, &tmpUp); + if (ret == 2){*Down += tmpDown;*Up += tmpUp;} + } + netdev.close(); +}//GetThroughPut + +std::string MeasureThroughPut(){ + std::stringstream output; + int frstDown, frstUp; + int totDown, totUp; + GetThroughPut(&frstDown, &frstUp); + sleep(5); + GetThroughPut(&totDown, &totUp); + //return totaal bytes down, up, gemiddelde bytes per seconde over de afgelopen 5 secs down, up. + output << totDown << " " << totUp << " " << ((totDown - frstDown)/5) << " " << ((totUp - frstUp)/5); + return output.str(); +}//MeasureThroughPut + +std::string GetConnectedUsers(){ + std::string output; + //laat ps aux de processen Client_PLS opvragen, zonder de grep zelf, en tel het aantal lines. + system("ps aux | grep Client_PLS | grep -v grep | wc -l > ./tmpfile"); + //lees de file, en return de inhoud + std::ifstream tmpfile ("./tmpfile"); + tmpfile >> output; + tmpfile.close(); + return output; +}//GetConnectedUsers + void readpreset( unsigned int values[], std::string & filename ) { std::ifstream presetfile ("preset"); presetfile >> filename; @@ -93,6 +135,7 @@ int main() { switch(inputcommand[2]) { case 'F': std::cout << "OK" << values[7] << "\n"; break; case 'P': std::cout << "OK" << values[8] << "\n"; break; + case 'C': std::cout << "OK" << GetConnectedUsers() << "\n"; break; default: std::cout << "ER\n"; break; } break; @@ -102,6 +145,12 @@ int main() { default: std::cout << "ER\n"; break; } break; + case 'G': + switch(inputcommand[2]) { + case 'T': std::cout << "OK" << MeasureThroughPut() << "\n"; break; + default: std::cout << "ER\n"; break; + } + break; default: std::cout << "ER\n"; break; } break;