mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Stats
Testing time! Also new: Effects dirs are now created automatically
This commit is contained in:
parent
64fc6a9003
commit
e2ca9bcaa5
@ -178,6 +178,8 @@ public:
|
||||
int getLedMappingType() { return _ledMAppingType; };
|
||||
|
||||
int getConfigVersionId() { return _configVersionId; };
|
||||
|
||||
QJsonObject getConfig() { return _qjsonConfig; };
|
||||
|
||||
int getLatchTime() const;
|
||||
|
||||
|
34
include/utils/Stats.h
Normal file
34
include/utils/Stats.h
Normal file
@ -0,0 +1,34 @@
|
||||
// qt includes
|
||||
#include <QDebug>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QEventLoop>
|
||||
#include <QTimer>
|
||||
|
||||
// hyperion includes
|
||||
#include <utils/Logger.h>
|
||||
|
||||
class Stats : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Stats();
|
||||
~Stats();
|
||||
|
||||
private:
|
||||
Logger* _log;
|
||||
QString _hash = "";
|
||||
QNetworkAccessManager _mgr;
|
||||
|
||||
bool trigger(bool set = false);
|
||||
|
||||
private slots:
|
||||
void sendHTTP(bool put = false);
|
||||
void resolveReply(QNetworkReply *reply);
|
||||
|
||||
|
||||
};
|
@ -282,7 +282,18 @@ void EffectEngine::readEffects()
|
||||
foreach (const QString & path, efxPathList )
|
||||
{
|
||||
QDir directory(path);
|
||||
if (directory.exists())
|
||||
if (!directory.exists())
|
||||
{
|
||||
if(directory.mkpath(path))
|
||||
{
|
||||
Warning(_log, "New Effect path \"%s\" created successfull",path.toUtf8().constData() );
|
||||
}
|
||||
else
|
||||
{
|
||||
Warning(_log, "Failed to create Effect path \"%s\", please check permissions",path.toUtf8().constData() );
|
||||
}
|
||||
}
|
||||
if (directory.exists(path))
|
||||
{
|
||||
int efxCount = 0;
|
||||
QStringList filenames = directory.entryList(QStringList() << "*.json", QDir::Files, QDir::Name | QDir::IgnoreCase);
|
||||
|
@ -5,6 +5,7 @@ SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/utils)
|
||||
|
||||
SET(Utils_QT_HEADERS
|
||||
${CURRENT_HEADER_DIR}/Logger.h
|
||||
${CURRENT_HEADER_DIR}/Stats.h
|
||||
)
|
||||
|
||||
SET(Utils_HEADERS
|
||||
@ -44,6 +45,7 @@ SET(Utils_SOURCES
|
||||
${CURRENT_SOURCE_DIR}/RgbTransform.cpp
|
||||
${CURRENT_SOURCE_DIR}/RgbToRgbw.cpp
|
||||
${CURRENT_SOURCE_DIR}/SysInfo.cpp
|
||||
${CURRENT_SOURCE_DIR}/Stats.cpp
|
||||
${CURRENT_SOURCE_DIR}/jsonschema/QJsonSchemaChecker.cpp
|
||||
)
|
||||
|
||||
|
155
libsrc/utils/Stats.cpp
Normal file
155
libsrc/utils/Stats.cpp
Normal file
@ -0,0 +1,155 @@
|
||||
#include <utils/Stats.h>
|
||||
#include <utils/SysInfo.h>
|
||||
#include <HyperionConfig.h>
|
||||
#include <leddevice/LedDevice.h>
|
||||
#include <hyperion/Hyperion.h>
|
||||
|
||||
// qt includes
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
#include <QNetworkInterface>
|
||||
#include <QCryptographicHash>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QDateTime>
|
||||
|
||||
Stats::Stats()
|
||||
: QObject()
|
||||
, _log(Logger::getInstance("STATS"))
|
||||
{
|
||||
// generate hash
|
||||
QString hash;
|
||||
foreach(QNetworkInterface interface, QNetworkInterface::allInterfaces())
|
||||
{
|
||||
if (!(interface.flags() & QNetworkInterface::IsLoopBack))
|
||||
{
|
||||
_hash = QString(QCryptographicHash::hash(interface.hardwareAddress().toLocal8Bit(),QCryptographicHash::Sha1).toHex());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// stop reporting if not found
|
||||
if(_hash.isEmpty())
|
||||
{
|
||||
Warning(_log, "No interface found, abort");
|
||||
return;
|
||||
}
|
||||
|
||||
connect(&_mgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(resolveReply(QNetworkReply*)));
|
||||
|
||||
// 7 days interval
|
||||
QTimer *timer = new QTimer(this);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(sendHTTP()));
|
||||
timer->start(604800000);
|
||||
|
||||
// check instant execution required
|
||||
if(trigger())
|
||||
{
|
||||
QTimer::singleShot(0, this, [=]() {
|
||||
sendHTTP();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Stats::~Stats()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Stats::sendHTTP(bool put)
|
||||
{
|
||||
QJsonObject config = Hyperion::getInstance()->getConfig();
|
||||
SysInfo::HyperionSysInfo data = SysInfo::get();
|
||||
|
||||
QJsonObject system;
|
||||
system["kType" ] = data.kernelType;
|
||||
//system["kernelVersion" ] = data.kernelVersion;
|
||||
system["arch" ] = data.architecture;
|
||||
system["pType" ] = data.productType;
|
||||
system["pVersion" ] = data.productVersion;
|
||||
system["pName" ] = data.prettyName;
|
||||
system["version" ] = QString(HYPERION_VERSION);
|
||||
system["device" ] = LedDevice::activeDevice();
|
||||
system["id" ] = _hash;
|
||||
system["ledCount" ] = QString::number(Hyperion::getInstance()->getLedCount());
|
||||
system["comp_sm" ] = config["smoothing"].toObject().take("enable");
|
||||
system["comp_bb" ] = config["blackborderdetector"].toObject().take("enable");
|
||||
system["comp_fw" ] = config["forwarder"].toObject().take("enable");
|
||||
system["comp_udpl" ] = config["udpListener"].toObject().take("enable");
|
||||
system["comp_bobl" ] = config["boblightServer"].toObject().take("enable");
|
||||
system["comp_pc" ] = config["framegrabber"].toObject().take("enable");
|
||||
system["comp_uc" ] = config["grabberV4L2"].toArray().at(0).toObject().take("enable");
|
||||
|
||||
QJsonDocument doc(system);
|
||||
QByteArray ba = doc.toJson();
|
||||
|
||||
QNetworkRequest req;
|
||||
req.setRawHeader("Content-Type", "application/json");
|
||||
req.setRawHeader("Authorization", "Basic SHlwZXJpb25YbDQ5MlZrcXA6ZDQxZDhjZDk4ZjAwYjIw");
|
||||
|
||||
if(put)
|
||||
{
|
||||
req.setUrl(QUrl("https://api.hyperion-project.org/api/stats/"+_hash));
|
||||
_mgr.put(req,ba);
|
||||
}
|
||||
else
|
||||
{
|
||||
req.setUrl(QUrl("https://api.hyperion-project.org/api/stats"));
|
||||
_mgr.post(req,ba);
|
||||
}
|
||||
}
|
||||
|
||||
void Stats::resolveReply(QNetworkReply *reply)
|
||||
{
|
||||
if (reply->error() == QNetworkReply::NoError)
|
||||
{
|
||||
// update file timestamp
|
||||
trigger(true);
|
||||
// already created, update entry
|
||||
if(reply->readAll().startsWith("null"))
|
||||
{
|
||||
//bool put = true;
|
||||
QTimer::singleShot(0, this, [=]() {
|
||||
sendHTTP(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Stats::trigger(bool set)
|
||||
{
|
||||
QString path = QDir::homePath()+"/.hyperion/misc/";
|
||||
QDir dir;
|
||||
QFile file(path + "ts");
|
||||
|
||||
if(set && file.open(QIODevice::ReadWrite) )
|
||||
{
|
||||
QTextStream stream( &file );
|
||||
stream << "DO NOT DELETE" << endl;
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!dir.exists(path))
|
||||
{
|
||||
dir.mkpath(path);
|
||||
}
|
||||
if (!file.exists())
|
||||
{
|
||||
if(file.open(QIODevice::ReadWrite))
|
||||
{
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
QFileInfo info(file);
|
||||
QDateTime newDate = QDateTime::currentDateTime();
|
||||
QDateTime oldDate = info.lastModified();
|
||||
int diff = oldDate.daysTo(newDate);
|
||||
return diff >= 7 ? true : false;
|
||||
}
|
||||
return false;
|
||||
}
|
@ -50,6 +50,7 @@ HyperionDaemon::HyperionDaemon(QString configFile, QObject *parent)
|
||||
, _fbGrabber(nullptr)
|
||||
, _osxGrabber(nullptr)
|
||||
, _hyperion(nullptr)
|
||||
, _stats(nullptr)
|
||||
{
|
||||
loadConfig(configFile, CURRENT_CONFIG_VERSION );
|
||||
|
||||
@ -99,6 +100,7 @@ void HyperionDaemon::freeObjects()
|
||||
delete _protoServer;
|
||||
delete _boblightServer;
|
||||
delete _udpListener;
|
||||
delete _stats;
|
||||
|
||||
_v4l2Grabbers.clear();
|
||||
_amlGrabber = nullptr;
|
||||
@ -110,6 +112,7 @@ void HyperionDaemon::freeObjects()
|
||||
_protoServer = nullptr;
|
||||
_boblightServer = nullptr;
|
||||
_udpListener = nullptr;
|
||||
_stats = nullptr;
|
||||
}
|
||||
|
||||
void HyperionDaemon::run()
|
||||
@ -302,6 +305,9 @@ void HyperionDaemon::startNetworkServices()
|
||||
{
|
||||
KODIVideoChecker* kodiVideoChecker = KODIVideoChecker::getInstance();
|
||||
|
||||
// Create Stats
|
||||
_stats = new Stats();
|
||||
|
||||
// Create Json server if configuration is present
|
||||
unsigned int jsonPort = 19444;
|
||||
if (_qconfig.contains("jsonServer"))
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include <protoserver/ProtoServer.h>
|
||||
#include <boblightserver/BoblightServer.h>
|
||||
#include <udplistener/UDPListener.h>
|
||||
#include <utils/Stats.h>
|
||||
#include <QJsonObject>
|
||||
|
||||
class HyperionDaemon : public QObject
|
||||
@ -92,6 +93,7 @@ private:
|
||||
FramebufferWrapper* _fbGrabber;
|
||||
OsxWrapper* _osxGrabber;
|
||||
Hyperion* _hyperion;
|
||||
Stats* _stats;
|
||||
|
||||
unsigned _grabber_width;
|
||||
unsigned _grabber_height;
|
||||
|
Loading…
Reference in New Issue
Block a user