Commit cfce862d authored by bstrong5280's avatar bstrong5280
Browse files

V2,0

Rewritten to use new sensor API.
Improved plotter smoothing, doubled amount of plot history.
parent 7f85ec3e
Version 2.0
Rewritten to use new sensor API.
Improved plotter smoothing, doubled amount of plot history.
Version 1.03
Fixed disk space for drives larger than 2TiB.
Minor code clean up.
......
......@@ -4,11 +4,11 @@ Plasmoid to view several Items from system Monitor. Each Item has its own toolti
## Requirements
Plasma 5 shell (plasma >= 5.7)
Plasma 5 shell (plasma >= 5.7), Starting with Version 2.0 (plasma > 20.0).
## Installation
(plasma > 5.20) may need to install ksysguardd.
Version 1.03 and below, with plasma > 5.20 may need to install ksysguardd.
### From store.kde.org
......
/*
* Copyright 2021 Barry Strong <bstrong@softtechok.com>
*
* This file is part of System Monitor Plasmoid
*
* System Monitor Plasmoid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* System Monitor Plasmoid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with System Monitor Plasmoid. If not, see <https://www.gnu.org/licenses/>.
*/
#include <QtDBus/QtDBus>
#include "dbusmodel.h"
DbusModel::DbusModel(QObject *parent) : QObject(parent)
{
QDBusConnection dbusCon = QDBusConnection::sessionBus();
dbusIface = new QDBusInterface("org.kde.ksystemstats", "/", "org.kde.ksystemstats", dbusCon);
dbusCon.connect("org.kde.ksystemstats", "/", "org.kde.ksystemstats", "newSensorData", this, SLOT(newSensorData(QDBusMessage)));
}
DbusModel::~DbusModel()
{
if (sensorList.count() != 0)
dbusIface->call("unsubscribe", sensorList);
dbusIface->disconnect();
}
void DbusModel::sensors(const QStringList &args) {
if (sensorList.count() != 0)
dbusIface->call("unsubscribe", sensorList);
sensorList = args;
if (sensorList.count() != 0)
dbusIface->call("subscribe", sensorList);
}
QStringList DbusModel::sensors() const {
return sensorList;
}
QStringList DbusModel::allSensors(const QString &filter) {
QStringList wrk;
QString key;
const auto reply = dbusIface->call("allSensors").arguments().at(0).value<QDBusArgument>();
reply.beginMap();
while (!reply.atEnd()) {
reply.beginMapEntry();
reply >> key;
if (key.indexOf(filter) == 0)
wrk.append(key);
reply.endMapEntry();
}
return wrk;
}
double DbusModel::doubleData(const QString &key) {
struct dbusrec data;
QStringList skey;
if (key == "") {
return 0;
} else {
skey.append(key);
auto reply = dbusIface->call("sensorData",skey);
const auto result = reply.arguments().at(0).value<QDBusArgument>();
result.beginArray();
if (!result.atEnd()) {
result.beginStructure();
result >> data.name >> data.value;
result.endStructure();
result.endArray();
return data.value.toDouble();
} else {
return 0;
}
}
}
QString DbusModel::stringData(const QString &key) {
struct dbusrec data;
QStringList skey;
if (key == "") {
return 0;
} else {
skey.append(key);
auto reply = dbusIface->call("sensorData",skey);
const auto result = reply.arguments().at(0).value<QDBusArgument>();
result.beginArray();
if (!result.atEnd()) {
result.beginStructure();
result >> data.name >> data.value;
result.endStructure();
result.endArray();
return data.value.toString();
} else {
return "";
}
}
}
void DbusModel::newSensorData(const QDBusMessage &arg) {
struct dbusrec data;
QStringList keys;
QVariantList values;
const auto reply = arg.arguments().at(0).value<QDBusArgument>();
reply.beginArray();
while (!reply.atEnd()) {
reply.beginStructure();
reply >> data.name;
reply >> data.value;
keys.append(data.name);
values.append(data.value);
reply.endStructure();
}
reply.endArray();
emit newSensorData(keys, values);
}
/*
* Copyright 2021 Barry Strong <bstrong@softtechok.com>
*
* This file is part of System Monitor Plasmoid
*
* System Monitor Plasmoid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* System Monitor Plasmoid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with System Monitor Plasmoid. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef DBUSMODEL_H
#define DBUSMODEL_H
#include <QtDBus/QtDBus>
#include <QtQml/qqml.h>
struct dbusrec {
QString name;
QVariant value;
};
struct SensorInfo {
QString name;
QString shortName;
QString description;
quint32 Type;
quint32 unit;
qreal min = 0;
qreal max = 0;
};
class DbusModel : public QObject
{
Q_OBJECT
Q_PROPERTY(QStringList sensors READ sensors WRITE sensors)
QML_NAMED_ELEMENT(Dbus)
public:
DbusModel(QObject *parent=nullptr);
~DbusModel() override;
QStringList sensors() const;
void sensors(const QStringList &args);
private:
QStringList sensorList;
QDBusInterface* dbusIface;
signals:
void newSensorData(const QStringList keys, const QVariantList values);
public slots:
QStringList allSensors(const QString &filter);
double doubleData(const QString &key);
QString stringData(const QString &key);
private slots:
void newSensorData(const QDBusMessage &arg);
};
#endif // DBUSMODEL_H
/*
* Copyright 2021 Barry Strong <bstrong@softtechok.com>
*
* This file is part of System Monitor Plasmoid
*
* System Monitor Plasmoid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* System Monitor Plasmoid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with System Monitor Plasmoid. If not, see <https://www.gnu.org/licenses/>.
*/
#include <QtQml/QQmlEngineExtensionPlugin>
class QDbusModelPlugin : public QQmlEngineExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid)
};
#include "plugin.moc"
......@@ -134,9 +134,9 @@
<entry name="cpuIOWaitColor" type="Color">
<default>green</default>
</entry>
<entry name="cpuNiceColor" type="Color">
<!-- <entry name="cpuNiceColor" type="Color">
<default>yellow</default>
</entry>
</entry> -->
<entry name="memAppsColor" type="Color">
<default>blue</default>
</entry>
......
......@@ -22,10 +22,18 @@ import QtQuick.Layouts 1.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.ksysguard.sensors 1.0 as Sensors
import DbusModel 1.0
Rectangle {
id: rectangle
property var values: [1, 0, 0, 0, 0] // cores, system, user, io wait, nice
property var values: [1, 0, 0, 0] // cores, system, user, io wait
property var work: [1, 0, 0, 0]
property var cpuValues: [
{ value:0, count: 0},
{ value:0, count: 0},
{ value:0, count: 0},
{ value:0, count: 0}]
property bool showBorder: true
property bool compactView: false
......@@ -54,7 +62,7 @@ Rectangle {
property color sysColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuSystemColor : "red"
property color userColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuUserColor : "blue"
property color waitColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuIOWaitColor : "green"
property color niceColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuNiceColor : "yellow"
// property color niceColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuNiceColor : "yellow"
sourceComponent: plasmoid.configuration.cpuBarGraph ? barGraph : undefined
Component {
id: barGraph
......@@ -62,20 +70,19 @@ Rectangle {
Repeater {
model: numCores
Rectangle {
property int sysIdx: numCores == 1 ? 2 : ((index + 1) * 4) + 2
property int userIdx: numCores == 1 ? 3 : ((index + 1) * 4) + 3
property int waitIdx: numCores == 1 ? 4 : ((index + 1) * 4) + 4
property int niceIdx: numCores == 1 ? 5 : ((index + 1) * 4) + 5
property int sysIdx: numCores == 1 ? 1 : ((index + 1) * 3) + 1
property int userIdx: numCores == 1 ? 2 : ((index + 1) * 3) + 2
property int waitIdx: numCores == 1 ? 3 : ((index + 1) * 3) + 3
x: (index * barWidth) + rectangle.border.width
y: rectangle.border.width
BarGraph {
width: barWidth
height: barHeight
segments: 4
segments: 3
devisor: 100
showLabels: plasmoid.configuration.showLabels && plasmoid.configuration.showCores && !compactView
config: [sysColor, userColor, waitColor, niceColor]
barValues: [setLabel(index), values[sysIdx], values[userIdx], values[waitIdx], values[niceIdx]]
config: [sysColor, userColor, waitColor]
barValues: [setLabel(index), values[sysIdx], values[userIdx], values[waitIdx]]
}
}
}
......@@ -89,7 +96,7 @@ Rectangle {
property color sysColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuSystemColor : "red"
property color userColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuUserColor : "blue"
property color waitColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuIOWaitColor : "green"
property color niceColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuNiceColor : "yellow"
// property color niceColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuNiceColor : "yellow"
property int xDem: 1
property int yDem: 1
sourceComponent: plasmoid.configuration.cpuCircularGraph ? circleGraph : undefined
......@@ -114,15 +121,14 @@ Rectangle {
CircleGraph {
width: (rectangle.width - (rectangle.border.width * 2)) / xDem
height: (rectangle.height - (rectangle.border.width * 2)) / yDem
property int sysIdx: numCores == 1 ? 2 : ((index + 1) * 4) + 2
property int userIdx: numCores == 1 ? 3 : ((index + 1) * 4) + 3
property int waitIdx: numCores == 1 ? 4 : ((index + 1) * 4) + 4
property int niceIdx: numCores == 1 ? 5 : ((index + 1) * 4) + 5
config: [sysColor, userColor, waitColor, niceColor]
property int sysIdx: numCores == 1 ? 1 : ((index + 1) * 3) + 1
property int userIdx: numCores == 1 ? 2 : ((index + 1) * 3) + 2
property int waitIdx: numCores == 1 ? 3 : ((index + 1) * 3) + 3
config: [sysColor, userColor, waitColor]
devisor: 100
segments: 4
segments: 3
showLabels: plasmoid.configuration.showLabels && plasmoid.configuration.showCores && !compactView
segValues: [setLabel(index), values[sysIdx], values[userIdx], values[waitIdx], values[niceIdx]]
segValues: [setLabel(index), values[sysIdx], values[userIdx], values[waitIdx]]
Component.onCompleted: reArrange()
}
}
......@@ -145,7 +151,7 @@ Rectangle {
property color sysColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuSystemColor : "red"
property color userColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuUserColor : "blue"
property color waitColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuIOWaitColor : "green"
property color niceColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuNiceColor : "yellow"
// property color niceColor: plasmoid.configuration.customColors ? plasmoid.configuration.cpuNiceColor : "yellow"
sourceComponent: plasmoid.configuration.cpuPlotterGraph ? plotGraph : undefined
Component {
id: plotGraph
......@@ -158,16 +164,14 @@ Rectangle {
PlotterGraph {
width: plotWidth
height: Math.floor(plotHeight)
property int sysIdx: numCores == 1 ? 2 : ((index + 1) * 4) + 2
property int userIdx: numCores == 1 ? 3 : ((index + 1) * 4) + 3
property int waitIdx: numCores == 1 ? 4 : ((index + 1) * 4) + 4
property int niceIdx: numCores == 1 ? 5 : ((index + 1) * 4) + 5
config: [sysColor, userColor, waitColor, niceColor]
property int sysIdx: numCores == 1 ? 1 : ((index + 1) * 3) + 1
property int userIdx: numCores == 1 ? 2 : ((index + 1) * 3) + 2
property int waitIdx: numCores == 1 ? 3 : ((index + 1) * 3) + 3
config: [sysColor, userColor, waitColor]
devisor: 100
plots: 4
plots: 3
showLabels: plasmoid.configuration.showLabels && plasmoid.configuration.showCores && !compactView
plotValues: [setLabel(index), values[sysIdx], values[userIdx], values[waitIdx],
values[niceIdx], values[1]]
plotValues: [setLabel(index), values[sysIdx], values[userIdx], values[waitIdx]]
}
}
}
......@@ -203,80 +207,131 @@ Rectangle {
var system
var user
var wait
var nice
system = Number(values[2]).toFixed(2)
user = Number(values[3]).toFixed(2)
wait = Number(values[4]).toFixed(2)
nice = Number(values[5]).toFixed(2)
system = Number(values[1]).toFixed(2)
user = Number(values[2]).toFixed(2)
wait = Number(values[3]).toFixed(2)
ws = qsTr("System: ") + spaceit(system) + "%\n"
ws = ws + qsTr("User: ") + spaceit(user) + "%\n"
ws = ws + qsTr("IO Wait: ") + spaceit(wait) + "%\n"
ws = ws + qsTr("Nice: ") + spaceit(nice) + "%\n"
total = Number(system) + Number(user) + Number(wait) + Number(nice)
total = Number(system) + Number(user) + Number(wait)
ws = ws + qsTr("Total ") + spaceit(total.toFixed(2)) + "%"
return ws
}
}
}
}
PlasmaCore.DataSource {
engine: "systemmonitor"
interval: plasmoid.configuration.updateInterval * 100
property int numCores: 1
connectedSources: {
var srcs = []
srcs.push("system/cores")
srcs.push("cpu/system/sys")
srcs.push("cpu/system/user")
srcs.push("cpu/system/wait")
srcs.push("cpu/system/nice")
if (numCores > 1) {
for (var idx = 0; idx < numCores; idx++) {
srcs.push("cpu/cpu" + idx + "/sys")
srcs.push("cpu/cpu" + idx + "/user")
srcs.push("cpu/cpu" + idx + "/wait")
srcs.push("cpu/cpu" + idx + "/nice")
}
}
return srcs
}
onNewData: {
var cpuValues
cpuValues = values
if (data.value !== undefined) {
if (sourceName == "system/cores") {
Dbus {
id : dbus1
property var coreCount: 0
property var sensorList: []
property var valueIdx: 0
property var sensorKey
sensors: ["cpu/all/system",
"cpu/all/user",
"cpu/all/wait"]
onNewSensorData: {
coreCount = dbus1.doubleData("cpu/all/coreCount")
if (coreCount >= 1) {
if (!plasmoid.configuration.showCores) coreCount = 1
if (coreCount != work[0]) {
sensorList = []
sensorList.push("cpu/all/system")
sensorList.push("cpu/all/user")
sensorList.push("cpu/all/wait")
if (plasmoid.configuration.showCores) {
numCores = Number(data.value)
cpuValues[0] = numCores
for (var idx = 0; idx < coreCount; idx++) {
valueIdx = (idx * 3) + 4
cpuValues[valueIdx] = {value: 0, count: 0}
cpuValues[valueIdx + 1] = {value: 0, count: 0}
cpuValues[valueIdx + 2] = {value: 0, count: 0}
sensorList.push("cpu/cpu" +idx + "/system")
sensorList.push("cpu/cpu" +idx + "/user")
sensorList.push("cpu/cpu" +idx + "/wait")
}
work[0] = coreCount
} else {
numCores = Number(1)
cpuValues[0] = numCores
work[0] = 1
}
}
if (sourceName == "cpu/system/sys") cpuValues[2] = Number(data.value)
if (sourceName == "cpu/system/user") cpuValues[3] = Number(data.value)
if (sourceName == "cpu/system/wait") cpuValues[4] = Number(data.value)
if (sourceName == "cpu/system/nice") cpuValues[5] = Number(data.value)
if (numCores > 1) {
for (var idx = 0; idx < numCores; idx++) {
if (sourceName == "cpu/cpu" + idx + "/sys") cpuValues[((idx + 1) *4) + 2] = Number(data.value)
if (sourceName == "cpu/cpu" + idx + "/user") cpuValues[((idx + 1) *4) + 3] = Number(data.value)
if (sourceName == "cpu/cpu" + idx + "/wait") cpuValues[((idx + 1) *4) + 4] = Number(data.value)
if (sourceName == "cpu/cpu" + idx + "/nice") cpuValues[((idx + 1) *4) + 5] = Number(data.value)
dbus1.sensors = sensorList
} else {
for (var idx = 0; idx < keys.length; idx++) {
sensorKey = keys[idx]
switch (sensorKey) {
case "cpu/all/system":
cpuValues[1].value += values[idx]
cpuValues[1].count += 1
break;
case "cpu/all/user":
cpuValues[2].value += values[idx]
cpuValues[2].count += 1
break;
case "cpu/all/wait":
cpuValues[3].value += values[idx]
cpuValues[3].count += 1
break;
}
if (work[0] > 1) {
if (sensorKey.indexOf("cpu/cpu") == 0) {
for (var idy = 0; idy < work[0]; idy++) {
if (sensorKey.indexOf("cpu/cpu" + idy) == 0) {
valueIdx = (idy * 3) + 4
switch (sensorKey) {
case "cpu/cpu" + idy + "/system":
cpuValues[valueIdx].value += values[idx]
cpuValues[valueIdx].count += 1
break;
case "cpu/cpu" + idy + "/user":
cpuValues[valueIdx + 1].value += values[idx]
cpuValues[valueIdx + 1].count += 1
break;
case "cpu/cpu" + idy + "/wait":
cpuValues[valueIdx + 2].value += values[idx]
cpuValues[valueIdx + 2].count += 1
break;
}
}
}
}
}
}
}
if (cpuValues[1] === 0) {
cpuValues[1] = 1
} else {
cpuValues[1] = 0
}
}
}
Timer {
interval: plasmoid.configuration.updateInterval * 100
running: true
repeat: true
property var valueIdx: 0
property var cpuItem
onTriggered: {
for (var idx = 1; idx <= 3; idx++) {
cpuItem = cpuValues[idx]
if (cpuItem.count > 0)
work[idx] = cpuItem.value / cpuItem.count
cpuItem.value = 0
cpuItem.count = 0
}
if (work[0] > 1) {
for (var idy = 0; idy < work[0]; idy++) {
valueIdx = (idy * 3) + 4
for (var idz = 0; idz < 3; idz++) {
cpuItem = cpuValues[valueIdx + idz]
if (cpuItem.count > 0) {
work[valueIdx + idz] = cpuItem.value / cpuItem.count
cpuItem.value = 0
cpuItem.count = 0
}
}
}
values = cpuValues
}
values = work
}
}
}
......@@ -22,10 +22,17 @@ import QtQuick.Layouts 1.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.plasma.components 2.0 as PlasmaComponents
import DbusModel 1.0
Rectangle {
id: rectangle
property var values: [1, 0, "", 0, 0] // Number of disks, toggle, label, BSread, BSwrite
property var values: [1, "", 0, 0] // Number of disks, label, BSread, BSwrite
property var work: [1, "", 0, 0]
property var duValues: [
{value:0, count:0},
{value:0, count:0},
{value:0, count:0},
{value:0, count:0}]
property bool showBorder: true
property bool compactView: false