Skip to content

Commit

Permalink
chore: show list gpus on system monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
urmauur committed Jan 29, 2025
1 parent eca2f3f commit defb494
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 77 deletions.
8 changes: 4 additions & 4 deletions web/containers/Layout/BottomPanel/SystemMonitor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ const SystemMonitor = () => {
<div className="mb-4 border-b border-[hsla(var(--app-border))] pb-4 last:border-none">
{gpus.map((gpu, index) => {
const gpuUtilization = utilizedMemory(
gpu.memoryFree,
gpu.memoryTotal
gpu.free_vram,
gpu.total_vram
)
return (
<div key={index} className="mt-4 flex flex-col gap-x-2">
Expand All @@ -163,8 +163,8 @@ const SystemMonitor = () => {
<div className="flex gap-x-2">
<div className="">
<span>
{gpu.memoryTotal - gpu.memoryFree}/
{gpu.memoryTotal}
{gpu.total_vram - gpu.free_vram}/
{gpu.total_vram}
</span>
<span> MB</span>
</div>
Expand Down
2 changes: 2 additions & 0 deletions web/helpers/atoms/App.atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export const mainViewStateAtom = atom<MainViewState>(MainViewState.Thread)

export const defaultJanDataFolderAtom = atom<string>('')

export const LocalEngineDefaultVariantAtom = atom<string>('')

const SHOW_RIGHT_PANEL = 'showRightPanel'

// Store panel atom
Expand Down
134 changes: 64 additions & 70 deletions web/hooks/useGetSystemResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,89 +9,83 @@ import {
cpuUsageAtom,
totalRamAtom,
usedRamAtom,
// nvidiaTotalVramAtom,
// gpusAtom,
nvidiaTotalVramAtom,
gpusAtom,
ramUtilitizedAtom,
// availableVramAtom,
availableVramAtom,
} from '@/helpers/atoms/SystemBar.atom'

export default function useGetSystemResources() {
const [intervalId, setIntervalId] = useState<
NodeJS.Timeout | number | undefined
>(undefined)

// const setGpus = useSetAtom(gpusAtom)
const setGpus = useSetAtom(gpusAtom)
const setCpuUsage = useSetAtom(cpuUsageAtom)
// const setTotalNvidiaVram = useSetAtom(nvidiaTotalVramAtom)
// const setAvailableVram = useSetAtom(availableVramAtom)
const setTotalNvidiaVram = useSetAtom(nvidiaTotalVramAtom)
const setAvailableVram = useSetAtom(availableVramAtom)
const setUsedRam = useSetAtom(usedRamAtom)
const setTotalRam = useSetAtom(totalRamAtom)
const setRamUtilitized = useSetAtom(ramUtilitizedAtom)

const getSystemResources = useCallback(
async () => {
if (
!extensionManager.get<HardwareManagementExtension>(
ExtensionTypeEnum.Hardware
)
) {
return
}

const hardwareExtension =
extensionManager.get<HardwareManagementExtension>(
ExtensionTypeEnum.Hardware
)

const hardwareInfo = await hardwareExtension?.getHardware()

// const currentLoadInfor = await monitoring?.getCurrentLoad()

const usedMemory =
Number(hardwareInfo?.ram.total) - Number(hardwareInfo?.ram.available)

if (hardwareInfo?.ram?.total && hardwareInfo?.ram?.available)
setUsedRam(Number(usedMemory))

if (hardwareInfo?.ram?.total) setTotalRam(hardwareInfo.ram.total)

const ramUtilitized =
((Number(usedMemory) ?? 0) / (hardwareInfo?.ram.total ?? 1)) * 100

setRamUtilitized(Math.round(ramUtilitized))

setCpuUsage(Math.round(hardwareInfo?.cpu.usage ?? 0))

// const gpus = currentLoadInfor?.gpu ?? []
// setGpus(gpus)

// let totalNvidiaVram = 0
// if (gpus.length > 0) {
// totalNvidiaVram = gpus.reduce(
// (total: number, gpu: { memoryTotal: string }) =>
// total + Number(gpu.memoryTotal),
// 0
// )
// }
// setTotalNvidiaVram(totalNvidiaVram)
// setAvailableVram(
// gpus.reduce(
// (total: number, gpu: { memoryFree: string }) =>
// total + Number(gpu.memoryFree),
// 0
// )
// )
},
[
// setUsedRam,
// setTotalRam,
// setRamUtilitized,
// setCpuUsage,
// setGpus,
// setTotalNvidiaVram,
// setAvailableVram,
]
)
const getSystemResources = useCallback(async () => {
if (
!extensionManager.get<HardwareManagementExtension>(
ExtensionTypeEnum.Hardware
)
) {
return
}

const hardwareExtension = extensionManager.get<HardwareManagementExtension>(
ExtensionTypeEnum.Hardware
)

const hardwareInfo = await hardwareExtension?.getHardware()

const usedMemory =
Number(hardwareInfo?.ram.total) - Number(hardwareInfo?.ram.available)

if (hardwareInfo?.ram?.total && hardwareInfo?.ram?.available)
setUsedRam(Number(usedMemory))

if (hardwareInfo?.ram?.total) setTotalRam(hardwareInfo.ram.total)

const ramUtilitized =
((Number(usedMemory) ?? 0) / (hardwareInfo?.ram.total ?? 1)) * 100

setRamUtilitized(Math.round(ramUtilitized))

setCpuUsage(Math.round(hardwareInfo?.cpu.usage ?? 0))

const gpus = hardwareInfo?.gpus ?? []
setGpus(gpus as any)

Check failure on line 62 in web/hooks/useGetSystemResources.ts

View workflow job for this annotation

GitHub Actions / test-on-macos

Unexpected any. Specify a different type

Check failure on line 62 in web/hooks/useGetSystemResources.ts

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

Unexpected any. Specify a different type

Check failure on line 62 in web/hooks/useGetSystemResources.ts

View workflow job for this annotation

GitHub Actions / coverage-check

Unexpected any. Specify a different type

Check failure on line 62 in web/hooks/useGetSystemResources.ts

View workflow job for this annotation

GitHub Actions / test-on-windows-pr

Unexpected any. Specify a different type

let totalNvidiaVram = 0
if (gpus.length > 0) {
totalNvidiaVram = gpus.reduce(
(total: number, gpu: { total_vram: number }) =>
total + Number(gpu.total_vram),
0
)
}

setTotalNvidiaVram(totalNvidiaVram)

setAvailableVram(
gpus.reduce((total, gpu) => {
return total + Number(gpu.free_vram || 0)
}, 0)
)
}, [

Check warning on line 80 in web/hooks/useGetSystemResources.ts

View workflow job for this annotation

GitHub Actions / test-on-macos

React Hook useCallback has a missing dependency: 'setTotalNvidiaVram'. Either include it or remove the dependency array

Check warning on line 80 in web/hooks/useGetSystemResources.ts

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

React Hook useCallback has a missing dependency: 'setTotalNvidiaVram'. Either include it or remove the dependency array

Check warning on line 80 in web/hooks/useGetSystemResources.ts

View workflow job for this annotation

GitHub Actions / coverage-check

React Hook useCallback has a missing dependency: 'setTotalNvidiaVram'. Either include it or remove the dependency array

Check warning on line 80 in web/hooks/useGetSystemResources.ts

View workflow job for this annotation

GitHub Actions / test-on-windows-pr

React Hook useCallback has a missing dependency: 'setTotalNvidiaVram'. Either include it or remove the dependency array
setUsedRam,
setTotalRam,
setRamUtilitized,
setCpuUsage,
setGpus,
// setTotalNvidiaVram,
setAvailableVram,
])

const watch = () => {
getSystemResources()
Expand Down
6 changes: 4 additions & 2 deletions web/screens/Settings/Engines/LocalEngineSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { formatDownloadPercentage } from '@/utils/converter'
import ExtensionSetting from '../ExtensionSetting'

import DeleteEngineVariant from './DeleteEngineVariant'

Check failure on line 29 in web/screens/Settings/Engines/LocalEngineSettings.tsx

View workflow job for this annotation

GitHub Actions / test-on-macos

There should be at least one empty line between import groups

Check failure on line 29 in web/screens/Settings/Engines/LocalEngineSettings.tsx

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

There should be at least one empty line between import groups

Check failure on line 29 in web/screens/Settings/Engines/LocalEngineSettings.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

There should be at least one empty line between import groups

Check failure on line 29 in web/screens/Settings/Engines/LocalEngineSettings.tsx

View workflow job for this annotation

GitHub Actions / test-on-windows-pr

There should be at least one empty line between import groups
import { LocalEngineDefaultVariantAtom } from '@/helpers/atoms/App.atom'

Check failure on line 30 in web/screens/Settings/Engines/LocalEngineSettings.tsx

View workflow job for this annotation

GitHub Actions / test-on-macos

There should be at least one empty line between import groups

Check failure on line 30 in web/screens/Settings/Engines/LocalEngineSettings.tsx

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

There should be at least one empty line between import groups

Check failure on line 30 in web/screens/Settings/Engines/LocalEngineSettings.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

There should be at least one empty line between import groups

Check failure on line 30 in web/screens/Settings/Engines/LocalEngineSettings.tsx

View workflow job for this annotation

GitHub Actions / test-on-windows-pr

There should be at least one empty line between import groups
import { useAtom } from 'jotai'

Check failure on line 31 in web/screens/Settings/Engines/LocalEngineSettings.tsx

View workflow job for this annotation

GitHub Actions / test-on-macos

`jotai` import should occur before import of `tailwind-merge`

Check failure on line 31 in web/screens/Settings/Engines/LocalEngineSettings.tsx

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

`jotai` import should occur before import of `tailwind-merge`

Check failure on line 31 in web/screens/Settings/Engines/LocalEngineSettings.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

`jotai` import should occur before import of `tailwind-merge`

Check failure on line 31 in web/screens/Settings/Engines/LocalEngineSettings.tsx

View workflow job for this annotation

GitHub Actions / test-on-windows-pr

`jotai` import should occur before import of `tailwind-merge`
const os = () => {
switch (PLATFORM) {
case 'win32':
Expand Down Expand Up @@ -86,8 +88,8 @@ const LocalEngineSettings = ({ engine }: { engine: InferenceEngine }) => {
(x: any) => x.version === defaultEngineVariant?.version
)

const [selectedVariants, setSelectedVariants] = useState(
defaultEngineVariant?.variant
const [selectedVariants, setSelectedVariants] = useAtom(
LocalEngineDefaultVariantAtom
)

const selectedVariant = useMemo(
Expand Down
17 changes: 16 additions & 1 deletion web/services/appService.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DefaultEngineVariant } from './../../core/src/types/engine/index'

Check failure on line 1 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / test-on-macos

There should be at least one empty line between import groups

Check warning on line 1 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / test-on-macos

'DefaultEngineVariant' is defined but never used

Check failure on line 1 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

There should be at least one empty line between import groups

Check warning on line 1 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

'DefaultEngineVariant' is defined but never used

Check failure on line 1 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / coverage-check

There should be at least one empty line between import groups

Check warning on line 1 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / coverage-check

'DefaultEngineVariant' is defined but never used

Check failure on line 1 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / test-on-windows-pr

There should be at least one empty line between import groups

Check warning on line 1 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / test-on-windows-pr

'DefaultEngineVariant' is defined but never used
import {

Check failure on line 2 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / test-on-macos

`@janhq/core` import should occur before import of `./../../core/src/types/engine/index`

Check failure on line 2 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

`@janhq/core` import should occur before import of `./../../core/src/types/engine/index`

Check failure on line 2 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / coverage-check

`@janhq/core` import should occur before import of `./../../core/src/types/engine/index`

Check failure on line 2 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / test-on-windows-pr

`@janhq/core` import should occur before import of `./../../core/src/types/engine/index`
ExtensionTypeEnum,
HardwareManagementExtension,
Expand All @@ -7,23 +8,32 @@ import {
SystemInformation,
GpuSetting,
GpuSettingInfo,
EngineManagementExtension,
} from '@janhq/core'

import { toaster } from '@/containers/Toast'

Check failure on line 14 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / test-on-macos

`@/containers/Toast` import should occur before import of `./../../core/src/types/engine/index`

Check failure on line 14 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

`@/containers/Toast` import should occur before import of `./../../core/src/types/engine/index`

Check failure on line 14 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / coverage-check

`@/containers/Toast` import should occur before import of `./../../core/src/types/engine/index`

Check failure on line 14 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / test-on-windows-pr

`@/containers/Toast` import should occur before import of `./../../core/src/types/engine/index`

import { extensionManager } from '@/extension'

Check failure on line 16 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / test-on-macos

There should be at least one empty line between import groups

Check failure on line 16 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

There should be at least one empty line between import groups

Check failure on line 16 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / coverage-check

There should be at least one empty line between import groups

Check failure on line 16 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / test-on-windows-pr

There should be at least one empty line between import groups
import { useAtomValue } from 'jotai'

Check failure on line 17 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / test-on-macos

There should be at least one empty line between import groups

Check failure on line 17 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / test-on-macos

`jotai` import should occur before import of `./../../core/src/types/engine/index`

Check failure on line 17 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

There should be at least one empty line between import groups

Check failure on line 17 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

`jotai` import should occur before import of `./../../core/src/types/engine/index`

Check failure on line 17 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / coverage-check

There should be at least one empty line between import groups

Check failure on line 17 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / coverage-check

`jotai` import should occur before import of `./../../core/src/types/engine/index`

Check failure on line 17 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / test-on-windows-pr

There should be at least one empty line between import groups

Check failure on line 17 in web/services/appService.ts

View workflow job for this annotation

GitHub Actions / test-on-windows-pr

`jotai` import should occur before import of `./../../core/src/types/engine/index`
import { LocalEngineDefaultVariantAtom } from '@/helpers/atoms/App.atom'

export const appService = {
systemInformation: async (): Promise<SystemInformation | undefined> => {
// const monitorExtension = extensionManager?.get<MonitoringExtension>(
// ExtensionTypeEnum.SystemMonitoring
// )

const selectedVariants = useAtomValue(LocalEngineDefaultVariantAtom)

const hardwareExtension =
extensionManager?.get<HardwareManagementExtension>(
ExtensionTypeEnum.Hardware
)

const engineExtension = extensionManager?.get<EngineManagementExtension>(
ExtensionTypeEnum.Engine
)

// if (!monitorExtension) {
// console.warn('System monitoring extension not found')
// return undefined
Expand All @@ -34,13 +44,18 @@ export const appService = {
return undefined
}

if (!engineExtension) {
console.warn('Engine extension not found')
return undefined
}

// const gpuSetting = await monitorExtension.getGpuSetting()
// const osInfo = await monitorExtension.getOsInfo()
const hardwareInfo = await hardwareExtension?.getHardware()

const gpuSettingInfo: GpuSetting | undefined = {
gpus: hardwareInfo.gpus as GpuSettingInfo[],
vulkan: false,
vulkan: isMac ? false : selectedVariants.includes('vulkan'),
}

const updateOsInfo = {
Expand Down

0 comments on commit defb494

Please sign in to comment.