mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ public:
|
||||
static QJsonObject cpuPercentage();
|
||||
static QJsonObject cpuTemps();
|
||||
static QJsonObject externalDevicePaths();
|
||||
static QJsonObject memoryPercentage();
|
||||
};
|
||||
|
||||
} //end of pcbsd namespace
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user