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

# stats/StatsProvider

## Interfaces

### StatsProvider

Defined in: [packages/prismarine/src/stats/StatsProvider.ts:26](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsProvider.ts#L26)

Reads the server's metrics and sends them somewhere, as a transport carries sessions. Each
provider owns its schedule: one service dictates an interval, and a scrape endpoint has none.

#### Properties

##### id

> `readonly` **id**: `string`

Defined in: [packages/prismarine/src/stats/StatsProvider.ts:28](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsProvider.ts#L28)

A short name for logs, such as `bstats`.

#### Methods

##### start()

> **start**(`context`): `void` \| `Promise`\<`void`\>

Defined in: [packages/prismarine/src/stats/StatsProvider.ts:30](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsProvider.ts#L30)

Starts reporting. Runs on every kernel start.

###### Parameters

###### context

[`StatsProviderContext`](#statsprovidercontext)

###### Returns

`void` \| `Promise`\<`void`\>

##### stop()

> **stop**(): `void` \| `Promise`\<`void`\>

Defined in: [packages/prismarine/src/stats/StatsProvider.ts:36](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsProvider.ts#L36)

Stops reporting and leaves no timer or request pending. Runs on every kernel stop. A stop
that arrives while `start` is still pending calls it at once and again when that `start`
returns, so it must not assume the start finished, and a second call must be harmless.

###### Returns

`void` \| `Promise`\<`void`\>

***

### StatsProviderContext

Defined in: [packages/prismarine/src/stats/StatsProvider.ts:13](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsProvider.ts#L13)

What the stats module hands a provider when it starts. The timer is injected, so a test drives
a provider's schedule on a clock it moves by hand.

#### Properties

##### logger

> `readonly` **logger**: [`KernelLogger`](https://jsprismarine.dev/api/@jsprismarine/kernel/index.md#kernellogger)

Defined in: [packages/prismarine/src/stats/StatsProvider.ts:17](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsProvider.ts#L17)

A logger scoped to the provider's id.

##### registry

> `readonly` **registry**: [`StatsRegistry`](https://jsprismarine.dev/api/@jsprismarine/prismarine/stats/StatsRegistry/classes/StatsRegistry.md)

Defined in: [packages/prismarine/src/stats/StatsProvider.ts:15](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsProvider.ts#L15)

The server's metrics, read with [StatsRegistry.snapshot](https://jsprismarine.dev/api/@jsprismarine/prismarine/stats/StatsRegistry/classes/StatsRegistry.md#snapshot) or [StatsRegistry.read](https://jsprismarine.dev/api/@jsprismarine/prismarine/stats/StatsRegistry/classes/StatsRegistry.md#read).

##### setTimer

> `readonly` **setTimer**: `CancelableTimer`

Defined in: [packages/prismarine/src/stats/StatsProvider.ts:19](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsProvider.ts#L19)

Schedules a callback; an unreferenced `setTimeout` on a running server.

## Type Aliases

### StatsTimer

> **StatsTimer** = `CancelableTimer`

Defined in: [packages/prismarine/src/stats/StatsProvider.ts:7](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/stats/StatsProvider.ts#L7)

Runs a callback once after a delay, and returns a function that cancels it.
