Monitoring Interface
TypeScript Support
A monitoring object has an associated TypeScript type:
- Type Name -
Monitoring - Package -
@resolve-js/core
A monitoring object's interface is the same as the interface of a monitoring adapter except for the getMetrics and clearMetrics methods that require a monitoring adapter ID as an argument.
A monitoring object exposes the following API:
| Member Name | Description |
|---|---|
error | Registers an occurred error. |
execution | Registers an execution of an operation. |
duration | Registers the duration of an operation. |
time | Starts execution time measurement. |
timeEnd | Ends execution time measurement and registers the resulting duration. |
custom | Registers a custom metric. |
publish | Defined by an implementation, publishes the collected metrics to the intended destination. |
rate | Registers operation execution rate during the specified time interval in seconds. |
group | Creates a monitoring group. |
getMetrics | Gets a list of collected metrics. |
clearMetrics | Clears the list of collected metrics. |
errorā
Registers an occurred error. The default implementation increments the count of the "Errors" metric.
Exampleā
try {
...
} catch (error) {
monitoring.error(error)
}
Argumentsā
| Argument Name | Type | Description |
|---|---|---|
error | An error object. | An error to add to monitoring metrics. |
executionā
Registers an operation's execution. The default implementation increments the count of the "Executions" metric. The execution method can also be passed an optional error parameter. If this parameter is not null, the function registers the error in metrics.
Exampleā
monitoring.execution()
Argumentsā
| Argument Name | Type | Description |
|---|---|---|
error? | An error object or null | An error to add to monitoring metrics. |
durationā
Registers the duration of an operation. The default implementation adds the specified value in milliseconds to the "Duration" metric.
Exampleā
monitoring.duration(
'myOperation',
duration / operations.length,
operations.length
)
Argumentsā
| Argument Name | Type | Description |
|---|---|---|
label | string | A text label to add to the 'Label' dimension. |
duration | number | An operation duration in milliseconds. |
count? | number | A number to add to the metric's count. Defaults to 1. |
timeā
Starts a timer to measure execution time.
Exampleā
monitoring.time('Execution', startTimestamp)
Argumentsā
| Argument Name | Type | Description |
|---|---|---|
name | string | The ID of the started timer. |
timestamp? | number | A moment in time from which to start counting. Defaults to Date.now(). |
timeEndā
Ends time measurement and registers the resulting duration. The default implementation adds the measured time value in milliseconds to the "Duration" metric.
Exampleā
monitoring.timeEnd('Execution')
Argumentsā
| Argument Name | Type | Description |
|---|---|---|
name | string | The ID of the timer to stop. |
timestamp? | number | A moment in time at which to stop counting. Defaults to Date.now(). |
customā
Registers the specified custom metric. If the metric object's value and/or count fields are not specified, the default implementation sets them to 1.
Exampleā
monitoring.custom(myMetric)
Argumentsā
| Argument Name | Type | Description |
|---|---|---|
metricData | A custom metric object. | Specifies a custom metric's data. |
publishā
Defined by an implementation, publishes the collected metrics to the intended destination.
Exampleā
await monitoring.publish()
Argumentsā
| Argument Name | Type | Description |
|---|---|---|
options? | object | Specifies additional options for the publish operation. |
Resultā
The returned value is a promise that resolves when the monitoring information is successfully published.
The monitoring adapters shipped with reSolve implement the publish function as follows:
| Module Name | Description |
|---|---|
@resolve-js/monitoring-console | Prints metrics to the text console. |
@resolve-js/monitoring-aws-cloudwatch | Publishes metrics to AWS CloudWatch. |
rateā
Registers operation execution rate during the specified time interval in seconds. The default implementation adds a value in times per N seconds to the specified metric.
Exampleā
monitoring.rate('ReadModelFeedingRate', eventCount, applyDuration / 1000)
Argumentsā
| Argument Name | Type | Description |
|---|---|---|
metricName | string | The name of the metric to add. |
count | number | A number to add to the metric's count. |
seconds? | number | The number of seconds for which to count the rate. Defaults to 1. |
groupā
Creates a monitoring group and returns a monitoring adapter instance for this group.
Exampleā
const groupMonitoring = monitoring.group({ Part: 'ReadModel' })
Argumentsā
| Argument Name | Type | Description |
|---|---|---|
config | A key-value pair object. | A key-value pair that identifies the group. |
Resultā
A monitoring object instance that operates on the created group.
getMetricsā
Gets a list of collected metrics.
Exampleā
const metrics = getMetrics('default')
| Argument Name | Type | Description |
|---|---|---|
id | string | The metrics adapter ID as specified in the application configuration. |
Resultā
The returned value is an array of metric objects.
clearMetricsā
Exampleā
monitoring.clearMetrics('default')
Clear the list of collected metrics.
| Argument Name | Type | Description |
|---|---|---|
id | string | The metrics adapter ID as specified in the application configuration. |