diff --git a/ee/tabby-ui/app/(dashboard)/cluster/components/cluster.tsx b/ee/tabby-ui/app/(dashboard)/cluster/components/cluster.tsx index 20b74ef79ca0..f40dd4eba1e2 100644 --- a/ee/tabby-ui/app/(dashboard)/cluster/components/cluster.tsx +++ b/ee/tabby-ui/app/(dashboard)/cluster/components/cluster.tsx @@ -1,12 +1,17 @@ 'use client' -import { noop } from 'lodash-es' +import bytes from 'bytes' +import { noop, sum } from 'lodash-es' +import { useTheme } from 'next-themes' +import { Cell, Label, Pie, PieChart, ResponsiveContainer } from 'recharts' import { useQuery } from 'urql' -import bytes from 'bytes'; -import { useTheme } from 'next-themes'; import { graphql } from '@/lib/gql/generates' -import { WorkerKind } from '@/lib/gql/generates/graphql' +import { + DiskUsage, + DiskUsageStats, + WorkerKind +} from '@/lib/gql/generates/graphql' import { useHealth } from '@/lib/hooks/use-health' import { useWorkers } from '@/lib/hooks/use-workers' import { useMutation } from '@/lib/tabby/gql' @@ -15,19 +20,7 @@ import { IconRotate } from '@/components/ui/icons' import { Input } from '@/components/ui/input' import { Separator } from '@/components/ui/separator' import { CopyButton } from '@/components/copy-button' -import { - ResponsiveContainer, - PieChart, - Pie, - Cell, - Label, -} from 'recharts' -import { - Tooltip, - TooltipContent, - TooltipTrigger, -} from "@/components/ui/tooltip" -import { IconFolderOpen } from '@/components/ui/icons'; +import LoadingWrapper from '@/components/loading-wrapper' import WorkerCard from './worker-card' @@ -62,15 +55,6 @@ export default function Workers() { if (!healthInfo) return - // TODO: mock data - const usageData = [ - { name: "Models", usage: 1024 * 1024 * 1024 * 1.1, color: "#0088FE", folders: ["~/.tabby/models"] }, - { name: "Repository data", usage: 1024 * 1024 * 2.1, color: "#00C49F", folders: ["~/.tabby/dataset", "~/.tabby/index"] }, - { name: "Database", usage: 1024 * 85, color: "#FFBB28", folders: ["~/.tabby/ee"] }, - { name: "Events", usage: 1024 * 1200 * 11, color: "#FF8042", folders: ["~/.tabby/events"] } - ]; - const totalUsage = 1024 * 1300 * 1200 - return (
- Storage Usage -
-Disk space used by Tabby
-{item.name}
-{bytes(item.usage)}
-Folder
+export const getDiskUsageStats = graphql(/* GraphQL */ ` + query GetDiskUsageStats { + diskUsageStats { + events { + filePaths + size + } + indexedRepositories { + filePaths + size + } + database { + filePaths + size + } + models { + filePaths + size + } + } + } +`) + +type UsageItem = { + label: string + key: keyof DiskUsageStats + color: string +} + +type UsageItemWithSize = UsageItem & { size: number } + +const usageList: UsageItem[] = [ + { + label: 'Model Cache', + key: 'models', + color: '#0088FE' + }, + { + label: 'Repository Context', + key: 'indexedRepositories', + color: '#00C49F' + }, + { + label: 'Event Logs', + key: 'events', + color: '#FF8042' + }, + { + label: 'Other', + key: 'database', + color: '#FFBB28' + } +] + +function Usage() { + const [{ data, fetching }] = useQuery({ + query: getDiskUsageStats + }) + + let usageData: UsageItemWithSize[] = [] + let totalUsage: number = 0 + if (data) { + usageData = usageList + .map(usage => { + if (!data.diskUsageStats[usage.key]) return null + const diskUsage = data.diskUsageStats[usage.key] as DiskUsage + return { + ...usage, + size: diskUsage.size + } + }) + .filter(usage => usage) as UsageItemWithSize[] + totalUsage = sum(usageData.map(data => data.size)) + } + + return ( +Storage Usage
++ Disk Space Utilization by Type +
+{usage!.label}
{folder}
))} - - - ))} +{bytes(usage!.size * 1024)}
+