@mark1russell7/lag-hud
v0.4.0
Published
An in-memory meter, a fan-out and a display without a framework for the lag monitors of @mark1russell7/lag.
Maintainers
Readme
@mark1russell7/lag-hud
An in-memory meter, a fan-out and a small display for the lag monitors of @mark1russell7/lag. The display needs no framework, so it works in a page of each framework.
npm install @mark1russell7/lag-hud @mark1russell7/lagUse
import { createBrowserDeps, setupAllMonitors } from "@mark1russell7/lag";
import { createHudMeter, mountLagHud } from "@mark1russell7/lag-hud";
const hud = createHudMeter();
const monitors = setupAllMonitors(createBrowserDeps(window, { meter: hud.meter, logger }));
const display = mountLagHud(hud, { corner: "bottom-right" });
// later: display.stop(); monitors.stop();The meter
lag reports through a Meter with the shape of the OpenTelemetry Meter. createHudMeter() gives a meter that keeps the values in memory.
- A histogram keeps its last
windowSizevalues (default 200), and it counts each value. - A counter keeps its total.
snapshot()gives aLagStatfor each metric:count,last,p50,p95,maxandsum.onChange(listener)starts the listener at most one time for eachtickMs(default 1000). Thus a display updates at a calm rate, also when the monitors are busy.
More meters
fanOutMeter(...meters) gives one meter that records into each meter of the list. Use it to send the values to the display and to OpenTelemetry:
const meter = fanOutMeter(hud.meter, otelMeterProvider.getMeter("lag"));fanOutMeter and the meter types have their home in @mark1russell7/lag/meters. This package exports them again. The types come from @opentelemetry/api, so this package has @opentelemetry/api as a peer dependency.
The display
mountLagHud(hud, options) adds a small fixed panel to the page: a title line, then one line for each metric. formatLagStat gives the line of one metric. lagHudText gives the text of the panel, for a display of your own.
| Option | What it does |
| --- | --- |
| corner | The corner of the screen: top-left, top-right, bottom-left or bottom-right (the default) |
| title | The first line (default lag) |
| parent | The parent element (default the body of the document) |
| document | The document (default globalThis.document) |
stop() removes the panel and stops its updates.
License
MIT
