store pingHistory as player count directly
This commit is contained in:
parent
37a88677cf
commit
3491c73b89
@ -111,12 +111,12 @@ export class App {
|
|||||||
|
|
||||||
serverRegistration.initServerStatus(payload)
|
serverRegistration.initServerStatus(payload)
|
||||||
|
|
||||||
// pingHistory is only defined when the backend has previous ping data
|
// playerCountHistory is only defined when the backend has previous ping data
|
||||||
// undefined pingHistory means this is a placeholder ping generated by the backend
|
// undefined playerCountHistory means this is a placeholder ping generated by the backend
|
||||||
if (typeof payload.pingHistory !== 'undefined') {
|
if (typeof payload.playerCountHistory !== 'undefined') {
|
||||||
// Push the historical data into the graph
|
// Push the historical data into the graph
|
||||||
// This will trim and format the data so it is ready for the graph to render once init
|
// This will trim and format the data so it is ready for the graph to render once init
|
||||||
serverRegistration.addGraphPoints(payload.pingHistory, timestampPoints)
|
serverRegistration.addGraphPoints(payload.playerCountHistory, timestampPoints)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the plot instance internally with the restructured and cleaned data
|
// Create the plot instance internally with the restructured and cleaned data
|
||||||
|
@ -96,8 +96,7 @@ export class ServerRegistration {
|
|||||||
for (let i = 0; i < points.length; i++) {
|
for (let i = 0; i < points.length; i++) {
|
||||||
const point = points[i]
|
const point = points[i]
|
||||||
const timestamp = timestampPoints[i]
|
const timestamp = timestampPoints[i]
|
||||||
|
this._graphData.push([timestamp, point])
|
||||||
this._graphData.push([timestamp, point.result ? point.result.players.online : 0])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,6 +67,8 @@ export class SocketManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(payload.servers)
|
||||||
|
|
||||||
payload.servers.forEach((serverPayload, serverId) => {
|
payload.servers.forEach((serverPayload, serverId) => {
|
||||||
this._app.addServer(serverId, serverPayload, payload.timestampPoints)
|
this._app.addServer(serverId, serverPayload, payload.timestampPoints)
|
||||||
})
|
})
|
||||||
|
@ -16,8 +16,15 @@ class ServerRegistration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handlePing (timestamp, resp, err, version) {
|
handlePing (timestamp, resp, err, version) {
|
||||||
|
const playerCount = resp ? resp.players.online : 0
|
||||||
|
|
||||||
// Store into in-memory ping data
|
// Store into in-memory ping data
|
||||||
this.addPing(resp)
|
this._pingHistory.push(playerCount)
|
||||||
|
|
||||||
|
// Trim pingHistory to avoid memory leaks
|
||||||
|
if (this._pingHistory.length > this._app.pingController.getMaxServerGraphDataLength()) {
|
||||||
|
this._pingHistory.shift()
|
||||||
|
}
|
||||||
|
|
||||||
// Only notify the frontend to append to the historical graph
|
// Only notify the frontend to append to the historical graph
|
||||||
// if both the graphing behavior is enabled and the backend agrees
|
// if both the graphing behavior is enabled and the backend agrees
|
||||||
@ -25,8 +32,6 @@ class ServerRegistration {
|
|||||||
let updateHistoryGraph = false
|
let updateHistoryGraph = false
|
||||||
|
|
||||||
if (config.logToDatabase) {
|
if (config.logToDatabase) {
|
||||||
const playerCount = resp ? resp.players.online : 0
|
|
||||||
|
|
||||||
if (this.addGraphPoint(resp !== undefined, playerCount, timestamp)) {
|
if (this.addGraphPoint(resp !== undefined, playerCount, timestamp)) {
|
||||||
updateHistoryGraph = true
|
updateHistoryGraph = true
|
||||||
}
|
}
|
||||||
@ -90,27 +95,6 @@ class ServerRegistration {
|
|||||||
return update
|
return update
|
||||||
}
|
}
|
||||||
|
|
||||||
addPing (resp) {
|
|
||||||
const ping = {}
|
|
||||||
|
|
||||||
if (resp) {
|
|
||||||
// Append a result object
|
|
||||||
// This filters out unwanted data from resp
|
|
||||||
ping.result = {
|
|
||||||
players: {
|
|
||||||
online: resp.players.online
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this._pingHistory.push(ping)
|
|
||||||
|
|
||||||
// Trim pingHistory to avoid memory leaks
|
|
||||||
if (this._pingHistory.length > this._app.pingController.getMaxServerGraphDataLength()) {
|
|
||||||
this._pingHistory.shift()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getPingHistory () {
|
getPingHistory () {
|
||||||
if (this._pingHistory.length > 0) {
|
if (this._pingHistory.length > 0) {
|
||||||
const payload = {
|
const payload = {
|
||||||
@ -127,21 +111,19 @@ class ServerRegistration {
|
|||||||
payload.graphPeakData = graphPeakData
|
payload.graphPeakData = graphPeakData
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert the latest update manually into the array
|
// Assume the ping was a success and define result
|
||||||
// This is a mutated copy of the last update to contain live metadata
|
// pingHistory does not keep error references, so its impossible to detect if this is an error
|
||||||
// The metadata is used by the frontend for rendering
|
// It is also pointless to store that data since it will be short lived
|
||||||
const lastPing = this._pingHistory[this._pingHistory.length - 1]
|
payload.result = {
|
||||||
|
players: {
|
||||||
// Conditionally append to avoid defining fields with undefined values
|
online: this._pingHistory[this._pingHistory.length - 1]
|
||||||
if (lastPing.result) {
|
}
|
||||||
payload.result = lastPing.result
|
|
||||||
} else if (lastPing.error) {
|
|
||||||
payload.error = lastPing.error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send a copy of pingHistory
|
// Send a copy of pingHistory
|
||||||
// Omit the last value since it is contained within payload
|
// Include the last value even though it is contained within payload
|
||||||
payload.pingHistory = this._pingHistory.slice(0, this._pingHistory.length - 1)
|
// The frontend will only push to its graphData from playerCountHistory
|
||||||
|
payload.playerCountHistory = this._pingHistory
|
||||||
|
|
||||||
return payload
|
return payload
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user