mirror of https://github.com/zlatinb/muwire
record the number of connections in the db every minute. Gitlab issue #49
parent
44eaa3986b
commit
33f38144eb
|
@ -43,6 +43,7 @@ class MuWireSettings {
|
|||
|
||||
int peerConnections
|
||||
int leafConnections
|
||||
int connectionHistory
|
||||
|
||||
int responderCacheSize
|
||||
|
||||
|
@ -118,6 +119,9 @@ class MuWireSettings {
|
|||
leafConnections = Integer.valueOf(props.getProperty("leafConnections","512"))
|
||||
peerConnections = Integer.valueOf(props.getProperty("peerConnections","128"))
|
||||
|
||||
// connection stats history
|
||||
connectionHistory = Integer.valueOf(props.getProperty("connectionHistory","1024"))
|
||||
|
||||
// responder cache settings
|
||||
responderCacheSize = Integer.valueOf(props.getProperty("responderCacheSize","32"))
|
||||
|
||||
|
@ -195,6 +199,9 @@ class MuWireSettings {
|
|||
props.setProperty("peerConnections", String.valueOf(peerConnections))
|
||||
props.setProperty("leafConnections", String.valueOf(leafConnections))
|
||||
|
||||
// connection history
|
||||
props.setProperty("connectionHistory", String.valueOf(connectionHistory))
|
||||
|
||||
// responder cache settings
|
||||
props.setProperty("responderCacheSize", String.valueOf(responderCacheSize))
|
||||
|
||||
|
|
|
@ -33,6 +33,10 @@ class DB2CSV {
|
|||
println "${dest.toBase32()},$it.SS,$it.SR,$it.SF,$it.RS,$it.RR,$it.RF,$it.FS,$it.FR,$it.FF"
|
||||
}
|
||||
break
|
||||
case "CONNECTION_COUNT" :
|
||||
sql.eachRow("select * from CONNECTION_COUNT") {
|
||||
println "$it.TSTAMP, $it.COUNT"
|
||||
}
|
||||
}
|
||||
sql.close()
|
||||
}
|
||||
|
|
|
@ -259,7 +259,7 @@ class H2HostCache extends HostCache {
|
|||
log.info("created table attempts $success")
|
||||
|
||||
// TODO add primary key
|
||||
success = sql.execute("CREATE TABLE IF NOT EXISTS HOST_PROFILES(" +
|
||||
success &= sql.execute("CREATE TABLE IF NOT EXISTS HOST_PROFILES(" +
|
||||
"DESTINATION VARCHAR(1024)," +
|
||||
"SS VARCHAR(16)," +
|
||||
"SR VARCHAR(16)," +
|
||||
|
@ -272,6 +272,7 @@ class H2HostCache extends HostCache {
|
|||
"FF VARCHAR(16)" +
|
||||
")")
|
||||
|
||||
success &= sql.execute("CREATE TABLE IF NOT EXISTS CONNECTION_COUNT(TSTAMP TIMESTAMP, COUNT INT)")
|
||||
timer.schedule({load()} as TimerTask, 1)
|
||||
|
||||
}
|
||||
|
@ -319,6 +320,7 @@ class H2HostCache extends HostCache {
|
|||
timer.schedule({
|
||||
purgeHopeless()
|
||||
verifyHosts()
|
||||
recordConnectionCount()
|
||||
} as TimerTask, 60000, 60000)
|
||||
loaded = true
|
||||
}
|
||||
|
@ -385,4 +387,11 @@ class H2HostCache extends HostCache {
|
|||
|
||||
}
|
||||
|
||||
private synchronized void recordConnectionCount() {
|
||||
int count = connSupplier.get().size()
|
||||
def tstamp = SDF.format(new Date())
|
||||
sql.execute("insert into CONNECTION_COUNT values('$tstamp','$count')")
|
||||
sql.execute("delete from CONNECTION_COUNT where TSTAMP not in (select TSTAMP from CONNECTION_COUNT order by TSTAMP desc limit ${settings.connectionHistory})")
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue