Skip to content

Metrics

The Metrics class is responsible for collecting and reporting performance data to the server. It tracks various indicators such as FPS, ping, and client-side lag.

Metrics public

Bounded to game as game.metrics. Alias: game.metricsType

Properties

PropertyTypeDescription
msElapsedSinceMetricsSentnumberTime in milliseconds since the last metrics update was sent.
metricsobjectThe current collection of performance metrics.
pingSumnumberSum of all ping samples for calculating average.
pingSamplesnumberNumber of ping samples collected.
shouldSendbooleanWhether metrics collection and reporting is active.
fpsSumnumberSum of all FPS samples for calculating average.
fpsSamplesnumberNumber of FPS samples collected.
metrics Object

The metrics object contains the following fields sent to the server:

FieldDescription
nameConstant set to "Metrics".
minFpsMinimum FPS observed.
maxFpsMaximum FPS observed.
currentFpsMost recent FPS value.
averageFpsCalculated average FPS.
framesRenderedTotal frames rendered since reset.
framesInterpolatedTotal frames rendered using interpolation.
framesExtrapolatedTotal frames rendered using extrapolation.
allocatedNetworkEntitiesTotal of tick entities and pooled network entities.
currentClientLagDifference between server time and client time.
minClientLagMinimum client lag observed.
maxClientLagMaximum client lag observed.
currentPingMost recent ping value.
minPingMinimum ping observed.
maxPingMaximum ping observed.
averagePingCalculated average ping.
longFramesNumber of frames that took longer than expected to render.
stuttersCount of frame stutters detected.
isMobileBoolean flag (0 or 1) indicating if the client is mobile.
groupGroup identifier.
timeResetsNumber of times client time was reset.
maxExtrapolationTimeMaximum time spent in extrapolation.
totalExtrapolationTimeCumulative time spent in extrapolation.
extrapolationIncidentsNumber of extrapolation occurrences.
differenceInClientTimeDiscrepancy in client time synchronization.

Methods

constructor()

ts
function constructor(): void

Initializes the metrics state and sets up event handlers for network status (close, error), server response (PACKET_ENTER_WORLD) and renderer ticks.

getFramesExtrapolated()

ts
function getFramesExtrapolated(): number

Returns the number of frames that have been extrapolated.

reset()

ts
function reset(): void

Resets all metrics counters and samples to their initial state.

updateMetrics()

ts
function updateMetrics(): boolean

Updates the internal metrics object with the latest data from the world and network. Returns true if the update was successful.

sendMetrics()

ts
function sendMetrics(): void

Sends the current metrics to the server via an RPC call if at least 5 seconds have passed since the last report.