DocumentationCore Protocol

@painda/admin

Lightweight monitoring dashboard for PaindaProtocol servers. Zero runtime dependencies — built on plain node:http. Serves a self-contained HTML dashboard and a Prometheus-compatible metrics endpoint.

Installation

npm install @painda/admin

Basic Setup

import { PPServer, ppMetricsPlugin } from "@painda/core";
import { PPAdminServer } from "@painda/admin";

const server = new PPServer({ port: 3000 });

// Optional: register metrics plugin for /api/stats and /metrics
server.register(ppMetricsPlugin);

const admin = new PPAdminServer(server, {
  port: 9090,
  host: "localhost",   // default
  auth: {
    username: "admin",
    password: "secret",
  },
});

admin.start();
// Dashboard: http://localhost:9090
// Prometheus: http://localhost:9090/metrics

HTTP Endpoints

RouteResponseNotes
GET /HTML dashboardAuto-refreshes every 2s, no CDN deps
GET /api/statsJSONServer stats + metrics snapshot + plugin names
GET /api/clientsJSON arrayConnected clients: id, rooms, tags
GET /metricsPrometheus textRequires ppMetricsPlugin — 404 otherwise

Options

OptionTypeDefaultDescription
portnumber9090HTTP port for the admin server
hoststring"localhost"Bind address
auth.usernamestringBasic Auth username (omit to disable auth)
auth.passwordstringBasic Auth password

Dashboard Stats Payload (/api/stats)

{
  "clients": 42,          // connected client count
  "rooms": 8,             // active room count
  "presenceTracked": 40,  // clients tracked by presence
  "uptime": 3612,         // server uptime in seconds
  "plugins": ["pp-metrics", "pp-auth"],
  "metrics": {            // null if ppMetricsPlugin not registered
    "messagesReceived": 14500,
    "messagesSent": 28900,
    "bytesReceived": 450000,
    "bytesSent": 890000,
    "connectionsTotal": 150,
    "disconnectionsTotal": 108,
    "roomJoinsTotal": 320,
    "roomLeavesTotal": 310,
    "errorsTotal": 2
  }
}

API

MemberDescription
new PPAdminServer(server, opts)Create admin server — does not start listening yet
admin.start()Start listening; logs dashboard and metrics URLs
admin.stop()Promise<void> — graceful shutdown
admin.httpServerUnderlying http.Server instance for advanced use

See also: Plugins · @painda/core