Update server statistics and add total count

more-debug
Simon Stürz 2018-09-05 18:58:19 +02:00
parent 4ff5e40088
commit 53a2925a2c
6 changed files with 59 additions and 5 deletions

View File

@ -83,7 +83,7 @@ void Engine::start(ProxyConfiguration *configuration)
m_monitorServer = new MonitorServer(configuration->monitorSocketFileName(), this);
m_monitorServer->startServer();
// Set tunning true in the next event loop
// Set running true in the next event loop
QMetaObject::invokeMethod(this, QString("setRunning").toLatin1().data(), Qt::QueuedConnection, Q_ARG(bool, true));
}

View File

@ -22,6 +22,7 @@
#include "proxyserver.h"
#include "loggingcategories.h"
#include <QSettings>
#include <QMetaObject>
#include <QVariantList>
#include <QJsonDocument>
@ -32,6 +33,8 @@ ProxyServer::ProxyServer(QObject *parent) : QObject(parent)
{
qRegisterMetaType<ProxyClient *>("ProxyClient *");
m_jsonRpcServer = new JsonRpcServer(this);
loadStatistics();
}
ProxyServer::~ProxyServer()
@ -67,6 +70,12 @@ QVariantMap ProxyServer::currentStatistics()
statisticsMap.insert("tunnelCount", m_tunnels.count());
statisticsMap.insert("troughput", m_troughput);
QVariantMap totalStatisticsMap;
totalStatisticsMap.insert("totalClientCount", m_totalClientCount);
totalStatisticsMap.insert("totalTunnelCount", m_totalTunnelCount);
totalStatisticsMap.insert("totalTraffic", m_totalTraffic);
statisticsMap.insert("total", totalStatisticsMap);
// Create client list
QVariantList clientList;
foreach (ProxyClient *client, m_proxyClients) {
@ -109,6 +118,26 @@ void ProxyServer::setRunning(bool running)
emit runningChanged();
}
void ProxyServer::loadStatistics()
{
QSettings settings;
settings.beginGroup("Statistics");
m_totalClientCount = settings.value("totalClientCount", 0).toInt();
m_totalTunnelCount = settings.value("totalTunnelCount", 0).toInt();
m_totalTraffic = settings.value("totalTraffic", 0).toInt();
settings.endGroup();
}
void ProxyServer::saveStatistics()
{
QSettings settings;
settings.beginGroup("Statistics");
settings.setValue("totalClientCount", m_totalClientCount);
settings.value("totalTunnelCount", m_totalTunnelCount);
settings.value("totalTraffic", m_totalTraffic);
settings.endGroup();
}
ProxyClient *ProxyServer::getRemoteClient(ProxyClient *proxyClient)
{
if (!m_tunnels.contains(proxyClient->token()))
@ -150,6 +179,10 @@ void ProxyServer::establishTunnel(ProxyClient *firstClient, ProxyClient *secondC
qCDebug(dcProxyServer()) << tunnel;
m_totalTunnelCount += 1;
saveStatistics();
// Notify the clients in the next event loop
QMetaObject::invokeMethod(m_jsonRpcServer, QString("sendNotification").toLatin1().data(), Qt::QueuedConnection,
Q_ARG(QString, m_jsonRpcServer->name()),
@ -176,6 +209,9 @@ void ProxyServer::onClientConnected(const QUuid &clientId, const QHostAddress &a
connect(proxyClient, &ProxyClient::authenticated, this, &ProxyServer::onProxyClientAuthenticated);
connect(proxyClient, &ProxyClient::timeoutOccured, this, &ProxyServer::onProxyClientTimeoutOccured);
m_totalClientCount += 1;
saveStatistics();
m_proxyClients.insert(clientId, proxyClient);
m_jsonRpcServer->registerClient(proxyClient);
}
@ -251,6 +287,9 @@ void ProxyServer::onClientDataAvailable(const QUuid &clientId, const QByteArray
proxyClient->addRxDataCount(data.count());
remoteClient->addTxDataCount(data.count());
m_totalTraffic += data.count();
saveStatistics();
qCDebug(dcProxyServerTraffic()) << "Pipe tunnel data:";
qCDebug(dcProxyServerTraffic()) << " --> from" << proxyClient;
qCDebug(dcProxyServerTraffic()) << " --> to" << remoteClient;

View File

@ -67,10 +67,21 @@ private:
int m_troughput = 0;
int m_troughputCounter = 0;
// Persistent statistics
int m_totalClientCount = 0;
int m_totalTunnelCount = 0;
int m_totalTraffic = 0;
// Set private properties
void setRunning(bool running);
ProxyClient *getRemoteClient(ProxyClient *proxyClient);
void loadStatistics();
void saveStatistics();
// Helper methods
ProxyClient *getRemoteClient(ProxyClient *proxyClient);
void establishTunnel(ProxyClient *firstClient, ProxyClient *secondClient);
signals:

View File

@ -41,6 +41,8 @@ void Monitor::onDisconnected()
if (!m_terminal)
return;
m_terminal->deleteLater();
delete m_terminal;
m_terminal = nullptr;
qDebug() << "Monitor disconnected.";
exit(0);
}

View File

@ -69,7 +69,6 @@ void MonitorClient::onErrorOccured(QLocalSocket::LocalSocketError socketError)
{
Q_UNUSED(socketError)
qWarning() << "Local socket error occured" << m_socket->errorString();
exit(1);
}
void MonitorClient::connectMonitor()

View File

@ -162,13 +162,16 @@ void TerminalWindow::drawWindowBorder(WINDOW *window)
void TerminalWindow::paintHeader()
{
QString headerString = QString(" Server: %1 %2 | API version %3 | Clients: %4 | Tunnels %5 | %6 | %7 ")
QString headerString = QString(" Server: %1 (%2) | API: %3 | Clients: %4, %5 | Tunnels: %6, %7 | %8 | %9 | %10")
.arg(m_dataMap.value("serverName", "-").toString())
.arg(m_dataMap.value("serverVersion", "-").toString())
.arg(m_dataMap.value("apiVersion", "-").toString())
.arg(m_dataMap.value("proxyStatistic").toMap().value("clientCount", 0).toInt())
.arg(m_dataMap.value("proxyStatistic").toMap().value("total").toMap().value("totalClientCount").toInt())
.arg(m_dataMap.value("proxyStatistic").toMap().value("tunnelCount", 0).toInt())
.arg(m_dataMap.value("proxyStatistic").toMap().value("total").toMap().value("totalTunnelCount").toInt())
.arg(humanReadableTraffic(m_dataMap.value("proxyStatistic").toMap().value("troughput", 0).toInt()) + " / s", - 13)
.arg(humanReadableTraffic(m_dataMap.value("proxyStatistic").toMap().value("total").toMap().value("totalTraffic").toInt()), - 10)
.arg((m_view == ViewClients ? "-- Clients --" : "-- Tunnels --"));
int delta = m_terminalSizeX - headerString.count();