import { Router } from "express";
import { validateToken } from "../middleware/auth.js";
import { collectSystemMetrics } from "../services/system-metrics.js";
import { createLogger } from "../utils/logger.js";
const log = createLogger("system-metrics-route");
export const systemMetricsRouter = Router();
/**
 * 获取机器关键资源指标。
 * 处理流程：校验 runtime token -> 采集 CPU/内存/存储/网络快照 -> 返回给调度中心代理。
 */
systemMetricsRouter.get("/system-metrics", validateToken, async (_req, res) => {
    try {
        res.json(await collectSystemMetrics());
    }
    catch (error) {
        const err = error instanceof Error ? error : new Error(String(error));
        log.error("Failed to collect system metrics:", err.message);
        res.status(500).json({ error: err.message });
    }
});
