mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
Add a new API call to "systeminfo" class, which returns
information about all processes on the system.
The below example was greatly truncated ;)
REST Request:
-------------------------------
PUT /sysadm/systeminfo
{
"action" : "procinfo"
}
REST Response:
-------------------------------
{
"args": {
"procinfo": {
"228": {
"command": "adjkerntz",
"cpu": "3",
"nice": "0",
"pri": "52",
"res": "1968K",
"size": "8276K",
"state": "pause",
"thr": "1",
"time": "0:00",
"username": "root",
"wcpu": "0.00%"
}
}
}
}
WebSocket Request:
-------------------------------
{
"id" : "fooid",
"namespace" : "sysadm",
"name" : "systeminfo",
"args" : {
"action" : "procinfo"
}
}
WebSocket Response:
-------------------------------
{
"args": {
"procinfo": {
"228": {
"command": "adjkerntz",
"cpu": "3",
"nice": "0",
"pri": "52",
"res": "1968K",
"size": "8276K",
"state": "pause",
"thr": "1",
"time": "0:00",
"username": "root",
"wcpu": "0.00%"
}
},
"id": "fooid",
"name": "response",
"namespace": "sysadm"
}
This commit is contained in:
@@ -319,6 +319,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmSystemInfoRequest(const QJso
|
||||
ok = true;
|
||||
out->insert("memorystats", sysadm::SysInfo::memoryStats());
|
||||
}
|
||||
if(act=="procinfo"){
|
||||
ok = true;
|
||||
out->insert("procinfo", sysadm::SysInfo::procInfo());
|
||||
}
|
||||
if(act=="systeminfo"){
|
||||
ok = true;
|
||||
out->insert("systeminfo", sysadm::SysInfo::systemInfo());
|
||||
|
||||
@@ -210,6 +210,44 @@ QJsonObject SysInfo::memoryStats() {
|
||||
return retObject;
|
||||
}
|
||||
|
||||
// Return a json list of process information
|
||||
QJsonObject SysInfo::procInfo() {
|
||||
QJsonObject retObject;
|
||||
QStringList output;
|
||||
output = General::RunCommand("top -t -n all").split("\n");
|
||||
bool inSection = false;
|
||||
for(int i=0; i<output.length(); i++){
|
||||
if (output.at(i).contains("PID") && output.at(i).contains("USERNAME")){
|
||||
inSection = true;
|
||||
continue;
|
||||
}
|
||||
if (!inSection)
|
||||
continue;
|
||||
if ( output.at(i).isEmpty())
|
||||
continue;
|
||||
|
||||
// Now, lets break down the various elements of process information
|
||||
QJsonObject values;
|
||||
QString line = output.at(i).simplified();
|
||||
QString pid = line.section(" ", 0, 0);
|
||||
values.insert("username", line.section(" ", 1, 1));
|
||||
values.insert("thr", line.section(" ", 2, 2));
|
||||
values.insert("pri", line.section(" ", 3, 3));
|
||||
values.insert("nice", line.section(" ", 4, 4));
|
||||
values.insert("size", line.section(" ", 5, 5));
|
||||
values.insert("res", line.section(" ", 6, 6));
|
||||
values.insert("state", line.section(" ", 7, 7));
|
||||
values.insert("cpu", line.section(" ", 8, 8));
|
||||
values.insert("time", line.section(" ", 9, 9));
|
||||
values.insert("wcpu", line.section(" ", 10, 10));
|
||||
values.insert("command", line.section(" ", 11, 11));
|
||||
|
||||
// Add the PID object
|
||||
retObject.insert(pid, values);
|
||||
}
|
||||
return retObject;
|
||||
}
|
||||
|
||||
// Return a bunch of various system information
|
||||
QJsonObject SysInfo::systemInfo() {
|
||||
QJsonObject retObject;
|
||||
|
||||
@@ -20,6 +20,7 @@ public:
|
||||
static QJsonObject externalDevicePaths();
|
||||
static QJsonObject memoryStats();
|
||||
static QJsonObject systemInfo();
|
||||
static QJsonObject procInfo();
|
||||
};
|
||||
|
||||
} //end of pcbsd namespace
|
||||
|
||||
Reference in New Issue
Block a user