koishi-plugin-maichuni-scorehelper 0.0.19-test → 0.0.20-test
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.
|
@@ -399,15 +399,26 @@ class MaimaiStatus extends koishi_1.Service {
|
|
|
399
399
|
for (const [name, group] of this.groups) {
|
|
400
400
|
const { ids } = group;
|
|
401
401
|
let upCount = 0;
|
|
402
|
+
let downCount = 0;
|
|
403
|
+
let unknownCount = 0;
|
|
402
404
|
let totalCount = 0;
|
|
403
405
|
for (const id of ids) {
|
|
404
406
|
const history = heartbeatData[id];
|
|
405
407
|
if (Array.isArray(history) && history.length > 0) {
|
|
406
408
|
totalCount++;
|
|
407
409
|
const latest = history[history.length - 1];
|
|
408
|
-
|
|
410
|
+
// 部分部署返回 boolean/字符串,需要兼容;仅将“1/true/"1"”视作在线
|
|
411
|
+
const rawStatus = typeof latest === 'object' && latest !== null ? latest.status : latest;
|
|
412
|
+
const statusNum = Number(rawStatus);
|
|
413
|
+
const isUp = statusNum === 1 || rawStatus === true || rawStatus === '1';
|
|
414
|
+
const isDown = statusNum === 0 || rawStatus === false || rawStatus === '0';
|
|
415
|
+
if (isUp)
|
|
409
416
|
upCount++;
|
|
410
|
-
|
|
417
|
+
else if (isDown)
|
|
418
|
+
downCount++;
|
|
419
|
+
else
|
|
420
|
+
unknownCount++; // status 2 或其它视为未知,不算作全线下线
|
|
421
|
+
this.logDebug(`[status] ${name} id=${id} raw=${String(rawStatus)} isUp=${isUp} isDown=${isDown}`);
|
|
411
422
|
}
|
|
412
423
|
}
|
|
413
424
|
let currentStatus = 'UNKNOWN';
|
|
@@ -415,13 +426,17 @@ class MaimaiStatus extends koishi_1.Service {
|
|
|
415
426
|
if (upCount === totalCount) {
|
|
416
427
|
currentStatus = 'ONLINE';
|
|
417
428
|
}
|
|
418
|
-
else if (upCount === 0) {
|
|
429
|
+
else if (upCount === 0 && downCount === totalCount) {
|
|
419
430
|
currentStatus = 'OFFLINE';
|
|
420
431
|
}
|
|
432
|
+
else if (upCount === 0 && downCount === 0) {
|
|
433
|
+
currentStatus = 'UNKNOWN';
|
|
434
|
+
}
|
|
421
435
|
else {
|
|
422
436
|
currentStatus = 'PARTIAL_OFFLINE';
|
|
423
437
|
}
|
|
424
438
|
}
|
|
439
|
+
this.logDebug(`[status] ${name} summary up=${upCount} down=${downCount} unknown=${unknownCount} total=${totalCount} -> ${currentStatus}`);
|
|
425
440
|
updates.push({ group, currentStatus });
|
|
426
441
|
// 记录主服务状态
|
|
427
442
|
if (group.groupName === this.config.mainServiceName) {
|
package/package.json
CHANGED
|
@@ -457,6 +457,8 @@ export class MaimaiStatus extends Service {
|
|
|
457
457
|
const { ids } = group
|
|
458
458
|
|
|
459
459
|
let upCount = 0
|
|
460
|
+
let downCount = 0
|
|
461
|
+
let unknownCount = 0
|
|
460
462
|
let totalCount = 0
|
|
461
463
|
|
|
462
464
|
for (const id of ids) {
|
|
@@ -464,9 +466,15 @@ export class MaimaiStatus extends Service {
|
|
|
464
466
|
if (Array.isArray(history) && history.length > 0) {
|
|
465
467
|
totalCount++
|
|
466
468
|
const latest = history[history.length - 1]
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
469
|
+
// 部分部署返回 boolean/字符串,需要兼容;仅将“1/true/"1"”视作在线
|
|
470
|
+
const rawStatus = typeof latest === 'object' && latest !== null ? (latest as any).status : latest
|
|
471
|
+
const statusNum = Number(rawStatus)
|
|
472
|
+
const isUp = statusNum === 1 || rawStatus === true || rawStatus === '1'
|
|
473
|
+
const isDown = statusNum === 0 || rawStatus === false || rawStatus === '0'
|
|
474
|
+
if (isUp) upCount++
|
|
475
|
+
else if (isDown) downCount++
|
|
476
|
+
else unknownCount++ // status 2 或其它视为未知,不算作全线下线
|
|
477
|
+
this.logDebug(`[status] ${name} id=${id} raw=${String(rawStatus)} isUp=${isUp} isDown=${isDown}`)
|
|
470
478
|
}
|
|
471
479
|
}
|
|
472
480
|
|
|
@@ -474,13 +482,17 @@ export class MaimaiStatus extends Service {
|
|
|
474
482
|
if (totalCount > 0) {
|
|
475
483
|
if (upCount === totalCount) {
|
|
476
484
|
currentStatus = 'ONLINE'
|
|
477
|
-
} else if (upCount === 0) {
|
|
485
|
+
} else if (upCount === 0 && downCount === totalCount) {
|
|
478
486
|
currentStatus = 'OFFLINE'
|
|
487
|
+
} else if (upCount === 0 && downCount === 0) {
|
|
488
|
+
currentStatus = 'UNKNOWN'
|
|
479
489
|
} else {
|
|
480
490
|
currentStatus = 'PARTIAL_OFFLINE'
|
|
481
491
|
}
|
|
482
492
|
}
|
|
483
493
|
|
|
494
|
+
this.logDebug(`[status] ${name} summary up=${upCount} down=${downCount} unknown=${unknownCount} total=${totalCount} -> ${currentStatus}`)
|
|
495
|
+
|
|
484
496
|
updates.push({ group, currentStatus })
|
|
485
497
|
|
|
486
498
|
// 记录主服务状态
|