import { Fragment, useCallback, useState } from 'react' import { Progress } from '@janhq/joi' import { useAtom, useAtomValue } from 'jotai' import { MonitorIcon, XIcon, ChevronDown, ChevronUp, FolderOpenIcon, } from 'lucide-react' import { twMerge } from 'tailwind-merge' import useGetSystemResources from '@/hooks/useGetSystemResources' import { usePath } from '@/hooks/usePath' import { toGigabytes } from '@/utils/converter' import { utilizedMemory } from '@/utils/memory' import TableActiveModel from './TableActiveModel' import { showSystemMonitorPanelAtom } from '@/helpers/atoms/App.atom' import { reduceTransparentAtom } from '@/helpers/atoms/Setting.atom' import { cpuUsageAtom, gpusAtom, ramUtilitizedAtom, totalRamAtom, usedRamAtom, } from '@/helpers/atoms/SystemBar.atom' const SystemMonitor = () => { const totalRam = useAtomValue(totalRamAtom) const usedRam = useAtomValue(usedRamAtom) const cpuUsage = useAtomValue(cpuUsageAtom) const gpus = useAtomValue(gpusAtom) const { onRevealInFinder } = usePath() const [showFullScreen, setShowFullScreen] = useState(false) const ramUtilitized = useAtomValue(ramUtilitizedAtom) const [showSystemMonitorPanel, setShowSystemMonitorPanel] = useAtom( showSystemMonitorPanelAtom ) const reduceTransparent = useAtomValue(reduceTransparentAtom) const { watch, stopWatching } = useGetSystemResources() const toggleShowSystemMonitorPanel = useCallback( (isShow: boolean) => { setShowSystemMonitorPanel(isShow) if (isShow) { watch() } else { stopWatching() } }, [setShowSystemMonitorPanel, stopWatching, watch] ) return (
{ toggleShowSystemMonitorPanel(!showSystemMonitorPanel) setShowFullScreen(false) }} > System Monitor
{showSystemMonitorPanel && (
Running Models
onRevealInFinder('Logs')} > App Log
{showFullScreen ? ( setShowFullScreen(!showFullScreen)} /> ) : ( setShowFullScreen(!showFullScreen)} /> )} { toggleShowSystemMonitorPanel(false) setShowFullScreen(false) }} />
CPU
{cpuUsage}%
Memory
{toGigabytes(usedRam, { hideUnit: true })}GB /{' '} {toGigabytes(totalRam, { hideUnit: true })}GB
{ramUtilitized}%
{gpus.length > 0 && (
{gpus .filter((gpu) => gpu.activated === true) .map((gpu, index) => { const gpuUtilization = utilizedMemory( gpu.free_vram, gpu.total_vram ) return (
{gpu.name}
{gpu.total_vram - gpu.free_vram}/ {gpu.total_vram} MB
{gpuUtilization}%
) })}
)}
)}
) } export default SystemMonitor