@zucker-framework/dashboard 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +22 -0
- package/THIRD_PARTY_NOTICES +4 -0
- package/dist/index.d.mts +181 -0
- package/dist/index.d.ts +181 -0
- package/dist/index.js +418 -0
- package/dist/index.mjs +379 -0
- package/package.json +39 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/index.ts
|
|
32
|
+
var index_exports = {};
|
|
33
|
+
__export(index_exports, {
|
|
34
|
+
DashboardManager: () => DashboardManager,
|
|
35
|
+
MeasurementParameter: () => MeasurementParameter,
|
|
36
|
+
SimpleMeasurementValue: () => SimpleMeasurementValue,
|
|
37
|
+
StaticMeasurement: () => StaticMeasurement,
|
|
38
|
+
SystemMonitorProvider: () => SystemMonitorProvider
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(index_exports);
|
|
41
|
+
|
|
42
|
+
// src/dashboard.ts
|
|
43
|
+
var import_common = require("@nestjs/common");
|
|
44
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
45
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
46
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
47
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
48
|
+
} else {
|
|
49
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
50
|
+
if (d = decorators[i]) {
|
|
51
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
56
|
+
}
|
|
57
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
58
|
+
var StaticMeasurement = class {
|
|
59
|
+
static {
|
|
60
|
+
__name(this, "StaticMeasurement");
|
|
61
|
+
}
|
|
62
|
+
definition;
|
|
63
|
+
dimensions = /* @__PURE__ */ new Map();
|
|
64
|
+
constructor(definition) {
|
|
65
|
+
this.definition = definition;
|
|
66
|
+
}
|
|
67
|
+
addDimension(dimension) {
|
|
68
|
+
this.dimensions.set(dimension.definition.id, dimension);
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
getDimensions() {
|
|
72
|
+
return Array.from(this.dimensions.values());
|
|
73
|
+
}
|
|
74
|
+
getDimension(id) {
|
|
75
|
+
return this.dimensions.get(id);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
var CompositeDashboardObject = class CompositeDashboardObject2 {
|
|
79
|
+
static {
|
|
80
|
+
__name(this, "CompositeDashboardObject");
|
|
81
|
+
}
|
|
82
|
+
definition;
|
|
83
|
+
providers = [];
|
|
84
|
+
addProvider(provider) {
|
|
85
|
+
if (!this.definition) {
|
|
86
|
+
this.definition = provider.getObjectDefinition();
|
|
87
|
+
}
|
|
88
|
+
this.providers.push(provider);
|
|
89
|
+
}
|
|
90
|
+
getMeasurements() {
|
|
91
|
+
return this.providers.flatMap((p) => p.getMeasurements());
|
|
92
|
+
}
|
|
93
|
+
getMeasurement(id) {
|
|
94
|
+
for (const provider of this.providers) {
|
|
95
|
+
const m = provider.getMeasurement(id);
|
|
96
|
+
if (m) return m;
|
|
97
|
+
}
|
|
98
|
+
return void 0;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
var CompositeDashboard = class CompositeDashboard2 {
|
|
102
|
+
static {
|
|
103
|
+
__name(this, "CompositeDashboard");
|
|
104
|
+
}
|
|
105
|
+
definition;
|
|
106
|
+
objects = /* @__PURE__ */ new Map();
|
|
107
|
+
subDashboards = [];
|
|
108
|
+
constructor(definition) {
|
|
109
|
+
this.definition = definition;
|
|
110
|
+
}
|
|
111
|
+
addProvider(provider) {
|
|
112
|
+
const objId = provider.getObjectDefinition().id;
|
|
113
|
+
let obj = this.objects.get(objId);
|
|
114
|
+
if (!obj) {
|
|
115
|
+
obj = new CompositeDashboardObject();
|
|
116
|
+
this.objects.set(objId, obj);
|
|
117
|
+
}
|
|
118
|
+
obj.addProvider(provider);
|
|
119
|
+
}
|
|
120
|
+
addDashboard(dashboard) {
|
|
121
|
+
this.subDashboards.push(dashboard);
|
|
122
|
+
}
|
|
123
|
+
getObjects() {
|
|
124
|
+
const objs = Array.from(this.objects.values());
|
|
125
|
+
for (const sub of this.subDashboards) {
|
|
126
|
+
objs.push(...sub.getObjects());
|
|
127
|
+
}
|
|
128
|
+
return objs;
|
|
129
|
+
}
|
|
130
|
+
getObject(id) {
|
|
131
|
+
const obj = this.objects.get(id);
|
|
132
|
+
if (obj) return obj;
|
|
133
|
+
for (const sub of this.subDashboards) {
|
|
134
|
+
const found = sub.getObject(id);
|
|
135
|
+
if (found) return found;
|
|
136
|
+
}
|
|
137
|
+
return void 0;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
var DashboardManager = class {
|
|
141
|
+
static {
|
|
142
|
+
__name(this, "DashboardManager");
|
|
143
|
+
}
|
|
144
|
+
dashboards = /* @__PURE__ */ new Map();
|
|
145
|
+
/**
|
|
146
|
+
* Register a MeasurementProvider.
|
|
147
|
+
* Automatically creates/composites the dashboard and object hierarchy.
|
|
148
|
+
*/
|
|
149
|
+
registerProvider(provider) {
|
|
150
|
+
const def = provider.getDashboardDefinition();
|
|
151
|
+
let dashboard = this.dashboards.get(def.id);
|
|
152
|
+
if (!dashboard) {
|
|
153
|
+
dashboard = new CompositeDashboard(def);
|
|
154
|
+
this.dashboards.set(def.id, dashboard);
|
|
155
|
+
}
|
|
156
|
+
dashboard.addProvider(provider);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Register a full Dashboard (will be merged into composite).
|
|
160
|
+
*/
|
|
161
|
+
registerDashboard(dashboard) {
|
|
162
|
+
const def = dashboard.definition;
|
|
163
|
+
let composite = this.dashboards.get(def.id);
|
|
164
|
+
if (!composite) {
|
|
165
|
+
composite = new CompositeDashboard(def);
|
|
166
|
+
this.dashboards.set(def.id, composite);
|
|
167
|
+
}
|
|
168
|
+
composite.addDashboard(dashboard);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Register a simple dashboard definition (backward compat).
|
|
172
|
+
*/
|
|
173
|
+
register(definition) {
|
|
174
|
+
if (!this.dashboards.has(definition.id)) {
|
|
175
|
+
this.dashboards.set(definition.id, new CompositeDashboard(definition));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
unregister(id) {
|
|
179
|
+
this.dashboards.delete(id);
|
|
180
|
+
}
|
|
181
|
+
getDashboard(id) {
|
|
182
|
+
return this.dashboards.get(id);
|
|
183
|
+
}
|
|
184
|
+
getDashboards() {
|
|
185
|
+
return Array.from(this.dashboards.values());
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Get all registered dashboard definitions.
|
|
189
|
+
*/
|
|
190
|
+
getDefinitions() {
|
|
191
|
+
return Array.from(this.dashboards.values()).map((d) => d.definition);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
DashboardManager = _ts_decorate([
|
|
195
|
+
(0, import_common.Injectable)()
|
|
196
|
+
], DashboardManager);
|
|
197
|
+
|
|
198
|
+
// src/measurement.ts
|
|
199
|
+
var MeasurementParameter = class _MeasurementParameter {
|
|
200
|
+
static {
|
|
201
|
+
__name(this, "MeasurementParameter");
|
|
202
|
+
}
|
|
203
|
+
params;
|
|
204
|
+
constructor(params = {}) {
|
|
205
|
+
this.params = {
|
|
206
|
+
...params
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
static of(params) {
|
|
210
|
+
return new _MeasurementParameter(params);
|
|
211
|
+
}
|
|
212
|
+
get(name) {
|
|
213
|
+
return this.params[name];
|
|
214
|
+
}
|
|
215
|
+
getString(name, defaultValue = "") {
|
|
216
|
+
const val = this.params[name];
|
|
217
|
+
return val !== void 0 && val !== null ? String(val) : defaultValue;
|
|
218
|
+
}
|
|
219
|
+
getNumber(name, defaultValue = 0) {
|
|
220
|
+
const val = this.params[name];
|
|
221
|
+
if (typeof val === "number") return val;
|
|
222
|
+
if (typeof val === "string") {
|
|
223
|
+
const n = Number(val);
|
|
224
|
+
return isNaN(n) ? defaultValue : n;
|
|
225
|
+
}
|
|
226
|
+
return defaultValue;
|
|
227
|
+
}
|
|
228
|
+
values() {
|
|
229
|
+
return {
|
|
230
|
+
...this.params
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
var SimpleMeasurementValue = class _SimpleMeasurementValue {
|
|
235
|
+
static {
|
|
236
|
+
__name(this, "SimpleMeasurementValue");
|
|
237
|
+
}
|
|
238
|
+
value;
|
|
239
|
+
timeString;
|
|
240
|
+
timestamp;
|
|
241
|
+
tags;
|
|
242
|
+
constructor(value, timestamp, tags) {
|
|
243
|
+
this.value = value;
|
|
244
|
+
this.timestamp = timestamp;
|
|
245
|
+
this.timeString = _SimpleMeasurementValue.formatTime(timestamp);
|
|
246
|
+
this.tags = tags;
|
|
247
|
+
}
|
|
248
|
+
static of(value, timestamp) {
|
|
249
|
+
const ts = timestamp instanceof Date ? timestamp : typeof timestamp === "number" ? new Date(timestamp) : /* @__PURE__ */ new Date();
|
|
250
|
+
return new _SimpleMeasurementValue(value, ts);
|
|
251
|
+
}
|
|
252
|
+
static formatTime(date) {
|
|
253
|
+
const pad = /* @__PURE__ */ __name((n) => String(n).padStart(2, "0"), "pad");
|
|
254
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Compare by timestamp ascending.
|
|
258
|
+
*/
|
|
259
|
+
static compareAsc(a, b) {
|
|
260
|
+
const ta = a.timestamp?.getTime() ?? 0;
|
|
261
|
+
const tb = b.timestamp?.getTime() ?? 0;
|
|
262
|
+
return ta - tb;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Compare by timestamp descending (newest first, default sort).
|
|
266
|
+
*/
|
|
267
|
+
static compareDesc(a, b) {
|
|
268
|
+
const ta = a.timestamp?.getTime() ?? 0;
|
|
269
|
+
const tb = b.timestamp?.getTime() ?? 0;
|
|
270
|
+
return tb - ta;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
// src/system-monitor.ts
|
|
275
|
+
var os = __toESM(require("os"));
|
|
276
|
+
var SystemMonitorProvider = class {
|
|
277
|
+
static {
|
|
278
|
+
__name(this, "SystemMonitorProvider");
|
|
279
|
+
}
|
|
280
|
+
measurements;
|
|
281
|
+
constructor() {
|
|
282
|
+
this.measurements = /* @__PURE__ */ new Map();
|
|
283
|
+
this.measurements.set("cpu", this.createCpuMeasurement());
|
|
284
|
+
this.measurements.set("memory", this.createMemoryMeasurement());
|
|
285
|
+
this.measurements.set("process", this.createProcessMeasurement());
|
|
286
|
+
}
|
|
287
|
+
getDashboardDefinition() {
|
|
288
|
+
return {
|
|
289
|
+
id: "system",
|
|
290
|
+
name: "System Monitor"
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
getObjectDefinition() {
|
|
294
|
+
return {
|
|
295
|
+
id: "stats",
|
|
296
|
+
name: "System Statistics"
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
getMeasurements() {
|
|
300
|
+
return Array.from(this.measurements.values());
|
|
301
|
+
}
|
|
302
|
+
getMeasurement(id) {
|
|
303
|
+
return this.measurements.get(id);
|
|
304
|
+
}
|
|
305
|
+
createCpuMeasurement() {
|
|
306
|
+
return new StaticMeasurement({
|
|
307
|
+
id: "cpu",
|
|
308
|
+
name: "CPU",
|
|
309
|
+
dimensions: [
|
|
310
|
+
{
|
|
311
|
+
id: "usage",
|
|
312
|
+
name: "CPU Usage"
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
id: "count",
|
|
316
|
+
name: "CPU Count"
|
|
317
|
+
}
|
|
318
|
+
]
|
|
319
|
+
}).addDimension(this.createDimension("usage", "CPU Usage", async () => {
|
|
320
|
+
const cpus2 = os.cpus();
|
|
321
|
+
let totalIdle = 0;
|
|
322
|
+
let totalTick = 0;
|
|
323
|
+
for (const cpu of cpus2) {
|
|
324
|
+
totalIdle += cpu.times.idle;
|
|
325
|
+
totalTick += cpu.times.user + cpu.times.nice + cpu.times.sys + cpu.times.irq + cpu.times.idle;
|
|
326
|
+
}
|
|
327
|
+
return SimpleMeasurementValue.of(totalTick > 0 ? 1 - totalIdle / totalTick : 0);
|
|
328
|
+
})).addDimension(this.createDimension("count", "CPU Count", async () => {
|
|
329
|
+
return SimpleMeasurementValue.of(os.cpus().length);
|
|
330
|
+
}));
|
|
331
|
+
}
|
|
332
|
+
createMemoryMeasurement() {
|
|
333
|
+
return new StaticMeasurement({
|
|
334
|
+
id: "memory",
|
|
335
|
+
name: "Memory",
|
|
336
|
+
dimensions: [
|
|
337
|
+
{
|
|
338
|
+
id: "total",
|
|
339
|
+
name: "Total Memory"
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
id: "used",
|
|
343
|
+
name: "Used Memory"
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
id: "free",
|
|
347
|
+
name: "Free Memory"
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
id: "usageRate",
|
|
351
|
+
name: "Memory Usage Rate"
|
|
352
|
+
}
|
|
353
|
+
]
|
|
354
|
+
}).addDimension(this.createDimension("total", "Total Memory", async () => {
|
|
355
|
+
return SimpleMeasurementValue.of(os.totalmem());
|
|
356
|
+
})).addDimension(this.createDimension("used", "Used Memory", async () => {
|
|
357
|
+
return SimpleMeasurementValue.of(os.totalmem() - os.freemem());
|
|
358
|
+
})).addDimension(this.createDimension("free", "Free Memory", async () => {
|
|
359
|
+
return SimpleMeasurementValue.of(os.freemem());
|
|
360
|
+
})).addDimension(this.createDimension("usageRate", "Memory Usage Rate", async () => {
|
|
361
|
+
const total = os.totalmem();
|
|
362
|
+
const free = os.freemem();
|
|
363
|
+
return SimpleMeasurementValue.of(total > 0 ? (total - free) / total : 0);
|
|
364
|
+
}));
|
|
365
|
+
}
|
|
366
|
+
createProcessMeasurement() {
|
|
367
|
+
return new StaticMeasurement({
|
|
368
|
+
id: "process",
|
|
369
|
+
name: "Process",
|
|
370
|
+
dimensions: [
|
|
371
|
+
{
|
|
372
|
+
id: "uptime",
|
|
373
|
+
name: "Uptime"
|
|
374
|
+
},
|
|
375
|
+
{
|
|
376
|
+
id: "rss",
|
|
377
|
+
name: "RSS Memory"
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
id: "heapUsed",
|
|
381
|
+
name: "Heap Used"
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
id: "heapTotal",
|
|
385
|
+
name: "Heap Total"
|
|
386
|
+
}
|
|
387
|
+
]
|
|
388
|
+
}).addDimension(this.createDimension("uptime", "Uptime", async () => {
|
|
389
|
+
return SimpleMeasurementValue.of(process.uptime());
|
|
390
|
+
})).addDimension(this.createDimension("rss", "RSS Memory", async () => {
|
|
391
|
+
return SimpleMeasurementValue.of(process.memoryUsage().rss);
|
|
392
|
+
})).addDimension(this.createDimension("heapUsed", "Heap Used", async () => {
|
|
393
|
+
return SimpleMeasurementValue.of(process.memoryUsage().heapUsed);
|
|
394
|
+
})).addDimension(this.createDimension("heapTotal", "Heap Total", async () => {
|
|
395
|
+
return SimpleMeasurementValue.of(process.memoryUsage().heapTotal);
|
|
396
|
+
}));
|
|
397
|
+
}
|
|
398
|
+
createDimension(id, name, getter) {
|
|
399
|
+
return {
|
|
400
|
+
definition: {
|
|
401
|
+
id,
|
|
402
|
+
name
|
|
403
|
+
},
|
|
404
|
+
async getValue(params) {
|
|
405
|
+
const p = params instanceof MeasurementParameter ? params : new MeasurementParameter(params);
|
|
406
|
+
return getter(p);
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
412
|
+
0 && (module.exports = {
|
|
413
|
+
DashboardManager,
|
|
414
|
+
MeasurementParameter,
|
|
415
|
+
SimpleMeasurementValue,
|
|
416
|
+
StaticMeasurement,
|
|
417
|
+
SystemMonitorProvider
|
|
418
|
+
});
|