add a systemmonitor plugin
parent
7123a92a01
commit
9d35c01006
|
|
@ -33,6 +33,7 @@ PLUGIN_DIRS = \
|
|||
osdomotics \
|
||||
philipshue \
|
||||
pushbullet \
|
||||
systemmonitor \
|
||||
remotessh \
|
||||
senic \
|
||||
serialportcommander \
|
||||
|
|
|
|||
|
|
@ -0,0 +1,90 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* *
|
||||
* Copyright (C) 2018 Michael Zanetti <michael.zanetti@guh.io *
|
||||
* *
|
||||
* This file is part of nymea. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Lesser General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2.1 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; If not, see *
|
||||
* <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#include "devicepluginsystemmonitor.h"
|
||||
#include "plugininfo.h"
|
||||
|
||||
|
||||
DevicePluginSystemMonitor::DevicePluginSystemMonitor()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
DevicePluginSystemMonitor::~DevicePluginSystemMonitor()
|
||||
{
|
||||
if (m_refreshTimer) {
|
||||
hardwareManager()->pluginTimerManager()->unregisterTimer(m_refreshTimer);
|
||||
}
|
||||
}
|
||||
|
||||
DeviceManager::DeviceSetupStatus DevicePluginSystemMonitor::setupDevice(Device *device)
|
||||
{
|
||||
Q_UNUSED(device)
|
||||
|
||||
if (!m_refreshTimer) {
|
||||
m_refreshTimer = hardwareManager()->pluginTimerManager()->registerTimer(2);
|
||||
connect(m_refreshTimer, &PluginTimer::timeout, this, &DevicePluginSystemMonitor::onRefreshTimer);
|
||||
}
|
||||
|
||||
|
||||
return DeviceManager::DeviceSetupStatusSuccess;
|
||||
}
|
||||
|
||||
void DevicePluginSystemMonitor::deviceRemoved(Device *device)
|
||||
{
|
||||
Q_UNUSED(device)
|
||||
|
||||
if (myDevices().isEmpty()) {
|
||||
hardwareManager()->pluginTimerManager()->unregisterTimer(m_refreshTimer);
|
||||
m_refreshTimer = nullptr;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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="});
|
||||
}
|
||||
|
||||
void DevicePluginSystemMonitor::onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
||||
{
|
||||
QProcess *p = static_cast<QProcess*>(sender());
|
||||
p->deleteLater();
|
||||
|
||||
if (exitCode != 0 || exitStatus != QProcess::NormalExit) {
|
||||
qWarning(dcSystemMonitor) << "Error reading process memory usage:" << p->readAllStandardError();
|
||||
return;
|
||||
}
|
||||
QByteArray data = p->readAllStandardOutput().trimmed();
|
||||
bool ok;
|
||||
qreal rssMem = data.toDouble(&ok);
|
||||
if (!ok) {
|
||||
qWarning(dcSystemMonitor) << "Failed to parse RSS memory value to a number:" << data;
|
||||
return;
|
||||
}
|
||||
foreach (Device *dev, myDevices()) {
|
||||
dev->setStateValue(systemMonitorRssMemoryStateTypeId, rssMem);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* *
|
||||
* Copyright (C) 2018 Michael Zanetti <michael.zanetti@guh.io *
|
||||
* *
|
||||
* This file is part of nymea. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Lesser General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2.1 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; If not, see *
|
||||
* <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#ifndef DEVICEPLUGINSYSTEMMONITOR_H
|
||||
#define DEVICEPLUGINSYSTEMMONITOR_H
|
||||
|
||||
#include "devicemanager.h"
|
||||
#include "plugin/deviceplugin.h"
|
||||
#include "plugintimer.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QProcess>
|
||||
#include <QUrlQuery>
|
||||
|
||||
|
||||
class DevicePluginSystemMonitor: public DevicePlugin {
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "io.nymea.DevicePlugin" FILE "devicepluginsystemmonitor.json")
|
||||
Q_INTERFACES(DevicePlugin)
|
||||
|
||||
public:
|
||||
explicit DevicePluginSystemMonitor();
|
||||
~DevicePluginSystemMonitor();
|
||||
|
||||
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override;
|
||||
void deviceRemoved(Device *device) override;
|
||||
|
||||
private slots:
|
||||
void onRefreshTimer();
|
||||
void onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
||||
|
||||
private:
|
||||
PluginTimer *m_refreshTimer = nullptr;
|
||||
|
||||
};
|
||||
|
||||
#endif // DEVICEPLUGINSYSTEMMONITOR_H
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"name": "systemMonitor",
|
||||
"displayName": "System Monitor",
|
||||
"id": "908b4f18-dc0c-4940-a6f7-c0c01a2861b8",
|
||||
"vendors": [
|
||||
{
|
||||
"displayName": "guh GmbH",
|
||||
"name": "guh",
|
||||
"id": "2062d64d-3232-433c-88bc-0d33c0ba2ba6",
|
||||
"deviceClasses": [
|
||||
{
|
||||
"id": "a3a15700-c251-4803-a608-0f3ddfcbd7a8",
|
||||
"name": "systemMonitor",
|
||||
"displayName": "System monitor",
|
||||
"createMethods": [ "manual" ],
|
||||
"paramTypes": [ ],
|
||||
"stateTypes": [
|
||||
{
|
||||
"id": "d9671ee3-51be-4cf8-8601-125c0684aec9",
|
||||
"name": "rssMemory",
|
||||
"displayName": "RSS memory usage",
|
||||
"displayNameEvent": "RSS memory usage changed",
|
||||
"type": "double",
|
||||
"defaultValue": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
include(../plugins.pri)
|
||||
|
||||
TARGET = $$qtLibraryTarget(nymea_devicepluginsystemmonitor)
|
||||
|
||||
SOURCES += \
|
||||
devicepluginsystemmonitor.cpp \
|
||||
|
||||
HEADERS += \
|
||||
devicepluginsystemmonitor.h \
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1">
|
||||
</TS>
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1">
|
||||
</TS>
|
||||
Loading…
Reference in New Issue