mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
New API call to get a listing of all the CPU temps on the system,
if the "coretemp" module isn't loaded, it will be loaded beforehand
REST Request:
-------------------------------
PUT /sysadm/systeminfo
{
"action" : "cputemps"
}
REST Response:
-------------------------------
{
"args": {
"cputemps": {
"cpu0": "27.0C",
"cpu1": "34.0C",
"cpu2": "33.0C",
"cpu3": "31.0C"
}
}
}
WebSocket Request:
-------------------------------
{
"args" : {
"action" : "cputemps"
},
"id" : "fooid",
"name" : "systeminfo",
"namespace" : "sysadm"
}
WebSocket Response:
-------------------------------
{
"args": {
"cputemps": {
"cpu0": "34.0C",
"cpu1": "32.0C",
"cpu2": "34.0C",
"cpu3": "31.0C"
}
},
"id": "fooid",
"name": "response",
"namespace": "sysadm"
}
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -23,6 +23,8 @@ src/server/WebServer.o
|
||||
src/server/WebSocket.o
|
||||
src/server/dispatcher-client.o
|
||||
src/server/main.o
|
||||
src/server/moc_AuthorizationManager.cpp
|
||||
src/server/moc_AuthorizationManager.o
|
||||
src/server/moc_WebServer.cpp
|
||||
src/server/moc_WebServer.o
|
||||
src/server/moc_WebSocket.cpp
|
||||
|
||||
@@ -32,7 +32,8 @@ Battery Information
|
||||
===================
|
||||
|
||||
The "batteryinfo" action will indicate whether or not a battery exists. If it does, it will also report its current charge percentage level (1-99) and its
|
||||
status (offline, charging, on backup, or unknown).
|
||||
status (offline, charging, on backup, or unknown) and estimated time left (in seconds)
|
||||
timeleft (1-XXXXXX)
|
||||
|
||||
**REST Request**
|
||||
|
||||
@@ -148,4 +149,4 @@ For each mounted device, the response will include the device name, filesystem,
|
||||
"id": "fooid",
|
||||
"name": "response",
|
||||
"namespace": "sysadm"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,27 @@ QJsonObject SysInfo::batteryInfo(){
|
||||
return retObject;
|
||||
}
|
||||
|
||||
QJsonObject SysInfo::cpuTemps() {
|
||||
|
||||
// Make sure coretemp is loaded
|
||||
if ( General::RunCommand("kldstat").indexOf("coretemp") == -1 )
|
||||
General::RunCommand("kldload coretemp");
|
||||
|
||||
QJsonObject retObject;
|
||||
QStringList temps;
|
||||
temps = General::RunCommand("sysctl -ai").split("\n").filter(".temperature:");
|
||||
temps.sort();
|
||||
for(int i=0; i<temps.length(); i++){
|
||||
if(temps[i].contains(".acpi.") || temps[i].contains(".cpu")){
|
||||
retObject.insert(temps[i].section(":", 0, 0).section(".", 1,2).replace(".", "").simplified(), temps[i].section(":", 1,5).simplified());
|
||||
}else{
|
||||
//non CPU temperature - skip it
|
||||
temps.removeAt(i); i--;
|
||||
}
|
||||
}
|
||||
return retObject;
|
||||
}
|
||||
|
||||
// ==== ExternalDevicePaths() ====
|
||||
QJsonObject SysInfo::externalDevicePaths() {
|
||||
QJsonObject retObject;
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace sysadm{
|
||||
class SysInfo{
|
||||
public:
|
||||
static QJsonObject batteryInfo();
|
||||
static QJsonObject cpuTemps();
|
||||
static QJsonObject externalDevicePaths();
|
||||
};
|
||||
|
||||
|
||||
@@ -255,14 +255,18 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmSystemInfoRequest(const QJso
|
||||
bool ok = false;
|
||||
if(keys.contains("action")){
|
||||
QString act = JsonValueToString(in_args.toObject().value("action"));
|
||||
if(act=="externalmounts"){
|
||||
ok = true;
|
||||
out->insert("externalmounts", sysadm::SysInfo::externalDevicePaths());
|
||||
}
|
||||
if(act=="batteryinfo"){
|
||||
ok = true;
|
||||
out->insert("batteryinfo", sysadm::SysInfo::batteryInfo());
|
||||
}
|
||||
if(act=="cputemps"){
|
||||
ok = true;
|
||||
out->insert("cputemps", sysadm::SysInfo::cpuTemps());
|
||||
}
|
||||
if(act=="externalmounts"){
|
||||
ok = true;
|
||||
out->insert("externalmounts", sysadm::SysInfo::externalDevicePaths());
|
||||
}
|
||||
|
||||
} //end of "action" key usage
|
||||
|
||||
|
||||
Reference in New Issue
Block a user