-
Notifications
You must be signed in to change notification settings - Fork 6k
feat(admin): add system status panel with database, storage, and update status. #3747
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ritiksahni
wants to merge
2
commits into
umami-software:master
Choose a base branch
from
ritiksahni:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,252 @@ | ||
| 'use client'; | ||
| import { Column, Grid, Text, StatusLight, Heading, Row, ProgressBar } from '@umami/react-zen'; | ||
| import { useMessages } from '@/components/hooks'; | ||
| import { PageHeader } from '@/components/common/PageHeader'; | ||
| import { Panel } from '@/components/common/Panel'; | ||
| import { useApi } from '@/components/hooks/useApi'; | ||
| import { Database, HardDrive, Download, AlertCircle } from '@/components/icons'; | ||
|
|
||
| interface DatabaseStatus { | ||
| connected: boolean; | ||
| type: string; | ||
| error?: string; | ||
| } | ||
|
|
||
| interface StorageStatus { | ||
| available: boolean; | ||
| total: number; | ||
| free: number; | ||
| used: number; | ||
| percentage: number; | ||
| path: string; | ||
| error?: string; | ||
| } | ||
|
|
||
| interface UpdateStatus { | ||
| current: string; | ||
| latest?: string; | ||
| updateAvailable: boolean; | ||
| error?: string; | ||
| } | ||
|
|
||
| interface SystemStatus { | ||
| database: DatabaseStatus; | ||
| storage: StorageStatus; | ||
| updates: UpdateStatus; | ||
| } | ||
|
|
||
| function formatBytes(bytes: number): string { | ||
| if (bytes === 0) return '0 B'; | ||
|
|
||
| const k = 1024; | ||
| const sizes = ['B', 'KB', 'MB', 'GB', 'TB']; | ||
| const i = Math.floor(Math.log(bytes) / Math.log(k)); | ||
|
|
||
| return `${parseFloat((bytes / Math.pow(k, i)).toFixed(2))} ${sizes[i]}`; | ||
| } | ||
|
|
||
| function StatusCard({ | ||
| title, | ||
| icon, | ||
| status, | ||
| children, | ||
| }: { | ||
| title: string; | ||
| icon: React.ReactNode; | ||
| status: 'success' | 'error' | 'warning'; | ||
| children: React.ReactNode; | ||
| }) { | ||
| return ( | ||
| <Panel> | ||
| <Column gap="4"> | ||
| <Row alignItems="center" gap="3"> | ||
| {icon} | ||
| <Heading size="3">{title}</Heading> | ||
| </Row> | ||
| <StatusLight variant={status === 'success' ? 'success' : status === 'error' ? 'error' : 'warning'}> | ||
| <Text size="2" weight="medium"> | ||
| {status === 'success' ? 'Operational' : status === 'error' ? 'Error' : 'Warning'} | ||
| </Text> | ||
| </StatusLight> | ||
| {children} | ||
| </Column> | ||
| </Panel> | ||
| ); | ||
| } | ||
|
|
||
| function DatabaseStatusCard({ database }: { database: DatabaseStatus }) { | ||
| const { formatMessage, labels } = useMessages(); | ||
|
|
||
| return ( | ||
| <StatusCard | ||
| title={formatMessage(labels.database) || 'Database'} | ||
| icon={<Database size={24} />} | ||
| status={database.connected ? 'success' : 'error'} | ||
| > | ||
| <Column gap="2"> | ||
| <Row justifyContent="space-between"> | ||
| <Text color="muted">Type:</Text> | ||
| <Text weight="medium">{database.type}</Text> | ||
| </Row> | ||
| <Row justifyContent="space-between"> | ||
| <Text color="muted">Status:</Text> | ||
| <Text weight="medium" color={database.connected ? 'success' : 'error'}> | ||
| {database.connected ? 'Connected' : 'Disconnected'} | ||
| </Text> | ||
| </Row> | ||
| {database.error && ( | ||
| <Text size="2" color="error"> | ||
| {database.error} | ||
| </Text> | ||
| )} | ||
| </Column> | ||
| </StatusCard> | ||
| ); | ||
| } | ||
|
|
||
| function StorageStatusCard({ storage }: { storage: StorageStatus }) { | ||
| const { formatMessage, labels } = useMessages(); | ||
|
|
||
| if (!storage.available) { | ||
| return ( | ||
| <StatusCard | ||
| title={formatMessage(labels.storage) || 'Storage'} | ||
| icon={<HardDrive size={24} />} | ||
| status="warning" | ||
| > | ||
| <Column gap="2"> | ||
| <Text size="2" color="error"> | ||
| {storage.error || 'Unable to determine storage usage'} | ||
| </Text> | ||
| <Text size="2" color="muted"> | ||
| Path: {storage.path} | ||
| </Text> | ||
| </Column> | ||
| </StatusCard> | ||
| ); | ||
| } | ||
|
|
||
| const status = storage.percentage >= 90 ? 'error' : storage.percentage >= 75 ? 'warning' : 'success'; | ||
|
|
||
| return ( | ||
| <StatusCard | ||
| title={formatMessage(labels.storage) || 'Storage'} | ||
| icon={<HardDrive size={24} />} | ||
| status={status} | ||
| > | ||
| <Column gap="3"> | ||
| <Column gap="2"> | ||
| <Row justifyContent="space-between"> | ||
| <Text color="muted">Total:</Text> | ||
| <Text weight="medium">{formatBytes(storage.total)}</Text> | ||
| </Row> | ||
| <Row justifyContent="space-between"> | ||
| <Text color="muted">Used:</Text> | ||
| <Text weight="medium">{formatBytes(storage.used)}</Text> | ||
| </Row> | ||
| <Row justifyContent="space-between"> | ||
| <Text color="muted">Free:</Text> | ||
| <Text weight="medium">{formatBytes(storage.free)}</Text> | ||
| </Row> | ||
| <Row justifyContent="space-between"> | ||
| <Text color="muted">Usage:</Text> | ||
| <Text weight="medium">{storage.percentage}%</Text> | ||
| </Row> | ||
| </Column> | ||
| <ProgressBar value={storage.percentage} max={100} /> | ||
| <Text size="2" color="muted"> | ||
| Path: {storage.path} | ||
| </Text> | ||
| </Column> | ||
| </StatusCard> | ||
| ); | ||
| } | ||
|
|
||
| function UpdateStatusCard({ updates }: { updates: UpdateStatus }) { | ||
| const { formatMessage, labels } = useMessages(); | ||
|
|
||
| // Only show error status if there's an actual error message | ||
| // If latest is just not available, show success (current version is fine) | ||
| const status = updates.updateAvailable ? 'warning' : updates.error ? 'error' : 'success'; | ||
|
|
||
| return ( | ||
| <StatusCard | ||
| title={formatMessage(labels.updates) || 'Updates'} | ||
| icon={<Download size={24} />} | ||
| status={status} | ||
| > | ||
| <Column gap="2"> | ||
| <Row justifyContent="space-between"> | ||
| <Text color="muted">Current Version:</Text> | ||
| <Text weight="medium">{updates.current}</Text> | ||
| </Row> | ||
| {updates.latest ? ( | ||
| <> | ||
| <Row justifyContent="space-between"> | ||
| <Text color="muted">Latest Version:</Text> | ||
| <Text weight="medium">{updates.latest}</Text> | ||
| </Row> | ||
| {updates.updateAvailable && ( | ||
| <Row alignItems="center" gap="2" marginTop="2"> | ||
| <AlertCircle size={16} /> | ||
| <Text size="2" color="warning"> | ||
| Update available | ||
| </Text> | ||
| </Row> | ||
| )} | ||
| {!updates.updateAvailable && ( | ||
| <Text size="2" color="muted" marginTop="2"> | ||
| You are running the latest version | ||
| </Text> | ||
| )} | ||
| </> | ||
| ) : ( | ||
| <Text size="2" color="muted" marginTop="2"> | ||
| {updates.error || 'Unable to check for updates'} | ||
| </Text> | ||
| )} | ||
| </Column> | ||
| </StatusCard> | ||
| ); | ||
| } | ||
|
|
||
| export function StatusPage() { | ||
| const { formatMessage, labels } = useMessages(); | ||
| const { get, useQuery: useApiQuery } = useApi(); | ||
|
|
||
| const { data, isLoading, error } = useApiQuery<SystemStatus>({ | ||
| queryKey: ['admin', 'status'], | ||
| queryFn: () => get('/admin/status'), | ||
| refetchInterval: 60000, // Refetch every minute | ||
| }); | ||
|
|
||
| if (isLoading) { | ||
| return ( | ||
| <Column gap="6" margin="2"> | ||
| <PageHeader title={formatMessage(labels.systemStatus) || 'System Status'} /> | ||
| <Text>Loading...</Text> | ||
| </Column> | ||
| ); | ||
| } | ||
|
|
||
| if (error || !data) { | ||
| return ( | ||
| <Column gap="6" margin="2"> | ||
| <PageHeader title={formatMessage(labels.systemStatus) || 'System Status'} /> | ||
| <Text color="error">Failed to load system status</Text> | ||
| </Column> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <Column gap="6" margin="2"> | ||
| <PageHeader title={formatMessage(labels.systemStatus) || 'System Status'} /> | ||
| <Grid columns={{ xs: '1fr', md: '1fr 1fr', lg: '1fr 1fr 1fr' }} gap="3"> | ||
| <DatabaseStatusCard database={data.database} /> | ||
| <StorageStatusCard storage={data.storage} /> | ||
| <UpdateStatusCard updates={data.updates} /> | ||
| </Grid> | ||
| </Column> | ||
| ); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { Metadata } from 'next'; | ||
| import { StatusPage } from './StatusPage'; | ||
|
|
||
| export default async function () { | ||
| return <StatusPage />; | ||
| } | ||
|
|
||
| export const metadata: Metadata = { | ||
| title: 'System Status', | ||
| }; | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.