guanghulab/skyeye/hibernation/overtime-monitor.js
Guanghu Domestic Migration d1e47f4565
Some checks are pending
自动更新代码和重启 / update-and-restart (push) Waiting to run
CI检查 + 自动部署 / check (push) Waiting to run
CI检查 + 自动部署 / deploy (push) Blocked by required conditions
重启聊天服务 / restart (push) Waiting to run
chore: import sanitized domestic snapshot for REPO-002
Source snapshot: ca48d3ddf926d79aa138306164169baf764bb829
2026-07-17 15:54:41 +08:00

89 lines
2.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env node
/**
* skyeye/hibernation/overtime-monitor.js
* ═══════════════════════════════════════════════
* 🔺 Sovereign: TCS-0002∞ | Root: SYS-GLW-0001
* 📜 Copyright: 国作登字-2026-A-00037559
* ═══════════════════════════════════════════════
*
* ⏰ 延时监控
* 如果实际休眠超出预估 15% 以上,自动追加延时通知。
*
* 用法:
* node overtime-monitor.js --planned=12 --elapsed=15 --mode=daily
*/
'use strict';
const fs = require('fs');
const path = require('path');
const OVERTIME_THRESHOLD = 0.15; // 15%
function parseArgs() {
const args = process.argv.slice(2);
const result = {};
for (const arg of args) {
if (arg.startsWith('--')) {
const [key, value] = arg.slice(2).split('=');
result[key] = value || 'true';
}
}
return result;
}
function checkOvertime(plannedDuration, elapsed) {
const threshold = plannedDuration * (1 + OVERTIME_THRESHOLD);
if (elapsed > threshold) {
return {
overtime: true,
planned: plannedDuration,
elapsed: elapsed,
threshold: Math.round(threshold),
overage_percent: Math.round(((elapsed - plannedDuration) / plannedDuration) * 100),
message: `原预计 ${plannedDuration}min实际已 ${elapsed}min`
};
}
return {
overtime: false,
planned: plannedDuration,
elapsed: elapsed,
threshold: Math.round(threshold),
remaining: Math.max(0, plannedDuration - elapsed)
};
}
function run() {
const args = parseArgs();
const planned = parseInt(args.planned || '12', 10);
const elapsed = parseInt(args.elapsed || '0', 10);
const mode = args.mode || 'daily';
console.log(`[Overtime Monitor] Mode: ${mode}`);
console.log(`[Overtime Monitor] Planned: ${planned}min, Elapsed: ${elapsed}min`);
const result = checkOvertime(planned, elapsed);
if (result.overtime) {
console.log(`⚠️ 休眠延时!${result.message}`);
console.log(` 超出阈值 ${OVERTIME_THRESHOLD * 100}%(预计 ${result.threshold}min`);
// 输出供 readme-status-updater 使用
console.log(`[RESULT] overtime=true`);
console.log(`[RESULT] message=${result.message}`);
} else {
console.log(`✅ 休眠时间正常,剩余 ${result.remaining}min`);
console.log(`[RESULT] overtime=false`);
}
return result;
}
module.exports = { checkOvertime, OVERTIME_THRESHOLD, run };
if (require.main === module) {
run();
}