Added cpu_use response to capabilities API call
This commit is contained in:
parent
66dc2dc0cb
commit
9239586a89
2 changed files with 17 additions and 1 deletions
|
@ -162,6 +162,7 @@ namespace Controller {
|
|||
/// },
|
||||
/// "speed": 6580, //total speed in MHz of all CPUs cores summed together
|
||||
/// "threads": 8 //total count of all threads of all CPUs summed together
|
||||
/// "cpu_use": 105 //Tenths of percent CPU usage - i.e. 105 = 10.5%
|
||||
/// }
|
||||
/// ~~~~~~~~~~~~~~~
|
||||
void checkCapable(JSON::Value & capa){
|
||||
|
@ -269,6 +270,21 @@ namespace Controller {
|
|||
capa["load"]["fifteen"] = (long long int)(fifteenmin * 100);
|
||||
}
|
||||
}
|
||||
std::ifstream cpustat("/proc/stat");
|
||||
if (cpustat){
|
||||
char line[300];
|
||||
while (cpustat.getline(line, 300)){
|
||||
static unsigned long long cl_total = 0, cl_idle = 0;
|
||||
unsigned long long c_user, c_nice, c_syst, c_idle, c_total;
|
||||
if (sscanf(line, "cpu %Lu %Lu %Lu %Lu", &c_user, &c_nice, &c_syst, &c_idle) == 4){
|
||||
c_total = c_user + c_nice + c_syst + c_idle;
|
||||
capa["cpu_use"] = (long long int)(1000 - ((c_idle - cl_idle) * 1000) / (c_total - cl_total));
|
||||
cl_total = c_total;
|
||||
cl_idle = c_idle;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -401,7 +401,7 @@ void Controller::statStorage::update(IPC::statExchange & data) {
|
|||
}
|
||||
|
||||
/// This function is called by the shared memory page that holds statistics.
|
||||
/// It updates the internally saved statistics data, moving across sessions or archiving when neccessary.
|
||||
/// It updates the internally saved statistics data, moving across sessions or archiving when necessary.
|
||||
void Controller::parseStatistics(char * data, size_t len, unsigned int id){
|
||||
//retrieve stats data
|
||||
IPC::statExchange tmpEx(data);
|
||||
|
|
Loading…
Add table
Reference in a new issue