diff --git a/systemmonitor/devicepluginsystemmonitor.cpp b/systemmonitor/devicepluginsystemmonitor.cpp index 6acd62c0..d912cb3f 100644 --- a/systemmonitor/devicepluginsystemmonitor.cpp +++ b/systemmonitor/devicepluginsystemmonitor.cpp @@ -64,7 +64,7 @@ void DevicePluginSystemMonitor::onRefreshTimer() { QProcess *p = new QProcess(this); 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) @@ -76,15 +76,38 @@ void DevicePluginSystemMonitor::onProcessFinished(int exitCode, QProcess::ExitSt qWarning(dcSystemMonitor) << "Error reading process memory usage:" << p->readAllStandardError(); 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; - 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) { qWarning(dcSystemMonitor) << "Failed to parse RSS memory value to a number:" << data; 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()) { dev->setStateValue(systemMonitorRssMemoryStateTypeId, rssMem); + dev->setStateValue(systemMonitorPercentMemoryStateTypeId, percentMem); + dev->setStateValue(systemMonitorVirtualMemoryStateTypeId, virtualMem); + dev->setStateValue(systemMonitorCpuUsageStateTypeId, cpuUsage); } } diff --git a/systemmonitor/devicepluginsystemmonitor.json b/systemmonitor/devicepluginsystemmonitor.json index 17b3fe49..442378bb 100644 --- a/systemmonitor/devicepluginsystemmonitor.json +++ b/systemmonitor/devicepluginsystemmonitor.json @@ -15,12 +15,43 @@ "createMethods": [ "manual" ], "paramTypes": [ ], "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", "name": "rssMemory", "displayName": "RSS memory usage", "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", "defaultValue": 0 }