Remove trailing kB from proc/meminfo

This commit is contained in:
Tyler Perkins 2022-04-29 11:50:13 -04:00
parent 39b09d7495
commit 0d6674b9b9
1 changed files with 5 additions and 2 deletions

View File

@ -13,14 +13,17 @@ bool memory::getProcMem(crow::json::wvalue& ret){
while(std::getline(f, line)){
size_t colon;
int last_space = -1;
int final_space = -1;
for(int i = 0; line[i] != '\0' ; ++i){
if(line[i] == ':')
colon = i;
else if(line[i-1] == ' ' && line[i] != ' ' && last_space == -1)
else if(last_space == -1 && line[i-1] == ' ' && line[i] != ' ' )
last_space = i;
else if(last_space != -1 && line[i] == ' ')
final_space = i;
}
ret[line.substr(0,colon)] = line.substr(last_space);
ret[line.substr(0,colon)] = line.substr(last_space, final_space - last_space);
}
} else {
ret["message"] = "Failed to open proc filesystem";