Skip to main content

Metrics

Server metrics collection and APM reporting via Elastic APM, with built-in HTTP/WebSocket traffic statistics.

Usage​

import { Metrics } from "@io-oidis-localhost/Io/Oidis/Localhost/Utils/Metrics.js";

const metrics : Metrics = Metrics.getInstance();

API Reference​

Instrument​

Wraps methods of registered classes with APM spans for automatic performance tracing. By default instruments all classes implementing IHttpRequestResolver and all connectors under Io.Oidis.Localhost.Connectors. Additional namespaces or class references may be passed.

public Instrument($namespaces? : any[]) : void

Start​

Starts an APM transaction for the given owner and type.

public Start($owner : string, $type : string) : void

End​

Ends the current APM transaction with an optional HTTP status result. Pass $force = true to flush the APM buffer immediately.

public End($result? : HttpStatusType, $force : boolean = false) : void

Error​

Captures an error to the APM agent. Also available as a static shortcut.

public Error($message : string | Error) : void
static Error($message : string | Error) : void

AddMeasurement​

Records a single traffic data point (size in bytes) for the 60-second rolling statistics window.

public AddMeasurement($data : IMetricsTrafficData) : void

IMetricsTrafficData fields:

FieldTypeDescription
type"ws" | "http"Traffic channel
inboundboolean?Direction — true for inbound, false for outbound
sizenumberPayload size in bytes
formatDataFormatType?Binary or text format

getStats​

Returns a snapshot of the current rolling traffic statistics for both HTTP and WebSocket channels.

public getStats() : any

The returned object has the shape:

{
"http": { "inbound": { "count": 0, "max": 0, "sum": 0, "avg": 0, "binaryCount": 0 }, "outbound": { ... } },
"ws": { "inbound": { ... }, "outbound": { ... } }
}

Configuration​

Metrics are configured via target.metrics in the project configuration (IMetricsConfiguration):

"metrics": {
"enabled": true,
"location": "localhost",
"port": 8200
}
  • enabled — when false, all APM calls are silently skipped; traffic statistics are still collected.
  • location + port — Elastic APM server endpoint.

The APM agent reports under the app name and version from EnvironmentArgs with framework name "Oidis Framework".


See also: Utilities Overview | LogProcessor | Logging (LogIt & SystemLog)