Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
eb6520a7
Commit
eb6520a7
authored
Dec 04, 2011
by
Max-Wilhelm Bruker
Browse files
store network traffic statistics in database
parent
1455c093
Changes
4
Hide whitespace changes
Inline
Side-by-side
servatrice/servatrice.sql
View file @
eb6520a7
...
@@ -119,9 +119,11 @@ CREATE TABLE IF NOT EXISTS `cockatrice_users` (
...
@@ -119,9 +119,11 @@ CREATE TABLE IF NOT EXISTS `cockatrice_users` (
CREATE
TABLE
`cockatrice_uptime`
(
CREATE
TABLE
`cockatrice_uptime`
(
`id_server`
tinyint
(
3
)
NOT
NULL
,
`id_server`
tinyint
(
3
)
NOT
NULL
,
`timest`
datetime
NOT
NULL
DEFAULT
'0000-00-00 00:00:00'
,
`timest`
datetime
NOT
NULL
DEFAULT
'0000-00-00 00:00:00'
,
`uptime`
int
(
11
)
DEFAULT
NULL
,
`uptime`
int
(
11
)
NOT
NULL
,
`users_count`
int
(
11
)
DEFAULT
NULL
,
`users_count`
int
(
11
)
NOT
NULL
,
`games_count`
int
(
11
)
DEFAULT
NULL
,
`games_count`
int
(
11
)
NOT
NULL
,
`rx_bytes`
int
(
11
)
NOT
NULL
,
`tx_bytes`
int
(
11
)
NOT
NULL
,
PRIMARY
KEY
(
`timest`
)
PRIMARY
KEY
(
`timest`
)
)
ENGINE
=
MyISAM
DEFAULT
CHARSET
=
utf8
;
)
ENGINE
=
MyISAM
DEFAULT
CHARSET
=
utf8
;
...
...
servatrice/src/servatrice.cpp
View file @
eb6520a7
...
@@ -398,15 +398,26 @@ void Servatrice::statusUpdate()
...
@@ -398,15 +398,26 @@ void Servatrice::statusUpdate()
uptime
+=
statusUpdateClock
->
interval
()
/
1000
;
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
);
QMutexLocker
locker
(
&
dbMutex
);
checkSql
();
checkSql
();
QSqlQuery
query
;
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
(
":id"
,
serverId
);
query
.
bindValue
(
":uptime"
,
uptime
);
query
.
bindValue
(
":uptime"
,
uptime
);
query
.
bindValue
(
":users_count"
,
uc
);
query
.
bindValue
(
":users_count"
,
uc
);
query
.
bindValue
(
":games_count"
,
gc
);
query
.
bindValue
(
":games_count"
,
gc
);
query
.
bindValue
(
":tx"
,
tx
);
query
.
bindValue
(
":rx"
,
rx
);
execSqlQuery
(
query
);
execSqlQuery
(
query
);
}
}
...
@@ -424,6 +435,20 @@ void Servatrice::scheduleShutdown(const QString &reason, int minutes)
...
@@ -424,6 +435,20 @@ void Servatrice::scheduleShutdown(const QString &reason, int minutes)
shutdownTimeout
();
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
()
void
Servatrice
::
shutdownTimeout
()
{
{
QMutexLocker
locker
(
&
serverMutex
);
QMutexLocker
locker
(
&
serverMutex
);
...
...
servatrice/src/servatrice.h
View file @
eb6520a7
...
@@ -75,6 +75,8 @@ public:
...
@@ -75,6 +75,8 @@ public:
QMap
<
QString
,
ServerInfo_User
*>
getBuddyList
(
const
QString
&
name
);
QMap
<
QString
,
ServerInfo_User
*>
getBuddyList
(
const
QString
&
name
);
QMap
<
QString
,
ServerInfo_User
*>
getIgnoreList
(
const
QString
&
name
);
QMap
<
QString
,
ServerInfo_User
*>
getIgnoreList
(
const
QString
&
name
);
void
scheduleShutdown
(
const
QString
&
reason
,
int
minutes
);
void
scheduleShutdown
(
const
QString
&
reason
,
int
minutes
);
void
incTxBytes
(
quint64
num
);
void
incRxBytes
(
quint64
num
);
protected:
protected:
int
startSession
(
const
QString
&
userName
,
const
QString
&
address
);
int
startSession
(
const
QString
&
userName
,
const
QString
&
address
);
void
endSession
(
int
sessionId
);
void
endSession
(
int
sessionId
);
...
@@ -89,6 +91,8 @@ private:
...
@@ -89,6 +91,8 @@ private:
int
serverId
;
int
serverId
;
bool
threaded
;
bool
threaded
;
int
uptime
;
int
uptime
;
QMutex
txBytesMutex
,
rxBytesMutex
;
quint64
txBytes
,
rxBytes
;
int
maxGameInactivityTime
,
maxPlayerInactivityTime
;
int
maxGameInactivityTime
,
maxPlayerInactivityTime
;
int
maxUsersPerAddress
,
messageCountingInterval
,
maxMessageCountPerInterval
,
maxMessageSizePerInterval
,
maxGamesPerUser
;
int
maxUsersPerAddress
,
messageCountingInterval
,
maxMessageCountPerInterval
,
maxMessageSizePerInterval
,
maxGamesPerUser
;
ServerInfo_User
*
evalUserQueryResult
(
const
QSqlQuery
&
query
,
bool
complete
);
ServerInfo_User
*
evalUserQueryResult
(
const
QSqlQuery
&
query
,
bool
complete
);
...
...
servatrice/src/serversocketinterface.cpp
View file @
eb6520a7
...
@@ -86,6 +86,7 @@ void ServerSocketInterface::flushXmlBuffer()
...
@@ -86,6 +86,7 @@ void ServerSocketInterface::flushXmlBuffer()
QMutexLocker
locker
(
&
xmlBufferMutex
);
QMutexLocker
locker
(
&
xmlBufferMutex
);
if
(
xmlBuffer
.
isEmpty
())
if
(
xmlBuffer
.
isEmpty
())
return
;
return
;
servatrice
->
incTxBytes
(
xmlBuffer
.
size
());
socket
->
write
(
xmlBuffer
.
toUtf8
());
socket
->
write
(
xmlBuffer
.
toUtf8
());
socket
->
flush
();
socket
->
flush
();
xmlBuffer
.
clear
();
xmlBuffer
.
clear
();
...
@@ -94,6 +95,7 @@ void ServerSocketInterface::flushXmlBuffer()
...
@@ -94,6 +95,7 @@ void ServerSocketInterface::flushXmlBuffer()
void
ServerSocketInterface
::
readClient
()
void
ServerSocketInterface
::
readClient
()
{
{
QByteArray
data
=
socket
->
readAll
();
QByteArray
data
=
socket
->
readAll
();
servatrice
->
incRxBytes
(
data
.
size
());
if
(
!
data
.
contains
(
"<cmd type=
\"
ping
\"
"
))
if
(
!
data
.
contains
(
"<cmd type=
\"
ping
\"
"
))
logger
->
logMessage
(
QString
(
data
),
this
);
logger
->
logMessage
(
QString
(
data
),
this
);
xmlReader
->
addData
(
data
);
xmlReader
->
addData
(
data
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment