API reference / @jsprismarine/prismarine / stats/StatsMetric
stats/StatsMetric
Interfaces
KindedMetric
Defined in: packages/prismarine/src/stats/StatsMetric.ts:35
One metric: a name, a kind, a description and a function that reads the current value.
The registry calls read only when a provider asks for the value. A metric with nothing to report at that moment returns undefined, and the reading leaves it out.
Extends
Type Parameters
K
K extends MetricKind
The metric's kind.
Properties
description
readonlydescription:string
Defined in: packages/prismarine/src/stats/StatsMetric.ts:23
What the metric reports, in a sentence, such as Players online..
Inherited from
kind
readonlykind:K
Defined in: packages/prismarine/src/stats/StatsMetric.ts:38
name
readonlyname:string
Defined in: packages/prismarine/src/stats/StatsMetric.ts:37
A namespaced snake_case name, such as jsprismarine:player_protocol.
unit?
readonlyoptionalunit?:string
Defined in: packages/prismarine/src/stats/StatsMetric.ts:25
What one count or gauge value is a number of, such as players. Left out for a value with no unit.
Inherited from
Methods
read()
read():
MetricValues[K] |undefined
Defined in: packages/prismarine/src/stats/StatsMetric.ts:40
Reads the current value, or undefined when the metric has nothing to report.
Returns
MetricValues[K] | undefined
MetricInfo
Defined in: packages/prismarine/src/stats/StatsMetric.ts:21
What a metric says about itself, for a provider that shows it to people.
Extended by
Properties
description
readonlydescription:string
Defined in: packages/prismarine/src/stats/StatsMetric.ts:23
What the metric reports, in a sentence, such as Players online..
unit?
readonlyoptionalunit?:string
Defined in: packages/prismarine/src/stats/StatsMetric.ts:25
What one count or gauge value is a number of, such as players. Left out for a value with no unit.
MetricValues
Defined in: packages/prismarine/src/stats/StatsMetric.ts:4
The value each metric kind reads. The kinds describe the data, not how a provider draws it.
Properties
breakdown
readonlybreakdown:Readonly<Record<string,Readonly<Record<string,number>>>>
Defined in: packages/prismarine/src/stats/StatsMetric.ts:14
A count per inner key under each outer key, such as players per release, then protocol.
distribution
readonlydistribution:Readonly<Record<string,number>>
Defined in: packages/prismarine/src/stats/StatsMetric.ts:12
A count per key, such as players per device OS.
gauge
readonlygauge:number
Defined in: packages/prismarine/src/stats/StatsMetric.ts:6
One number, such as the players online.
label
readonlylabel:string
Defined in: packages/prismarine/src/stats/StatsMetric.ts:8
One string, such as the software version.
set
readonlyset: readonlystring[]
Defined in: packages/prismarine/src/stats/StatsMetric.ts:10
A set of names with no count attached, such as the enabled transports.
Type Aliases
MetricKind
MetricKind = keyof
MetricValues
Defined in: packages/prismarine/src/stats/StatsMetric.ts:18
The kind of a metric: gauge, label, set, distribution or breakdown.
StatsMetric
StatsMetric =
{ [K in MetricKind]: KindedMetric<K> }[MetricKind]
Defined in: packages/prismarine/src/stats/StatsMetric.ts:44
A metric of any kind, narrowed by its kind field.
StatsReading
StatsReading =
{ [K in MetricKind]: MetricInfo & { kind: K; value: MetricValues[K] } }[MetricKind]
Defined in: packages/prismarine/src/stats/StatsMetric.ts:47
One metric's value at one moment, with its description, narrowed by its kind field.
Functions
isMetricName()
isMetricName(
name):boolean
Defined in: packages/prismarine/src/stats/StatsMetric.ts:60
Whether a metric name is a snake_case namespace and a snake_case name joined by a colon, such as jsprismarine:player_protocol or myaddon:something.
Parameters
name
string
The name to check.
Returns
boolean
True for a well-formed name.
readingValue()
readingValue<
K>(metrics,name,kind):MetricValues[K] |undefined
Defined in: packages/prismarine/src/stats/StatsMetric.ts:78
The value of one metric in a set of readings, when it is there and of the expected kind.
Type Parameters
K
K extends keyof MetricValues
Parameters
metrics
ReadonlyMap<string, StatsReading>
Readings by metric name, such as a snapshot's.
name
string
The metric name.
kind
K
The kind the caller reads it as.
Returns
MetricValues[K] | undefined
The value, or undefined when the metric is missing or of another kind.