Throughput support, connected usercount support
This commit is contained in:
parent
08107b606b
commit
6b28436a5d
1 changed files with 49 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
@ -24,6 +25,47 @@ std::string getstringparam(std::string input) {
|
||||||
return result;
|
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 ) {
|
void readpreset( unsigned int values[], std::string & filename ) {
|
||||||
std::ifstream presetfile ("preset");
|
std::ifstream presetfile ("preset");
|
||||||
presetfile >> filename;
|
presetfile >> filename;
|
||||||
|
@ -93,6 +135,7 @@ int main() {
|
||||||
switch(inputcommand[2]) {
|
switch(inputcommand[2]) {
|
||||||
case 'F': std::cout << "OK" << values[7] << "\n"; break;
|
case 'F': std::cout << "OK" << values[7] << "\n"; break;
|
||||||
case 'P': std::cout << "OK" << values[8] << "\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;
|
default: std::cout << "ER\n"; break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -102,6 +145,12 @@ int main() {
|
||||||
default: std::cout << "ER\n"; break;
|
default: std::cout << "ER\n"; break;
|
||||||
}
|
}
|
||||||
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;
|
default: std::cout << "ER\n"; break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Reference in a new issue