mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
store network traffic statistics in database
This commit is contained in:
parent
1455c093cc
commit
eb6520a737
4 changed files with 37 additions and 4 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue