at the end of work on ext-sysmon-1.8.0

This commit is contained in:
arcan1s 2014-04-08 22:47:03 +04:00
parent 3bfeabe537
commit 4c442a7e73
4 changed files with 84 additions and 15 deletions

View File

@ -7,8 +7,8 @@ cmake_policy (SET CMP0015 NEW)
project (pytextmonitor)
set (PROJECT_VERSION_MAJOR 1)
set (PROJECT_VERSION_MINOR 7)
set (PROJECT_VERSION_PATCH 5)
set (PROJECT_VERSION_MINOR 8)
set (PROJECT_VERSION_PATCH 0)
set (PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
message (STATUS "Version: ${PROJECT_VERSION}")

View File

@ -1,6 +1,9 @@
# Configuration file for Extended Systemmonitor DataEngine
# Uncomment needed lines
# Custom command
#CUSTOM=wget -qO- http://ifconfig.me/ip
# Set GPU device
# May be 'nvidia' (for nvidia), 'ati' (for ATI RADEON), 'ignore' or 'auto'
#GPUDEV=auto
@ -12,5 +15,15 @@
#MPDADDRESS=localhost
#MPDPORT=6600
# Custom command
#CUSTOM=wget -qO- http://ifconfig.me/ip
# Package upgrade info
## from vicious
## Arch: PKGCMD=pacman -Qu PKGNULL=0
## Debian: PKGCMD=apt-show-versions -u -b PKGNULL=0
## Ubuntu: PKGCMD=aptitude search '~U' PKGNULL=0
## Fedora: PKGCMD=yum list updates PKGNULL=3
## FreeBSD: PKGCMD=pkg_version -I -l '<' PKGNULL=0
## Mandriva: PKGCMD=urpmq --auto-select PKGNULL=0
# Commands to run, comma separated
#PKGCMD=pacman -Qu
# Number of null lines for commands, comma separated
#PKGNULL=0

View File

@ -72,13 +72,13 @@ QString ExtendedSysMon::getAutoGpu()
QStringList ExtendedSysMon::sources() const
{
QStringList source;
source.append(QString("custom"));
source.append(QString("gpu"));
source.append(QString("gputemp"));
source.append(QString("hddtemp"));
source.append(QString("pkg"));
source.append(QString("player"));
source.append(QString("ps"));
source.append(QString("custom"));
return source;
}
@ -86,12 +86,13 @@ QStringList ExtendedSysMon::sources() const
bool ExtendedSysMon::readConfiguration()
{
// pre-setup
configuration[QString("CUSTOM")] = QString("wget -qO- http://ifconfig.me/ip");
configuration[QString("GPUDEV")] = QString("auto");
configuration[QString("HDDDEV")] = QString("all");
configuration[QString("MPDADDRESS")] = QString("localhost");
configuration[QString("MPDPORT")] = QString("6600");
configuration[QString("CUSTOM")] = QString("wget -qO- http://ifconfig.me/ip");
configuration[QString("PKGCMD")] = QString("pacman -Qu");
configuration[QString("PKGNULL")] = QString("0");
QString fileStr;
// FIXME: define configuration file
@ -118,6 +119,10 @@ bool ExtendedSysMon::readConfiguration()
configuration[QString("GPUDEV")] = getAutoGpu();
if (configuration[QString("HDDDEV")] == QString("all"))
configuration[QString("HDDDEV")] = getAllHdd();
for (int i=configuration[QString("PKGNULL")].split(QString(","), QString::SkipEmptyParts).count();
i<configuration[QString("PKGCMD")].split(QString(","), QString::SkipEmptyParts).count()+1;
i++)
configuration[QString("PKGNULL")] += QString(",0");
return true;
}
@ -239,8 +244,8 @@ QStringList ExtendedSysMon::getPlayerInfo(const QString playerName,
info.append(QString("0"));
// title
info.append(QString("unknown"));
if ((playerName != QString("amarok")) ||
(playerName != QString("mpd")) ||
if ((playerName != QString("amarok")) &&
(playerName != QString("mpd")) &&
(playerName != QString("qmmp")))
return info;
QProcess command;
@ -276,7 +281,7 @@ QStringList ExtendedSysMon::getPlayerInfo(const QString playerName,
else if (playerName == QString("mpd")) {
// mpd
command.start(QString("bash -c \"echo 'currentsong\nstatus\nclose' | curl --connect-timeout 1 -fsm 3 telnet://") +
mpdAddress + QString(":") + mpdPort);
mpdAddress + QString(":") + mpdPort + QString("\""));
command.waitForFinished(-1);
qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput());
for (int i=0; i<qoutput.split(QString("\n"), QString::SkipEmptyParts).count(); i++) {
@ -323,6 +328,40 @@ QStringList ExtendedSysMon::getPlayerInfo(const QString playerName,
}
QStringList ExtendedSysMon::getPsStats()
{
int psCount = 0;
QStringList psList;
QProcess command;
QString qoutput = QString("");
command.start(QString("ps --no-headers -o command"));
command.waitForFinished(-1);
qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()).trimmed();
for (int i=0; i<qoutput.split(QString("\n"), QString::SkipEmptyParts).count(); i++)
if (qoutput.split(QString("\n"), QString::SkipEmptyParts)[i] != QString("ps --no-headers -o command")) {
psCount++;
psList.append(qoutput.split(QString("\n"), QString::SkipEmptyParts)[i]);
}
QStringList psStats;
psStats.append(QString::number(psCount));
psStats.append(psList.join(QString(",")));
return psStats;
}
int ExtendedSysMon::getUpgradeInfo(const QString pkgCommand, const int pkgNull)
{
int count = 0;
QProcess command;
QString qoutput = QString("");
command.start(QString("bash -c \"") + pkgCommand + QString("\""));
command.waitForFinished(-1);
qoutput = QTextCodec::codecForMib(106)->toUnicode(command.readAllStandardOutput()).trimmed();
count = qoutput.split(QString("\n"), QString::SkipEmptyParts).count();
return (count - pkgNull);
}
bool ExtendedSysMon::sourceRequestEvent(const QString &name)
{
return updateSourceEvent(name);
@ -332,7 +371,12 @@ bool ExtendedSysMon::sourceRequestEvent(const QString &name)
bool ExtendedSysMon::updateSourceEvent(const QString &source)
{
QString key;
if (source == QString("gpu")) {
if (source == QString("custom")) {
key = QString("custom");
QString value = getCustomCmd(configuration[QString("CUSTOM")]);
setData(source, key, value);
}
else if (source == QString("gpu")) {
key = QString("GPU");
float value = getGpu(configuration[QString("GPUDEV")]);
setData(source, key, value);
@ -349,6 +393,14 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
setData(source, deviceList[i], value);
}
}
else if (source == QString("pkg")) {
for (int i=0; i<configuration[QString("PKGCMD")].split(QString(","), QString::SkipEmptyParts).count(); i++) {
key = QString("pkgCount") + QString::number(i);
int value = getUpgradeInfo(configuration[QString("PKGCMD")].split(QString(","), QString::SkipEmptyParts)[i],
configuration[QString("PKGNULL")].split(QString(","), QString::SkipEmptyParts)[i].toInt());
setData(source, key, value);
}
}
else if (source == QString("player")) {
QStringList value;
// amarok
@ -390,12 +442,13 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
key = QString("qmmp_title");
setData(source, key, value[4]);
}
else if (source == QString("custom")) {
key = QString("custom");
QString value = getCustomCmd(configuration[QString("CUSTOM")]);
setData(source, key, value);
else if (source == QString("ps")) {
QStringList value = getPsStats();
key = QString("psCount");
setData(source, key, value[0].toInt());
key = QString("ps");
setData(source, key, value[1]);
}
return true;
}

View File

@ -34,6 +34,9 @@ public:
QStringList getPlayerInfo(const QString playerName,
const QString mpdAddress = 0,
const QString mpdPort = 0);
QStringList getPsStats();
int getUpgradeInfo(const QString pkgCommand,
const int pkgNull = 0);
protected:
bool readConfiguration();