import { Fragment, useEffect, useState } from 'react' import { Progress } from '@janhq/joi' import { useClickOutside } from '@janhq/joi' import { useAtom, useAtomValue } from 'jotai' import { MonitorIcon, XIcon, ChevronDown, ChevronUp } from 'lucide-react' import { twMerge } from 'tailwind-merge' import useGetSystemResources from '@/hooks/useGetSystemResources' import { toGibibytes } from '@/utils/converter' 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 [showFullScreen, setShowFullScreen] = useState(false) const ramUtilitized = useAtomValue(ramUtilitizedAtom) const [showSystemMonitorPanel, setShowSystemMonitorPanel] = useAtom( showSystemMonitorPanelAtom ) const [control, setControl] = useState(null) const [elementExpand, setElementExpand] = useState( null ) const reduceTransparent = useAtomValue(reduceTransparentAtom) const { watch, stopWatching } = useGetSystemResources() useClickOutside( () => { setShowSystemMonitorPanel(false) setShowFullScreen(false) }, null, [control, elementExpand] ) useEffect(() => { // Watch for resource update watch() return () => { stopWatching() } // eslint-disable-next-line react-hooks/exhaustive-deps }, []) return (
{ setShowSystemMonitorPanel(!showSystemMonitorPanel) setShowFullScreen(false) }} > System Monitor
{showSystemMonitorPanel && (
Running Models
{showFullScreen ? ( setShowFullScreen(!showFullScreen)} /> ) : ( setShowFullScreen(!showFullScreen)} /> )} { setShowSystemMonitorPanel(false) setShowFullScreen(false) }} />
CPU
{cpuUsage}%
Memory
{toGibibytes(usedRam, { hideUnit: true })}/ {toGibibytes(totalRam, { hideUnit: true })} GB
{ramUtilitized}%
{gpus.length > 0 && (
{gpus.map((gpu, index) => (
{gpu.name}
{gpu.memoryTotal - gpu.memoryFree}/ {gpu.memoryTotal} MB
{gpu.utilization}%
))}
)}
)}
) } export default SystemMonitor