qa: Replace deprecated qVariantFromValue() by QVariant::fromValue()
[quassel.git] / src / core / metricsserver.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2019 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #pragma once
22
23 #include <QHash>
24 #include <QObject>
25 #include <QString>
26 #include <QTcpServer>
27
28 #include "coreidentity.h"
29
30 class MetricsServer : public QObject
31 {
32     Q_OBJECT
33
34 public:
35     explicit MetricsServer(QObject* parent = nullptr);
36
37     bool startListening();
38     void stopListening(const QString& msg);
39
40     void addLoginAttempt(UserId user, bool successful);
41     void addLoginAttempt(const QString& user, bool successful);
42
43     void addSession(UserId user, const QString& name);
44     void removeSession(UserId user);
45
46     void addClient(UserId user);
47     void removeClient(UserId user);
48
49     void addNetwork(UserId user);
50     void removeNetwork(UserId user);
51
52     void transmitDataNetwork(UserId user, uint64_t size);
53     void receiveDataNetwork(UserId user, uint64_t size);
54
55     void loginSuccessful();
56     void loginFailed();
57
58     void messageQueue(UserId user, uint64_t size);
59
60     void setCertificateExpires(QDateTime expires);
61
62 private slots:
63     void incomingConnection();
64     void respond();
65
66 private:
67     QTcpServer _server, _v6server;
68
69     QHash<UserId, uint64_t> _loginAttempts{};
70     QHash<UserId, uint64_t> _successfulLogins{};
71
72     QHash<UserId, QString> _sessions{};
73
74     QHash<UserId, int64_t> _clientSessions{};
75     QHash<UserId, int64_t> _networkSessions{};
76
77     QHash<UserId, uint64_t> _networkDataTransmit{};
78     QHash<UserId, uint64_t> _networkDataReceive{};
79
80     QHash<UserId, uint64_t> _messageQueue{};
81
82     uint64_t _loginSuccessful{};
83     uint64_t _loginFailed{};
84
85     QDateTime _certificateExpires{};
86 };