Skip to content

Metrics

The Exot Inspector includes the metrics instrument for collecting time-series data, such as CPU and memory usage, request latency, etc.

Metrics are built on top of the measurements module, which includes an in-memory store. To integrate metrics with persistent storage, refer to the Data stores documentation.

Instrument

Access the metrics instrument via the metrics namespace:

inspector.instruments.metrics

Configuration

Configure the metrics instrument using the main Inspector configuration options:

const inspector = new Inspector({
instruments: {
metrics: {
dashboards: [],
disabled: false,
measurements: [],
},
},
});

Available configuration options:

  • dashboards: Dashboard[] An array of custom dashboards.
  • disabled: boolean: Disables the instrument. When disabled, the instrument cannot be activated, and no data will be recorded (default false).
  • measurements: MeasurementConfig[] An array of custom measurements.

Dashboards

The Inspector Application offers dashboards and charts to explore recorded metrics. Dashboards can be easily adjusted using the JSON dashboard configuration, and you can also add custom measurements and dashboards.

Monitoring dashboard

The default built-in dashboard named Monitoring includes CPU, memory, event loop delay, request count, and request latency metrics.

Custom dashboards

To add a custom dashboard, define a new dashboard in the Inspector configuration options.

import { Inspector } from '@exotjs/inspector';
import { MemoryStore } from '@exotjs/inspector/store';
const inspector = new Inspector({
instruments: {
metrics: {
dashboards: [{
name: 'My Dashboard',
panels: [{
title: 'Metric title',
measurements: ['metric_name'],
type: 'area',
}],
}],
measurements: [{
interval: 30000,
key: 'metric_name',
type: 'sum',
}],
},
},
store: new MemoryStore(),
});

Recording Metrics

To record a measurement, use the push function:

inspector.instruments.metrics.push({
metric_name: [{
label: 'some_label',
values: [1, 2, 3]
}],
});

Querying metrics

While recorded metrics can be viewed in the Application, you can programmatically retrieve metrics using the query() function.

inspector.instruments.metrics.query({
keys: ['metric_name'],
endTime: Date.now(),
startTime: Date.now() - 60000,
});

Sensors

The Inspector includes several built-in sensors for measuring runtime metrics.

CPU Sensor

Sensor name: cpu

The CPU sensor measures the CPU utilization using Node’s process.cpuUsage() function.

Memory Sensors

Sensor names:

  • memory-heap
  • memory-rss

There are two memory sensors: memory-heap and memory-rss, which collect the current memory usage using Node’s process.memoryUsage().

Event Loop Delay Sensor

Sensor name: event-loop-delay

The event loop delay (or lag) is the time span between a function’s scheduling and its actual execution. It’s an important metric indicating how “busy” a process is.

To learn more about Node’s event loop, visit the Node.js documentation.