npm.io
1.0.1 • Published yesterday

@x12i/api-live-sdk

Licence
exellix-license
Version
1.0.1
Deps
0
Size
102 kB
Vulns
0
Weekly
0

@x12i/api-live-sdk

Embeddable in-memory /_live status dashboard for any Node HTTP service.

  • Process sparklines (CPU, RSS, heap, host memory, external, event-loop busy)
  • UTC hourly push / pull volume bars (up to 48 hours)
  • Traffic rings for inbound and worker (outbound) calls
  • Adapters: Fastify and Node http
  • No database

Install

npm install @x12i/api-live-sdk

Peer (Fastify adapter only): fastify@^5.

Fastify

import Fastify from "fastify";
import { attachFastifyLiveSdk } from "@x12i/api-live-sdk/fastify";

const app = Fastify();
const live = await attachFastifyLiveSdk(app, {
  service: {
    id: "my-api",
    title: "My API",
    port: 8080,
    env: "PORT",
    origin: "http://127.0.0.1:8080/",
    description: "Example service",
  },
});

const fetchLive = live.createInstrumentedFetch({ caller: "worker" });
await fetchLive("https://example.test/x");

await app.listen({ port: 8080, host: "127.0.0.1" });
// Open http://127.0.0.1:8080/_live

Node http

import http from "node:http";
import { createNodeHttpLiveSdk } from "@x12i/api-live-sdk/node-http";

const port = 8080;
const live = createNodeHttpLiveSdk({
  service: { id: "fixture", title: "Fixture", port },
});

http
  .createServer(async (req, res) => {
    if (await live.tryHandle(req, res)) return;
    res.writeHead(200, { "content-type": "application/json" });
    res.end(JSON.stringify({ ok: true }));
  })
  .listen(port);

Manual volume (non-HTTP writers)

live.recordVolume({ direction: "push", bytes: 12_345 });
live.recordVolume({ direction: "pull", bytes: 67_890, requests: 0 });

Default semantics match station Memorix live views: pushed = request / write bodies in, pulled = response / read bodies out.

Endpoints (default basePath: /_live)

Path Purpose
GET /_live HTML dashboard
GET /_live/api/info Service metadata
GET /_live/api/status Liveness + process snapshot + volume
GET /_live/api/health-series?limit= Process samples (default 120)
GET /_live/api/volume-series?limit= UTC hourly buckets (default 48)
GET /_live/api/traffic?lane=inbound|worker Recent traffic entries

Health probes and /_live/* are excluded from the inbound ring.

License

exellix-license

Keywords