Add cpu info the the job page

This commit is contained in:
Jaret Burkett
2025-10-07 08:30:23 -06:00
parent c9f982af83
commit 1ea50d8590
7 changed files with 228 additions and 33 deletions

View File

@@ -0,0 +1,29 @@
import { NextResponse } from 'next/server';
import si from 'systeminformation';
import { CpuInfo } from '@/types';
export async function GET() {
try {
const cpuInfoRaw = await si.cpu();
const memoryData = await si.mem();
let cpuInfo: CpuInfo = {
name: `${cpuInfoRaw.manufacturer} ${cpuInfoRaw.brand}`,
cores: cpuInfoRaw.cores,
temperature: (await si.cpuTemperature()).main || 0,
totalMemory: memoryData.total / (1024 * 1024),
availableMemory: memoryData.available / (1024 * 1024),
freeMemory: memoryData.free / (1024 * 1024),
currentLoad: (await si.currentLoad()).currentLoad || 0,
};
return NextResponse.json(cpuInfo);
} catch (error) {
console.error('Error fetching CPU stats:', error);
return NextResponse.json(
{
error: `Failed to fetch CPU stats: ${error instanceof Error ? error.message : String(error)}`,
},
{ status: 500 },
);
}
}