[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/prismarine](https://jsprismarine.dev/api/@jsprismarine/prismarine/index.md) / stats/StatsMetric

# stats/StatsMetric

## Interfaces

### KindedMetric

Defined in: [packages/prismarine/src/stats/StatsMetric.ts:35](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsMetric.ts#L35)

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

- [`MetricInfo`](#metricinfo)

#### Type Parameters

##### K

`K` *extends* [`MetricKind`](#metrickind)

The metric's kind.

#### Properties

##### description

> `readonly` **description**: `string`

Defined in: [packages/prismarine/src/stats/StatsMetric.ts:23](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsMetric.ts#L23)

What the metric reports, in a sentence, such as `Players online.`.

###### Inherited from

[`MetricInfo`](#metricinfo).[`description`](#description-1)

##### kind

> `readonly` **kind**: `K`

Defined in: [packages/prismarine/src/stats/StatsMetric.ts:38](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsMetric.ts#L38)

##### name

> `readonly` **name**: `string`

Defined in: [packages/prismarine/src/stats/StatsMetric.ts:37](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsMetric.ts#L37)

A namespaced `snake_case` name, such as `jsprismarine:player_protocol`.

##### unit?

> `readonly` `optional` **unit?**: `string`

Defined in: [packages/prismarine/src/stats/StatsMetric.ts:25](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsMetric.ts#L25)

What one count or gauge value is a number of, such as `players`. Left out for a value with no unit.

###### Inherited from

[`MetricInfo`](#metricinfo).[`unit`](#unit-1)

#### Methods

##### read()

> **read**(): [`MetricValues`](#metricvalues)\[`K`\] \| `undefined`

Defined in: [packages/prismarine/src/stats/StatsMetric.ts:40](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsMetric.ts#L40)

Reads the current value, or `undefined` when the metric has nothing to report.

###### Returns

[`MetricValues`](#metricvalues)\[`K`\] \| `undefined`

***

### MetricInfo

Defined in: [packages/prismarine/src/stats/StatsMetric.ts:21](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsMetric.ts#L21)

What a metric says about itself, for a provider that shows it to people.

#### Extended by

- [`KindedMetric`](#kindedmetric)

#### Properties

##### description

> `readonly` **description**: `string`

Defined in: [packages/prismarine/src/stats/StatsMetric.ts:23](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsMetric.ts#L23)

What the metric reports, in a sentence, such as `Players online.`.

##### unit?

> `readonly` `optional` **unit?**: `string`

Defined in: [packages/prismarine/src/stats/StatsMetric.ts:25](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsMetric.ts#L25)

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](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsMetric.ts#L4)

The value each metric kind reads. The kinds describe the data, not how a provider draws it.

#### Properties

##### breakdown

> `readonly` **breakdown**: `Readonly`\<`Record`\<`string`, `Readonly`\<`Record`\<`string`, `number`\>\>\>\>

Defined in: [packages/prismarine/src/stats/StatsMetric.ts:14](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsMetric.ts#L14)

A count per inner key under each outer key, such as players per release, then protocol.

##### distribution

> `readonly` **distribution**: `Readonly`\<`Record`\<`string`, `number`\>\>

Defined in: [packages/prismarine/src/stats/StatsMetric.ts:12](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsMetric.ts#L12)

A count per key, such as players per device OS.

##### gauge

> `readonly` **gauge**: `number`

Defined in: [packages/prismarine/src/stats/StatsMetric.ts:6](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsMetric.ts#L6)

One number, such as the players online.

##### label

> `readonly` **label**: `string`

Defined in: [packages/prismarine/src/stats/StatsMetric.ts:8](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsMetric.ts#L8)

One string, such as the software version.

##### set

> `readonly` **set**: readonly `string`[]

Defined in: [packages/prismarine/src/stats/StatsMetric.ts:10](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsMetric.ts#L10)

A set of names with no count attached, such as the enabled transports.

## Type Aliases

### MetricKind

> **MetricKind** = keyof [`MetricValues`](#metricvalues)

Defined in: [packages/prismarine/src/stats/StatsMetric.ts:18](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsMetric.ts#L18)

The kind of a metric: `gauge`, `label`, `set`, `distribution` or `breakdown`.

***

### StatsMetric

> **StatsMetric** = `{ [K in MetricKind]: KindedMetric<K> }`\[[`MetricKind`](#metrickind)\]

Defined in: [packages/prismarine/src/stats/StatsMetric.ts:44](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsMetric.ts#L44)

A metric of any kind, narrowed by its `kind` field.

***

### StatsReading

> **StatsReading** = `{ [K in MetricKind]: MetricInfo & { kind: K; value: MetricValues[K] } }`\[[`MetricKind`](#metrickind)\]

Defined in: [packages/prismarine/src/stats/StatsMetric.ts:47](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsMetric.ts#L47)

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](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsMetric.ts#L60)

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`](#metricvalues)\[`K`\] \| `undefined`

Defined in: [packages/prismarine/src/stats/StatsMetric.ts:78](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsMetric.ts#L78)

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`](#metricvalues)

#### Parameters

##### metrics

`ReadonlyMap`\<`string`, [`StatsReading`](#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`](#metricvalues)\[`K`\] \| `undefined`

The value, or undefined when the metric is missing or of another kind.
