diff --git a/Admin/main.cpp b/Admin/main.cpp index 26255ef9..227aa710 100644 --- a/Admin/main.cpp +++ b/Admin/main.cpp @@ -1,8 +1,10 @@ #include #include +#include #include #include #include +#include int getparam (std::string input) { if(input.size() <= 3) { return -1;} @@ -23,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; @@ -49,8 +92,9 @@ void writesh( unsigned int values[], std::string filename ) { if (values[4] != 0) { shfile << "-r " << values[4] << " "; } if (values[5] != 0) { shfile << "-ab " << values[5] << " "; } if (values[6] != 0) { shfile << "-ar " << values[6] << " "; } - shfile << "rtmp://projectlivestream.com/oflaDemo/test"; + shfile << "rtmp://projectlivestream.com/oflaDemo/test &"; shfile.close(); + system("sh ./run.sh"); } int main() { @@ -91,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; @@ -100,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;