diff --git a/servatrice/servatrice.sql b/servatrice/servatrice.sql index b2362e6a..192cdef7 100644 --- a/servatrice/servatrice.sql +++ b/servatrice/servatrice.sql @@ -119,9 +119,11 @@ CREATE TABLE IF NOT EXISTS `cockatrice_users` ( CREATE TABLE `cockatrice_uptime` ( `id_server` tinyint(3) NOT NULL, `timest` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', - `uptime` int(11) DEFAULT NULL, - `users_count` int(11) DEFAULT NULL, - `games_count` int(11) DEFAULT NULL, + `uptime` int(11) NOT NULL, + `users_count` int(11) NOT NULL, + `games_count` int(11) NOT NULL, + `rx_bytes` int(11) NOT NULL, + `tx_bytes` int(11) NOT NULL, PRIMARY KEY (`timest`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; diff --git a/servatrice/src/servatrice.cpp b/servatrice/src/servatrice.cpp index 344d05e3..dbb7937a 100644 --- a/servatrice/src/servatrice.cpp +++ b/servatrice/src/servatrice.cpp @@ -398,15 +398,26 @@ void Servatrice::statusUpdate() uptime += statusUpdateClock->interval() / 1000; + txBytesMutex.lock(); + quint64 tx = txBytes; + txBytes = 0; + txBytesMutex.unlock(); + rxBytesMutex.lock(); + quint64 rx = rxBytes; + rxBytes = 0; + rxBytesMutex.unlock(); + QMutexLocker locker(&dbMutex); checkSql(); QSqlQuery query; - query.prepare("insert into " + dbPrefix + "_uptime (id_server, timest, uptime, users_count, games_count) values(:id, NOW(), :uptime, :users_count, :games_count)"); + query.prepare("insert into " + dbPrefix + "_uptime (id_server, timest, uptime, users_count, games_count, tx_bytes, rx_bytes) values(:id, NOW(), :uptime, :users_count, :games_count, :tx, :rx)"); query.bindValue(":id", serverId); query.bindValue(":uptime", uptime); query.bindValue(":users_count", uc); query.bindValue(":games_count", gc); + query.bindValue(":tx", tx); + query.bindValue(":rx", rx); execSqlQuery(query); } @@ -424,6 +435,20 @@ void Servatrice::scheduleShutdown(const QString &reason, int minutes) shutdownTimeout(); } +void Servatrice::incTxBytes(quint64 num) +{ + txBytesMutex.lock(); + txBytes += num; + txBytesMutex.unlock(); +} + +void Servatrice::incRxBytes(quint64 num) +{ + rxBytesMutex.lock(); + rxBytes += num; + rxBytesMutex.unlock(); +} + void Servatrice::shutdownTimeout() { QMutexLocker locker(&serverMutex); diff --git a/servatrice/src/servatrice.h b/servatrice/src/servatrice.h index 53faa70a..e22aa01c 100644 --- a/servatrice/src/servatrice.h +++ b/servatrice/src/servatrice.h @@ -75,6 +75,8 @@ public: QMap getBuddyList(const QString &name); QMap getIgnoreList(const QString &name); void scheduleShutdown(const QString &reason, int minutes); + void incTxBytes(quint64 num); + void incRxBytes(quint64 num); protected: int startSession(const QString &userName, const QString &address); void endSession(int sessionId); @@ -89,6 +91,8 @@ private: int serverId; bool threaded; int uptime; + QMutex txBytesMutex, rxBytesMutex; + quint64 txBytes, rxBytes; int maxGameInactivityTime, maxPlayerInactivityTime; int maxUsersPerAddress, messageCountingInterval, maxMessageCountPerInterval, maxMessageSizePerInterval, maxGamesPerUser; ServerInfo_User *evalUserQueryResult(const QSqlQuery &query, bool complete); diff --git a/servatrice/src/serversocketinterface.cpp b/servatrice/src/serversocketinterface.cpp index 25ac9be8..ecd1c000 100644 --- a/servatrice/src/serversocketinterface.cpp +++ b/servatrice/src/serversocketinterface.cpp @@ -86,6 +86,7 @@ void ServerSocketInterface::flushXmlBuffer() QMutexLocker locker(&xmlBufferMutex); if (xmlBuffer.isEmpty()) return; + servatrice->incTxBytes(xmlBuffer.size()); socket->write(xmlBuffer.toUtf8()); socket->flush(); xmlBuffer.clear(); @@ -94,6 +95,7 @@ void ServerSocketInterface::flushXmlBuffer() void ServerSocketInterface::readClient() { QByteArray data = socket->readAll(); + servatrice->incRxBytes(data.size()); if (!data.contains("logMessage(QString(data), this); xmlReader->addData(data);