Skip to main content
Access via:io.insights.metrics

Metrics API.

Properties (2)

Property Type Default Required Description
settings⚓︎ MetricsSettings x

Metrics settings.

started⚓︎ boolean x

Whether or not this instance is started.

7 Methods

get()⚓︎

(name: string) => Metric | undefined

Creates or retrieves a metric by name.

If a metric is already created with this name, it will be returned.

Otherwise, if settings exist for a metric with this name, either provided by the platform or by configuration, a metric will be created.

Otherwise, returns undefined.

Subsequent calls to this method with the same name return the same metric.

Parameters (1)

Name Type Required Description
name⚓︎ string

the name of the metric, e.g. platform_startup

getFromSettings()⚓︎

(settings: MetricSettings) => Metric | undefined

Creates or retrieves a metric based on the provided settings.

If a metric is already created with this name, it will be returned.

Otherwise, if settings exist for a metric with this name, either provided by the platform or by configuration, they will be merged with the settings provided to this method before creating it.

Otherwise, the settings provided will be used as is.

Subsequent calls to this method with the same name return the same metric.

Parameters (1)

Name Type Required Description
settings⚓︎ MetricSettings

settings to use when creating the metric

getObservable()⚓︎

<TData extends Attributes>(name: string, observeCallback: (result: ObservableResult<TData>) => Promise<void>, subscribeCallback?: () => Promise<void>, unsubscribeCallback?: () => Promise<void>) => Metric | undefined

Creates or retrieves an observable metric by name.

If a metric is already created with this name, it will be returned.

Otherwise, if settings exist for a metric with this name, either provided by the platform or by configuration, a metric will be created.

Otherwise, returns undefined.

Subsequent calls to this method with the same name return the same metric.

Parameters (4)

Name Type Required Description
name⚓︎ string

the name of the metric, e.g. platform_startup

observeCallback⚓︎ (result: ObservableResult<TData>) => Promise<void>

callback that provides the observable metric's value, invoked once per publishInterval

subscribeCallback⚓︎ () => Promise<void> x

optional callback invoked when the metric is started, can be used to set up subscriptions if the metric is measuring event data

unsubscribeCallback⚓︎ () => Promise<void> x

optional callback invoked when the metric is stopped, can be used to destroy subscriptions if the metric is measuring event data

getObservableFromSettings()⚓︎

<TData extends Attributes>(settings: MetricSettings, observeCallback: (result: ObservableResult<TData>) => Promise<void>, subscribeCallback?: () => Promise<void>, unsubscribeCallback?: () => Promise<void>) => Metric | undefined

Creates or retrieves an observable metric based on the provided settings.

If a metric is already created with this name, it will be returned.

Otherwise, if settings exist for a metric with this name, either provided by the platform or by configuration, they will be merged with the settings provided to this method before creating it.

Otherwise, the settings provided will be used as is.

Subsequent calls to this method with the same name return the same metric.

Parameters (4)

Name Type Required Description
settings⚓︎ MetricSettings

settings to use when creating the metric

observeCallback⚓︎ (result: ObservableResult<TData>) => Promise<void>

callback that provides the observable metric's value, invoked once per publishInterval

subscribeCallback⚓︎ () => Promise<void> x

optional callback invoked when the metric is started, can be used to set up subscriptions if the metric is measuring event data

unsubscribeCallback⚓︎ () => Promise<void> x

optional callback invoked when the metric is stopped, can be used to destroy subscriptions if the metric is measuring event data

start()⚓︎

() => Promise<void>

Starts publishing data.

stop()⚓︎

() => Promise<void>

Stops publishing data.

waitForFinalExport()⚓︎

(timeoutMs?: number) => Promise<void>

Waits for any pending data to be published, with the option to specify a timeout.

Parameters (1)

Name Type Required Description
timeoutMs⚓︎ number x

maximum time to wait for export