Print to stdout in order to make grep working
parent
06e8457744
commit
45dcf5e62a
|
|
@ -84,8 +84,8 @@ int main(int argc, char *argv[])
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (parser.isSet(noninteractiveOption)) {
|
||||
NonInteractiveMonitor *monitor = new NonInteractiveMonitor(parser.value(socketOption), parser.isSet(allOption), &application);
|
||||
if (parser.isSet(noninteractiveOption) || parser.isSet(jsonOption)) {
|
||||
NonInteractiveMonitor *monitor = new NonInteractiveMonitor(parser.value(socketOption), parser.isSet(jsonOption), parser.isSet(allOption), &application);
|
||||
Q_UNUSED(monitor);
|
||||
} else {
|
||||
if (parser.isSet(allOption)) {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#include "monitorclient.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <QJsonDocument>
|
||||
|
||||
|
|
@ -62,8 +63,10 @@ void MonitorClient::processBufferData()
|
|||
}
|
||||
|
||||
if (m_jsonMode) {
|
||||
qDebug() << qUtf8Printable(jsonDoc.toJson(QJsonDocument::Indented));
|
||||
return;
|
||||
qStdOut() << qUtf8Printable(jsonDoc.toJson(QJsonDocument::Indented)) << "\n";
|
||||
QTextStream out(stdout);
|
||||
out.flush();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
QVariantMap dataMap = jsonDoc.toVariant().toMap();
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ public:
|
|||
bool printAll() const;
|
||||
void setPrintAll(bool printAll);
|
||||
|
||||
|
||||
private:
|
||||
QLocalSocket *m_socket = nullptr;
|
||||
|
||||
|
|
|
|||
|
|
@ -29,11 +29,13 @@
|
|||
#include "utils.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QTextStream>
|
||||
|
||||
NonInteractiveMonitor::NonInteractiveMonitor(const QString &serverName, bool printAll, QObject *parent)
|
||||
: QObject{parent}
|
||||
NonInteractiveMonitor::NonInteractiveMonitor(const QString &serverName, bool jsonMode, bool printAll, QObject *parent)
|
||||
: QObject{parent},
|
||||
m_jsonMode{jsonMode}
|
||||
{
|
||||
m_monitorClient = new MonitorClient(serverName, false, this);
|
||||
m_monitorClient = new MonitorClient(serverName, m_jsonMode, this);
|
||||
m_monitorClient->setPrintAll(printAll);
|
||||
|
||||
connect(m_monitorClient, &MonitorClient::connected, this, &NonInteractiveMonitor::onConnected);
|
||||
|
|
@ -47,20 +49,20 @@ void NonInteractiveMonitor::onConnected()
|
|||
|
||||
QVariantMap tunnelProxyMap = dataMap.value("tunnelProxyStatistic").toMap();
|
||||
|
||||
qInfo().noquote() << "---------------------------------------------------------------------";
|
||||
qInfo().noquote() << "Server name:" << dataMap.value("serverName", "-").toString();
|
||||
qInfo().noquote() << "Server version:" << dataMap.value("serverVersion", "-").toString();
|
||||
qInfo().noquote() << "API version:" << dataMap.value("apiVersion", "-").toString();
|
||||
qInfo().noquote() << "Total client count:" << tunnelProxyMap.value("totalClientCount", 0).toInt();
|
||||
qInfo().noquote() << "Server connections:" << tunnelProxyMap.value("serverConnectionsCount", 0).toInt();
|
||||
qInfo().noquote() << "Client connections:" << tunnelProxyMap.value("clientConnectionsCount", 0).toInt();
|
||||
qInfo().noquote() << "Data troughput:" << Utils::humanReadableTraffic(tunnelProxyMap.value("troughput", 0).toInt()) + " / s";
|
||||
qInfo().noquote() << "---------------------------------------------------------------------";
|
||||
qStdOut() << "---------------------------------------------------------------------\n";
|
||||
qStdOut() << "Server name:" << dataMap.value("serverName", "-").toString() << "\n";
|
||||
qStdOut() << "Server version:" << dataMap.value("serverVersion", "-").toString() << "\n";
|
||||
qStdOut() << "API version:" << dataMap.value("apiVersion", "-").toString() << "\n";
|
||||
qStdOut() << "Total client count:" << tunnelProxyMap.value("totalClientCount", 0).toInt() << "\n";
|
||||
qStdOut() << "Server connections:" << tunnelProxyMap.value("serverConnectionsCount", 0).toInt() << "\n";
|
||||
qStdOut() << "Client connections:" << tunnelProxyMap.value("clientConnectionsCount", 0).toInt() << "\n";
|
||||
qStdOut() << "Data troughput:" << Utils::humanReadableTraffic(tunnelProxyMap.value("troughput", 0).toInt()) + " / s" << "\n";
|
||||
qStdOut() << "---------------------------------------------------------------------" << "\n";
|
||||
QVariantMap transportsMap = tunnelProxyMap.value("transports").toMap();
|
||||
foreach(const QString &transportInterface, transportsMap.keys()) {
|
||||
qInfo().noquote().nospace() << "Connections on " << transportInterface << ": " << transportsMap.value(transportInterface).toInt();
|
||||
qStdOut() << "Connections on " << transportInterface << ": " << transportsMap.value(transportInterface).toInt() << "\n";
|
||||
}
|
||||
qInfo().noquote() << "---------------------------------------------------------------------";
|
||||
qStdOut() << "---------------------------------------------------------------------" << "\n";
|
||||
|
||||
foreach (const QVariant &serverVariant, tunnelProxyMap.value("tunnelConnections").toList()) {
|
||||
QVariantMap serverMap = serverVariant.toMap();
|
||||
|
|
@ -83,7 +85,7 @@ void NonInteractiveMonitor::onConnected()
|
|||
.arg(Utils::humanReadableTraffic(serverMap.value("txDataCount").toInt()), - 9)
|
||||
.arg(serverMap.value("name").toString());
|
||||
|
||||
qInfo().noquote() << serverLinePrint;
|
||||
qStdOut() << serverLinePrint << "\n";
|
||||
|
||||
for (int cc = 0; cc < clientList.count(); cc++) {
|
||||
QVariantMap clientMap = clientList.at(cc).toMap();
|
||||
|
|
@ -102,7 +104,7 @@ void NonInteractiveMonitor::onConnected()
|
|||
.arg(Utils::humanReadableTraffic(serverMap.value("txDataCount").toInt()), - 9)
|
||||
.arg(clientMap.value("name").toString(), -30);
|
||||
|
||||
qInfo().noquote() << clientLinePrint;
|
||||
qStdOut() << clientLinePrint << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,10 +35,11 @@ class NonInteractiveMonitor : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit NonInteractiveMonitor(const QString &serverName, bool printAll = false, QObject *parent = nullptr);
|
||||
explicit NonInteractiveMonitor(const QString &serverName, bool jsonMode, bool printAll = false, QObject *parent = nullptr);
|
||||
|
||||
private:
|
||||
MonitorClient *m_monitorClient = nullptr;
|
||||
bool m_jsonMode = false;
|
||||
|
||||
private slots:
|
||||
void onConnected();
|
||||
|
|
|
|||
|
|
@ -28,9 +28,15 @@
|
|||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
#include <QTextStream>
|
||||
#include <QString>
|
||||
#include <QDateTime>
|
||||
|
||||
inline QTextStream& qStdOut() {
|
||||
static QTextStream ts(stdout);
|
||||
return ts;
|
||||
}
|
||||
|
||||
class Utils {
|
||||
|
||||
public:
|
||||
|
|
|
|||
Loading…
Reference in New Issue