Repository navigation
Expand file tree
/
Copy pathstats.js
More file actions
706 lines (655 loc) · 25.2 KB
/
Copy pathstats.js
File metadata and controls
706 lines (655 loc) · 25.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
const { monitorEventLoopDelay } = require('perf_hooks');
const {Utilities} = require("./library/utilities");
const escape = require('escape-html');
const StatsDatabase = require('./stats-db');
const { validRow: validClusterEvent } = require('./library/cluster-events');
const { readProcessMemory } = require('./library/cgroup-memory');
// Requests that aren't counted by a module (the root page, the dashboard) are
// attributed here, and requests that have no endpoint dimension (everything
// outside the tx module) carry NO_ENDPOINT.
const SERVER_MODULE = '(server)';
const NO_ENDPOINT = '';
/**
* A per-module view of the server statistics.
*
* Modules are handed one of these instead of the ServerStats itself, so that
* everything they count is attributed to them without each of the ~76 call
* sites having to name its own module. The API is deliberately the same shape
* as ServerStats, so a module can't tell the difference - except that
* countRequest takes an optional endpoint, which is how the tx module
* distinguishes /tx/r4 from /tx/r5.
*/
class ModuleStats {
constructor(parent, module) {
this.parent = parent;
this.module = module;
}
countRequest(name, tat, endpoint = NO_ENDPOINT) {
this.parent.countRequest(name, tat, this.module, endpoint);
}
countExternalRequest(name, tat, endpoint = NO_ENDPOINT) {
this.parent.countExternalRequest(name, tat, this.module, endpoint);
}
addTask(name, frequency) { this.parent.addTask(name, frequency); }
task(name, state) { this.parent.task(name, state); }
taskDone(name, state) { this.parent.taskDone(name, state); }
taskError(name, state) { this.parent.taskError(name, state); }
// Pass-throughs for the handful of properties modules read off the stats
// object. These have to be getters, not copies, or a module would capture
// the value at construction time and never see it change.
get cachingModules() { return this.parent.cachingModules; }
get requestCount() { return this.parent.requestCount; }
get staticRequestCount() { return this.parent.staticRequestCount; }
get history() { return this.parent.history; }
get startTime() { return this.parent.startTime; }
/**
* What this module served in (since, now]: {total, operations: {name: count},
* endpoints: {endpoint: {name: count}}} - see ServerStats.countsSince(). This
* is what a module's dailyReport() builds its numbers from.
*/
countsSince(since, now = Date.now()) {
return this.parent.countsSince(since, now, this.module);
}
}
class ServerStats {
started = false;
requestCount = 0;
staticRequestCount = 0;
// on the master under the launcher: the workers' requests added by mergeCounts
mergedRequestCount = 0;
requestTime = 0;
// requests that had to ask another server (see countExternalRequest): in requestCount, but
// not in requestTime, and sampled separately
externalCount = 0;
externalTime = 0;
externalCountSnapshot = 0;
// Collect metrics every 10 minutes (stats.sampleSeconds, else stats.intervalMinutes)
intervalMs = 10 * 60 * 1000;
// and write the counters to the database every 10 minutes (stats.intervalMinutes)
flushMs = 10 * 60 * 1000;
history = [];
requestCountSnapshot = 0;
refusedCount = 0;
refusedCountSnapshot = 0;
startMem = 0;
startTime = Date.now();
timer;
cachingModules = [];
taskMap = new Map();
// key (module/endpoint/operation) -> counter. See countRequest().
counters = new Map();
db = null;
// this run's row in server_runs, and what the earlier runs add up to - see overallUptime()
runId = null;
earlierRuns = {firstStart: null, runningMs: 0};
// how often this run says "still alive"; a crash loses at most this much
// from the overall uptime figure
heartbeatMs = 60 * 1000;
heartbeat = null;
constructor(config, log) {
this.config = config || {};
this.log = log || console;
if (this.config.intervalMinutes) {
this.intervalMs = this.config.intervalMinutes * 60 * 1000;
this.flushMs = this.intervalMs;
}
// the graphs' sample interval, when it isn't the counters' (with a role, a minute at most:
// library/role.js)
if (this.config.sampleSeconds > 0) {
this.intervalMs = this.config.sampleSeconds * 1000;
}
this.openDatabase();
this.timer = setInterval(() => {
this.recordMetrics();
}, this.intervalMs);
}
/**
* Open the persistent counter store and pick up where the last run of the
* server left off. Statistics must never be the reason the server won't
* start, so a failure here is logged and then ignored: the counters carry
* on in memory, they just don't survive the next restart.
*/
openDatabase() {
if (this.config.enabled === false) {
return;
}
try {
this.db = new StatsDatabase(this.config, this.log).open();
for (const row of this.db.loadTotals()) {
const counter = this.counterFor(row.module, row.endpoint, row.operation);
counter.countTotal = row.countTotal;
counter.timeTotal = row.timeTotal;
}
} catch (e) {
this.log.error(`Unable to open the statistics database: ${e.message}. Statistics will not be persisted`);
this.db = null;
}
}
/**
* A view of the statistics that attributes everything counted through it to
* the named module (see ModuleStats).
*/
forModule(module) {
return new ModuleStats(this, module);
}
recordMetrics() {
if (this.started) {
const now = Date.now();
const currentMem = process.memoryUsage().heapUsed;
const combinedCount = this.requestCount + this.staticRequestCount;
const requestsDelta = combinedCount - this.requestCountSnapshot;
// the external requests are timed separately: they are orders of magnitude slower
const externalDelta = this.externalCount - this.externalCountSnapshot;
const ownDelta = requestsDelta - externalDelta;
const requestsTat = ownDelta > 0 ? this.requestTime / ownDelta : 0;
// Under load, the timer can run late. Use the actual time since the last sample, so
// an event-loop stall does not inflate the displayed request rate.
const intervalMinutes = (now - (this.lastTime ?? this.startTime)) / 60000;
const requestsPerMin = intervalMinutes > 0 ? requestsDelta / intervalMinutes : 0;
// where this sample's interval began, so the cluster graphs can place a late sample
const intervalStart = this.lastTime ?? this.startTime;
const refused = this.refusedCount - this.refusedCountSnapshot;
const loopDelay = this.eventLoopMonitor.mean / 1e6;
// Worst single stall in the window - the mean dilutes a multi-second
// event-loop block into noise; the max is what shows request-freezing
// stalls (see the 2026-07-30 tx.fhir.org incident).
const loopMax = this.eventLoopMonitor.max / 1e6;
// The client (resource) cache, as concepts held - a sense of how much it's carrying.
// (The expansion cache isn't tracked over time: it fills to its limit over a few
// days and then sits there, so a history of it says nothing. The home page still
// shows its current size.)
const clientConcepts = this._sumCachingModules('clientConceptCount');
const point = {time: now, mem: currentMem - this.startMem, rpm: requestsPerMin, tat: requestsTat, block: loopDelay, blockMax: loopMax, clientConcepts: clientConcepts};
// where the interval began, and this process's private memory (RssAnon: RSS less mapped
// files; null where /proc can't be read), for the graphs (library/cluster-metrics.js)
point.intervalStart = intervalStart;
// the external requests in the interval, and their mean turnaround (null: none)
point.ext = externalDelta;
point.extTat = externalDelta > 0 ? this.externalTime / externalDelta : null;
const own = readProcessMemory('self');
point.anon = own ? own.anon : null;
if (this.onMetric) {
// under the launcher: the memory guard's refusals, which only a role counts
point.refused = refused;
}
this.history.push(point);
if (this.onMetric) {
this.onMetric(point);
}
this.eventLoopMonitor.reset();
this.requestCountSnapshot = combinedCount;
this.refusedCountSnapshot = this.refusedCount;
this.requestTime = 0;
this.externalCountSnapshot = this.externalCount;
this.externalTime = 0;
this.lastTime = now;
// Prune old data (keep 24 hours). Only the in-memory history is pruned -
// the per-endpoint counters are persisted and kept indefinitely.
const cutoff = now - (24 * 60 * 60 * 1000); // 24 hours ago
this.history = this.history.filter(m => m.time > cutoff);
// the counters every flushMs: at each sample when the two intervals are the same, as
// before, else at the first sample after (half a sample's grace for a timer that fires early)
if (this.lastFlush === undefined || now - this.lastFlush >= this.flushMs - this.intervalMs / 2) {
this.flushCounters(now, this.flushMs);
}
}
}
markStarted(version = null) {
this.started = true;
this.version = version;
this.startMem = process.memoryUsage().heapUsed;
this.startTime = Date.now();
this.lastTime = this.startTime;
this.eventLoopMonitor = monitorEventLoopDelay({ resolution: 20 });
this.eventLoopMonitor.enable();
this.startRun();
this.recordMetrics();
}
/**
* Record this run in the database and start the heartbeat that keeps its
* last_seen current. As with everything else here, a failure is logged and
* the overall uptime just isn't available for this run.
*/
startRun() {
if (!this.db) {
return;
}
try {
this.runId = this.db.startRun(this.startTime, this.version);
this.earlierRuns = this.db.loadRunHistory(this.runId);
} catch (e) {
this.log.error(`Unable to record the server run: ${e.message}. Overall uptime will not be available`);
this.runId = null;
return;
}
this.heartbeat = setInterval(() => this.touchRun(), this.heartbeatMs);
if (typeof this.heartbeat.unref === 'function') {
this.heartbeat.unref();
}
}
/**
* The server's runs since `since`, oldest first, each {started, lastSeen,
* version, current}, preceded by the run before that (if any) - see
* StatsDatabase.loadRuns(). The current run is reported as seen now, not as
* of its last heartbeat. null if the history isn't being kept.
*/
runHistory(since, now = Date.now()) {
if (this.runId == null) {
return null;
}
let runs;
try {
runs = this.db.loadRuns(since);
} catch (e) {
this.log.error(`Unable to read the server run history: ${e.message}`);
return null;
}
return runs.map(r => r.id === this.runId
? {started: r.started, lastSeen: now, version: r.version, current: true}
: {started: r.started, lastSeen: r.lastSeen, version: r.version, current: false});
}
touchRun() {
if (this.db && this.runId != null) {
try {
this.db.touchRun(this.runId, Date.now());
} catch (e) {
this.log.error(`Unable to record the server heartbeat: ${e.message}`);
}
}
}
/**
* The proportion of time the server has been up, over every run recorded
* in the statistics database: time it was known to be running (each run,
* from its start to the last heartbeat it wrote, plus this run up to now)
* as a percentage of the time since the first recorded run started.
*
* Returns {percent, since} or null if the history isn't being kept.
*/
overallUptime(now = Date.now()) {
if (this.runId == null) {
return null;
}
const since = this.earlierRuns.firstStart == null ? this.startTime : Math.min(this.earlierRuns.firstStart, this.startTime);
const elapsed = now - since;
if (elapsed <= 0) {
return {percent: 100, since: since};
}
const running = this.earlierRuns.runningMs + (now - this.startTime);
return {percent: Math.min(100, (running * 100) / elapsed), since: since};
}
/**
* The counter for one (module, endpoint, operation), created on first use.
*
* countDelta/timeDelta accumulate within the current interval and are reset
* each time they're written out; countTotal/timeTotal are cumulative for the
* life of the database, not the life of the process.
*/
counterFor(module, endpoint, operation) {
const key = `${module}\u001f${endpoint}\u001f${operation}`;
let counter = this.counters.get(key);
if (!counter) {
counter = {
module: module, endpoint: endpoint, operation: operation,
countDelta: 0, timeDelta: 0, countTotal: 0, timeTotal: 0
};
this.counters.set(key, counter);
}
return counter;
}
/**
* Count one request. Modules go through their own ModuleStats, which fills
* in module (and, for tx, the endpoint) for them.
*
* @param {string} name - the operation, e.g. '$expand' or 'login'
* @param {number} tat - turnaround time in ms
* @param {string} module - the module that served it
* @param {string} endpoint - the endpoint within the module, where the
* module has more than one (the tx module does; nothing else does yet)
*/
countRequest(name, tat, module = SERVER_MODULE, endpoint = NO_ENDPOINT) {
this.requestCount++;
this.requestTime = this.requestTime + tat;
const counter = this.counterFor(module || SERVER_MODULE, endpoint || NO_ENDPOINT, name || '(unnamed)');
counter.countDelta++;
counter.countTotal++;
counter.timeDelta = counter.timeDelta + tat;
counter.timeTotal = counter.timeTotal + tat;
}
/**
* Count one request whose answer had to ask another server (the tx module's ecosystem
* resolution: tx/ecosystem-resolver.js). These take seconds, not milliseconds, so they are
* kept out of the turnaround time graph and sampled separately (point.ext, point.extTat),
* and counted under their own operation, '<name> (external)'
*/
countExternalRequest(name, tat, module = SERVER_MODULE, endpoint = NO_ENDPOINT) {
this.requestCount++;
this.externalCount++;
this.externalTime = this.externalTime + tat;
const counter = this.counterFor(module || SERVER_MODULE, endpoint || NO_ENDPOINT, (name || '(unnamed)') + ' (external)');
counter.countDelta++;
counter.countTotal++;
counter.timeDelta = counter.timeDelta + tat;
counter.timeTotal = counter.timeTotal + tat;
}
/**
* Count something that happened to the server that isn't a request (an event-loop block:
* library/block-monitor.js), under the (server) module, with how long it took. Persisted and
* merged like the request counts, but kept out of the request count and turnaround time.
*/
countEvent(name, ms = 0) {
const counter = this.counterFor(SERVER_MODULE, NO_ENDPOINT, name || '(unnamed)');
counter.countDelta++;
counter.countTotal++;
counter.timeDelta = counter.timeDelta + ms;
counter.timeTotal = counter.timeTotal + ms;
}
// The memory guard runs before routing and body parsing. Keep its refusals
// separate from completed module work and its turnaround-time denominator.
countRefusedRequest() {
this.refusedCount++;
}
/**
* For a tx-worker under the launcher (library/cluster-counts.js): the requests counted
* since the last call, [{module, endpoint, operation, count, time}], and start again
* from zero. A worker has no statistics database; the master merges these into its
* own counters (mergeCounts), so the master's database and daily report count every
* process, each request once.
*/
takeCounts() {
const rows = [];
for (const counter of this.counters.values()) {
if (counter.countDelta > 0) {
rows.push({module: counter.module, endpoint: counter.endpoint, operation: counter.operation,
count: counter.countDelta, time: counter.timeDelta});
counter.countDelta = 0;
counter.timeDelta = 0;
}
}
return rows;
}
/** Put back what takeCounts gave, when it couldn't be sent: it goes with the next lot. */
restoreCounts(rows) {
for (const row of rows) {
const counter = this.counterFor(row.module, row.endpoint, row.operation);
counter.countDelta = counter.countDelta + row.count;
counter.timeDelta = counter.timeDelta + row.time;
}
}
/**
* On the master: add another process's requests (from its takeCounts) to the counters,
* as if this process had counted them. They are written out with the next interval and
* are in countsSince() at once. Rows that aren't well formed are ignored.
* @returns {number} the requests added
*/
mergeCounts(rows) {
let added = 0;
for (const row of Array.isArray(rows) ? rows : []) {
if (!row || typeof row.module !== 'string' || typeof row.endpoint !== 'string' ||
typeof row.operation !== 'string' || !Number.isInteger(row.count) || row.count <= 0 ||
!Number.isFinite(row.time) || row.time < 0) {
continue;
}
const counter = this.counterFor(row.module, row.endpoint, row.operation);
counter.countDelta = counter.countDelta + row.count;
counter.countTotal = counter.countTotal + row.count;
counter.timeDelta = counter.timeDelta + row.time;
counter.timeTotal = counter.timeTotal + row.time;
added = added + row.count;
}
this.mergedRequestCount = this.mergedRequestCount + added;
return added;
}
/**
* On the master under the launcher: what the launcher saw (library/cluster-events.js),
* written straight to the database - there are few, and the daily report reads them from
* there. Rows that aren't well formed are ignored; without a database, all of them are.
* @returns {number} the rows written
*/
recordClusterEvents(rows) {
if (!this.db) {
return 0;
}
const valid = (Array.isArray(rows) ? rows : []).map(validClusterEvent).filter(Boolean);
try {
this.db.writeClusterEvents(valid);
return valid.length;
} catch (e) {
this.log.error(`Unable to record the launcher's events: ${e.message}`);
return 0;
}
}
/**
* What the launcher saw in (since, now], oldest first, or null without a database.
*/
clusterEventsSince(since, now = Date.now()) {
if (!this.db) {
return null;
}
try {
return this.db.clusterEventsSince(since, now);
} catch (e) {
this.log.error(`Unable to read the launcher's events: ${e.message}`);
return null;
}
}
/**
* Write out the counters that saw traffic this interval, and start the next
* one. The deltas are only cleared if the write succeeded, so a transient
* database problem delays the numbers rather than losing them (the interval
* they're eventually written against is longer, which is what interval_ms on
* the row is for).
*/
flushCounters(now, intervalMs) {
if (!this.db) {
return 0;
}
const rows = [];
for (const counter of this.counters.values()) {
if (counter.countDelta > 0) {
rows.push({...counter});
}
}
if (rows.length === 0) {
this.lastFlush = now;
return 0;
}
try {
this.db.write(now, intervalMs, rows);
} catch (e) {
this.log.error(`Unable to write statistics: ${e.message}`);
return 0;
}
for (const counter of this.counters.values()) {
counter.countDelta = 0;
counter.timeDelta = 0;
}
this.lastFlush = now;
return rows.length;
}
/**
* Write out whatever has been counted since the last flush, so that a
* countsSince() up to `now` sees everything. Used by the daily report.
*/
flushNow(now = Date.now()) {
this.flushCounters(now, now - (this.lastFlush || this.lastTime || this.startTime));
}
/**
* The requests a module served in (since, now], from the persisted rows plus
* anything counted since the last flush. Without the database only the
* unflushed counts are known, so persisted is false to say the numbers are
* partial.
*/
countsSince(since, now, module) {
const result = {total: 0, operations: {}, endpoints: {}, persisted: Boolean(this.db)};
const add = (endpoint, operation, count) => {
if (!count) {
return;
}
result.total += count;
result.operations[operation] = (result.operations[operation] || 0) + count;
const ep = result.endpoints[endpoint] || (result.endpoints[endpoint] = {});
ep[operation] = (ep[operation] || 0) + count;
};
if (this.db) {
try {
for (const row of this.db.countsSince(since, now, module)) {
add(row.endpoint, row.operation, row.count);
}
} catch (e) {
this.log.error(`Unable to read request counts: ${e.message}`);
result.persisted = false;
}
}
for (const counter of this.counters.values()) {
if (counter.module === module) {
add(counter.endpoint, counter.operation, counter.countDelta);
}
}
return result;
}
addTask(name, frequency) {
let info = {};
this.taskMap.set(name, info);
info.frequency = frequency;
info.state = "Started";
info.status = "started"
}
task(name, state) {
let info = this.taskMap.get(name);
if (info) {
info.date = Date.now();
info.state = state;
info.status = 'working';
}
}
taskDone(name, state) {
let info = this.taskMap.get(name);
if (info) {
info.date = Date.now();
info.state = state;
info.status = 'resting';
}
}
taskError(name, state) {
let info = this.taskMap.get(name);
if (info) {
info.date = Date.now();
info.state = state;
info.status = 'error';
}
}
/**
* The background tasks for the status page: those at work, in full
* ([{name, state, frequency, date, ago}]); the names of those whose last run failed (the status
* line lists them, with their state); and the names of the rest (resting, or not run yet)
*/
taskSummary(now = Date.now()) {
const working = [];
const failed = [];
const idle = [];
for (const [name, info] of this.taskMap) {
if (info.status === 'working') {
working.push({name: name, state: info.state, frequency: info.frequency, date: info.date,
ago: info.date ? Utilities.formatDuration(info.date, now) : ''});
} else if (info.status === 'error') {
failed.push(name);
} else {
idle.push(name);
}
}
return { working, failed, idle };
}
/**
* The background tasks whose last run failed: [{name, state, frequency, date}]
*/
failedTasks() {
const failed = [];
for (const [name, info] of this.taskMap) {
if (info.status === 'error') {
failed.push({name: name, state: info.state, frequency: info.frequency, date: info.date});
}
}
return failed;
}
taskDetails() {
if (this.taskMap.size == 0) {
return "";
}
let html = '<table class="grid" >';
html += "<tr><th>Background Task</th><th>Status</th><th>Frequency</th><th>Last Seen</th></tr>";
for (let m of this.taskMap.keys()) {
let mm = this.taskMap.get(m);
let color = this.getTaskColor(mm.status);
html += `<tr style="background-color: ${color}"><td>`;
html += escape(m);
html += "</td><td>";
html += escape(mm.state);
html += "</td><td>";
html += mm.frequency;
html += "</td><td>";
html += Utilities.formatDuration(mm.date, Date.now());
html += "</td></tr>";
}
html += "</table>";
return html;
}
finishStats() {
clearInterval(this.timer);
if (this.heartbeat) {
clearInterval(this.heartbeat);
this.heartbeat = null;
}
this.touchRun();
// Synchronous, so the last partial interval is on disk before server.js
// calls process.exit().
this.flushCounters(Date.now(), Date.now() - (this.lastFlush || this.lastTime || this.startTime));
if (this.db) {
try {
this.db.close();
} catch (e) {
this.log.error(`Unable to close the statistics database: ${e.message}`);
}
this.db = null;
}
}
// Live cache aggregates across all registered caching modules (defensive: a
// module that doesn't expose a given metric contributes 0).
_sumCachingModules(method) {
let total = 0;
for (let m of this.cachingModules) {
if (typeof m[method] === 'function') {
total = total + m[method]();
}
}
return total;
}
expansionItems() { return this._sumCachingModules('expansionItemCount'); }
clientCaches() { return this._sumCachingModules('clientCacheCount'); }
clientConcepts() { return this._sumCachingModules('clientConceptCount'); }
maxClientCaches() { return this._sumCachingModules('maxClientCacheCount'); }
maxClientConcepts() { return this._sumCachingModules('maxClientConceptCount'); }
// $closure usage, from whichever module keeps closure tables; null if none does
closureStats() {
for (let m of this.cachingModules) {
if (typeof m.closureStats === 'function') {
const s = m.closureStats();
if (s) {
return s;
}
}
}
return null;
}
getTaskColor(status) {
switch (status) {
case "started": return "LightGrey";
case "working": return "LightGreen";
case "resting": return "White";
case "error": return "LightRed";
default: return "DarkBlue"; // should not happen
}
}
}
module.exports = ServerStats;
module.exports.ModuleStats = ModuleStats;
module.exports.SERVER_MODULE = SERVER_MODULE;