@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
| Route | Response | Notes |
|---|
| GET / | HTML dashboard | Auto-refreshes every 2s, no CDN deps |
| GET /api/stats | JSON | Server stats + metrics snapshot + plugin names |
| GET /api/clients | JSON array | Connected clients: id, rooms, tags |
| GET /metrics | Prometheus text | Requires ppMetricsPlugin — 404 otherwise |
Options
| Option | Type | Default | Description |
|---|
| port | number | 9090 | HTTP port for the admin server |
| host | string | "localhost" | Bind address |
| auth.username | string | — | Basic Auth username (omit to disable auth) |
| auth.password | string | — | Basic 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
| Member | Description |
|---|
| 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.httpServer | Underlying http.Server instance for advanced use |
See also: Plugins · @painda/core