added more states to systemmonitor
parent
fff482f1d5
commit
5a1677a80b
|
|
@ -64,7 +64,7 @@ void DevicePluginSystemMonitor::onRefreshTimer()
|
||||||
{
|
{
|
||||||
QProcess *p = new QProcess(this);
|
QProcess *p = new QProcess(this);
|
||||||
connect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(onProcessFinished(int,QProcess::ExitStatus)));
|
connect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(onProcessFinished(int,QProcess::ExitStatus)));
|
||||||
p->start("ps", {"-C", "nymead", "-o", "rss="});
|
p->start("ps", {"-C", "nymead", "-o", "%mem=,vsz=,rss=,pcpu="});
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginSystemMonitor::onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
void DevicePluginSystemMonitor::onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
||||||
|
|
@ -76,15 +76,38 @@ void DevicePluginSystemMonitor::onProcessFinished(int exitCode, QProcess::ExitSt
|
||||||
qWarning(dcSystemMonitor) << "Error reading process memory usage:" << p->readAllStandardError();
|
qWarning(dcSystemMonitor) << "Error reading process memory usage:" << p->readAllStandardError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QByteArray data = p->readAllStandardOutput().trimmed();
|
QString data = QString(p->readAllStandardOutput().trimmed()).replace(QRegExp("[ ]{2,}"), " ");
|
||||||
|
QStringList parts = data.split(' ');
|
||||||
|
if (parts.count() != 4) {
|
||||||
|
qCWarning(dcSystemMonitor()) << "Unexpected result from ps" << data << parts;
|
||||||
|
return;
|
||||||
|
}
|
||||||
bool ok;
|
bool ok;
|
||||||
qreal rssMem = data.toDouble(&ok);
|
qreal percentMem = parts.at(0).toDouble(&ok);
|
||||||
|
if (!ok) {
|
||||||
|
qWarning(dcSystemMonitor) << "Failed to parse % memory value to a number:" << parts.at(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
qint64 virtualMem = parts.at(1).toLongLong(&ok);
|
||||||
|
if (!ok) {
|
||||||
|
qWarning(dcSystemMonitor) << "Failed to parse virtual memory value to a number:" << parts.at(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
quint64 rssMem = parts.at(2).toLongLong(&ok);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
qWarning(dcSystemMonitor) << "Failed to parse RSS memory value to a number:" << data;
|
qWarning(dcSystemMonitor) << "Failed to parse RSS memory value to a number:" << data;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
qreal cpuUsage = parts.at(3).toDouble(&ok);
|
||||||
|
if (!ok) {
|
||||||
|
qWarning(dcSystemMonitor) << "Failed to parse CPU usage value to a number:" << parts.at(3);
|
||||||
|
return;
|
||||||
|
}
|
||||||
foreach (Device *dev, myDevices()) {
|
foreach (Device *dev, myDevices()) {
|
||||||
dev->setStateValue(systemMonitorRssMemoryStateTypeId, rssMem);
|
dev->setStateValue(systemMonitorRssMemoryStateTypeId, rssMem);
|
||||||
|
dev->setStateValue(systemMonitorPercentMemoryStateTypeId, percentMem);
|
||||||
|
dev->setStateValue(systemMonitorVirtualMemoryStateTypeId, virtualMem);
|
||||||
|
dev->setStateValue(systemMonitorCpuUsageStateTypeId, cpuUsage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,43 @@
|
||||||
"createMethods": [ "manual" ],
|
"createMethods": [ "manual" ],
|
||||||
"paramTypes": [ ],
|
"paramTypes": [ ],
|
||||||
"stateTypes": [
|
"stateTypes": [
|
||||||
|
{
|
||||||
|
"id": "56f8fac2-1021-4b96-bf15-23b21bb85b4c",
|
||||||
|
"name": "cpuUsage",
|
||||||
|
"displayName": "CPU usage",
|
||||||
|
"displayNameEvent": "CPU usage changed",
|
||||||
|
"type": "double",
|
||||||
|
"unit": "Percentage",
|
||||||
|
"defaultValue": 0,
|
||||||
|
"minValue": 0,
|
||||||
|
"maxValue": 100
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "efe2d520-3b35-4668-b6f5-db3df0c8bf0d",
|
||||||
|
"name": "percentMemory",
|
||||||
|
"displayName": "memory usage",
|
||||||
|
"displayNameEvent": "memory usage changed",
|
||||||
|
"type": "double",
|
||||||
|
"unit": "Percentage",
|
||||||
|
"defaultValue": 0,
|
||||||
|
"minValue": 0,
|
||||||
|
"maxValue": 100
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "d9671ee3-51be-4cf8-8601-125c0684aec9",
|
"id": "d9671ee3-51be-4cf8-8601-125c0684aec9",
|
||||||
"name": "rssMemory",
|
"name": "rssMemory",
|
||||||
"displayName": "RSS memory usage",
|
"displayName": "RSS memory usage",
|
||||||
"displayNameEvent": "RSS memory usage changed",
|
"displayNameEvent": "RSS memory usage changed",
|
||||||
"type": "double",
|
"type": "int",
|
||||||
|
"unit": "KiloByte",
|
||||||
|
"defaultValue": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "6d71b001-c7fe-4f08-941d-47009b710d94",
|
||||||
|
"name": "virtualMemory",
|
||||||
|
"displayName": "virtual memory usage",
|
||||||
|
"displayNameEvent": "virtual memory usage changed",
|
||||||
|
"type": "int",
|
||||||
"unit": "KiloByte",
|
"unit": "KiloByte",
|
||||||
"defaultValue": 0
|
"defaultValue": 0
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue