/**
 * Resources Collector
 * Phase 3: Read CPU%, load, RAM, disk, uptime, proc count
 */
import * as os from 'os';
/**
 * Collect system resources
 * Must work on Linux + degrade gracefully elsewhere
 */
export async function collectResources() {
    try {
        const data = {
            // CPU - simplified (would need actual monitoring)
            cpuPercent: "UNKNOWN",
            // Load average (1 minute)
            load1m: (() => {
                try {
                    const load = os.loadavg();
                    if (load && load.length > 0) {
                        return load[0];
                    }
                }
                catch {
                    // Not available on Windows
                }
                return "UNKNOWN";
            })(),
            // RAM
            ramUsedMb: (() => {
                try {
                    const total = os.totalmem();
                    const free = os.freemem();
                    const used = total - free;
                    return Math.round(used / 1024 / 1024);
                }
                catch {
                    return "UNKNOWN";
                }
            })(),
            ramTotalMb: (() => {
                try {
                    const total = os.totalmem();
                    return Math.round(total / 1024 / 1024);
                }
                catch {
                    return "UNKNOWN";
                }
            })(),
            // Disk - simplified (would need actual disk monitoring)
            diskUsedGb: "UNKNOWN",
            diskTotalGb: "UNKNOWN",
            // Uptime
            uptimeSec: (() => {
                try {
                    return os.uptime();
                }
                catch {
                    return "UNKNOWN";
                }
            })(),
            // Process count - simplified
            procCount: "UNKNOWN",
        };
        // Phase 9: Resources are usually LIVE if collected successfully
        const now = Date.now();
        const status = 'LIVE';
        return {
            status,
            asOf: now,
            data,
            source: 'collector_resources',
            staleAfterMs: 2000, // Refresh every 2s
        };
    }
    catch (error) {
        return {
            status: 'UNAVAILABLE',
            asOf: Date.now(),
            source: 'collector_resources',
            staleAfterMs: 2000,
            reasonCode: 'COLLECTION_ERROR',
            message: error.message || 'Unknown error',
            action: 'system resources',
        };
    }
}
//# sourceMappingURL=collector_resources.js.map