add serverGraphDuration config option

This commit is contained in:
Nick Krecklow
2020-05-08 01:54:04 -05:00
parent aee7b565b2
commit f467fa1938
10 changed files with 52 additions and 55 deletions

View File

@ -14,27 +14,19 @@ class Database {
})
}
loadGraphPoints (graphDuration, callback) {
// Query recent pings
const endTime = new Date().getTime()
const startTime = endTime - graphDuration
this.getRecentPings(startTime, endTime, pingData => {
loadGraphPoints (length, callback) {
this.getRecentPings(length, pingData => {
const graphPointsByIp = []
for (const row of pingData) {
// Avoid loading outdated records
// This shouldn't happen and is mostly a sanity measure
if (startTime - row.timestamp <= graphDuration) {
// Load into temporary array
// This will be culled prior to being pushed to the serverRegistration
let graphPoints = graphPointsByIp[row.ip]
if (!graphPoints) {
graphPoints = graphPointsByIp[row.ip] = []
}
graphPoints.push([row.timestamp, row.playerCount])
// Load into temporary array
// This will be culled prior to being pushed to the serverRegistration
let graphPoints = graphPointsByIp[row.ip]
if (!graphPoints) {
graphPoints = graphPointsByIp[row.ip] = []
}
graphPoints.push([row.timestamp, row.playerCount])
}
Object.keys(graphPointsByIp).forEach(ip => {
@ -80,10 +72,9 @@ class Database {
})
}
getRecentPings (startTime, endTime, callback) {
this._sql.all('SELECT * FROM pings WHERE timestamp >= ? AND timestamp <= ?', [
startTime,
endTime
getRecentPings (length, callback) {
this._sql.all('SELECT * FROM pings WHERE 1 LIMIT ?', [
length
], (_, data) => callback(data))
}