Add a new API call which returns the total memory in use

This will be expanded upon later so we can return more of the
particulars of where memory is used

REST Request:
-------------------------------
PUT /sysadm/systeminfo
{
   "action" : "memorypercentage"
}

REST Response:
-------------------------------
{
    "args": {
        "memorypercentage": {
            "memoryused": 42
        }
    }
}

WebSocket Request:
-------------------------------
{
   "id" : "fooid",
   "args" : {
      "action" : "memorypercentage"
   },
   "namespace" : "sysadm",
   "name" : "systeminfo"
}

WebSocket Response:
-------------------------------
{
  "args": {
    "memorypercentage": {
      "memoryused": 42
    }
  },
  "id": "fooid",
  "name": "response",
  "namespace": "sysadm"
}
This commit is contained in:
Kris Moore
2016-01-21 13:47:11 -05:00
parent aa5755d4b4
commit 1fc7b3cabd
3 changed files with 19 additions and 0 deletions

View File

@@ -160,3 +160,17 @@ QJsonObject SysInfo::externalDevicePaths() {
// Return the devices / mounts
return retObject;
}
// KPM 1-21-2016
// This needs to beefed up as well, so we return more stats on arc, wired, etc
QJsonObject SysInfo::memoryPercentage() {
QJsonObject retObject;
//SYSCTL: vm.stats.vm.v_<something>_count
QStringList info = General::RunCommand("sysctl -n vm.stats.vm.v_page_count vm.stats.vm.v_wire_count vm.stats.vm.v_active_count").split("\n");
if(info.length()<3){ return retObject; } //error in fetching information
//List output: [total, wired, active]
double perc = 100.0* (info[1].toLong()+info[2].toLong())/(info[0].toDouble());
retObject.insert("memoryused", qRound(perc));
return retObject;
}

View File

@@ -18,6 +18,7 @@ public:
static QJsonObject cpuPercentage();
static QJsonObject cpuTemps();
static QJsonObject externalDevicePaths();
static QJsonObject memoryPercentage();
};
} //end of pcbsd namespace

View File

@@ -271,6 +271,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmSystemInfoRequest(const QJso
ok = true;
out->insert("externalmounts", sysadm::SysInfo::externalDevicePaths());
}
if(act=="memorypercentage"){
ok = true;
out->insert("memorypercentage", sysadm::SysInfo::memoryPercentage());
}
} //end of "action" key usage