Add status monitoring
This commit is contained in:
150
src/App.tsx
150
src/App.tsx
@@ -1,9 +1,11 @@
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
||||
import { Separator } from "@/components/ui/separator"
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Moon, Sun } from "lucide-react"
|
||||
import { Moon, Sun, Monitor, CheckCircle2, XCircle, AlertCircle, Clock } from "lucide-react"
|
||||
import { useTheme } from "@/components/theme-provider"
|
||||
import { useMetrics } from "./hooks/useMetrics"
|
||||
import { ServiceStatus } from "./types/metrics"
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"
|
||||
import {
|
||||
Server,
|
||||
Box,
|
||||
@@ -30,6 +32,7 @@ interface ServiceCard {
|
||||
url: string
|
||||
icon: React.ReactNode
|
||||
category: 'system' | 'media' | 'monitoring' | 'tools' | 'acot' | 'home'
|
||||
monitorName?: string // Optional monitor name that matches Uptime Kuma
|
||||
}
|
||||
|
||||
const services: ServiceCard[] = [
|
||||
@@ -59,7 +62,8 @@ const services: ServiceCard[] = [
|
||||
description: "Synology NAS",
|
||||
url: "https://diskstation.kent.pw",
|
||||
icon: <HardDrive className="h-6 w-6" />,
|
||||
category: "system"
|
||||
category: "system",
|
||||
monitorName: "Synology Diskstation"
|
||||
},
|
||||
{
|
||||
name: "Plex",
|
||||
@@ -101,21 +105,24 @@ const services: ServiceCard[] = [
|
||||
description: "Network Ad Blocking",
|
||||
url: "https://adguard.kent.pw",
|
||||
icon: <Shield className="h-6 w-6" />,
|
||||
category: "system"
|
||||
category: "system",
|
||||
monitorName: "Adguard Home"
|
||||
},
|
||||
{
|
||||
name: "NocoDB",
|
||||
description: "Database Platform",
|
||||
url: "https://noco.kent.pw",
|
||||
icon: <Database className="h-6 w-6" />,
|
||||
category: "tools"
|
||||
category: "tools",
|
||||
monitorName: "NocoDB"
|
||||
},
|
||||
{
|
||||
name: "IT Tools",
|
||||
description: "Developer Utilities",
|
||||
url: "https://ittools.kent.pw",
|
||||
icon: <Settings className="h-6 w-6" />,
|
||||
category: "tools"
|
||||
category: "tools",
|
||||
monitorName: "IT Tools"
|
||||
},
|
||||
{
|
||||
name: "Firefox",
|
||||
@@ -129,14 +136,16 @@ const services: ServiceCard[] = [
|
||||
description: "Network Speed Monitor",
|
||||
url: "https://speedtest.kent.pw",
|
||||
icon: <Gauge className="h-6 w-6" />,
|
||||
category: "monitoring"
|
||||
category: "monitoring",
|
||||
monitorName: "Speedtest Tracker"
|
||||
},
|
||||
{
|
||||
name: "Drive",
|
||||
description: "File Storage",
|
||||
url: "https://drive.kent.pw",
|
||||
icon: <HardDrive className="h-6 w-6" />,
|
||||
category: "tools"
|
||||
category: "tools",
|
||||
monitorName: "Synology Drive"
|
||||
},
|
||||
{
|
||||
name: "Dashboard",
|
||||
@@ -169,33 +178,82 @@ const services: ServiceCard[] = [
|
||||
]
|
||||
|
||||
function ThemeToggle() {
|
||||
const { setTheme } = useTheme()
|
||||
const { theme, setTheme } = useTheme()
|
||||
|
||||
const cycleTheme = () => {
|
||||
if (theme === 'light') setTheme('dark')
|
||||
else if (theme === 'dark') setTheme('system')
|
||||
else setTheme('light')
|
||||
}
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="outline" size="icon">
|
||||
<Sun className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
|
||||
<Moon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
|
||||
<span className="sr-only">Toggle theme</span>
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={() => setTheme("light")}>
|
||||
Light
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => setTheme("dark")}>
|
||||
Dark
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => setTheme("system")}>
|
||||
System
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={cycleTheme}
|
||||
className="relative w-10 h-10"
|
||||
>
|
||||
<Sun className={`h-[1.2rem] w-[1.2rem] transition-all ${
|
||||
theme === 'light' ? 'scale-100 rotate-0' : 'scale-0 rotate-90'
|
||||
}`} />
|
||||
<Moon className={`absolute h-[1.2rem] w-[1.2rem] transition-all ${
|
||||
theme === 'dark' ? 'scale-100 rotate-0' : 'scale-0 rotate-90'
|
||||
}`} />
|
||||
<Monitor className={`absolute h-[1.2rem] w-[1.2rem] transition-all ${
|
||||
theme === 'system' ? 'scale-100 rotate-0' : 'scale-0 rotate-90'
|
||||
}`} />
|
||||
<span className="sr-only">Toggle theme</span>
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
function ServiceSection({ title, services }: { title: string, services: ServiceCard[] }) {
|
||||
function StatusIndicator({ status, responseTime, certDaysRemaining }: {
|
||||
status: ServiceStatus,
|
||||
responseTime: number,
|
||||
certDaysRemaining: number
|
||||
}) {
|
||||
const getStatusIcon = () => {
|
||||
switch (status) {
|
||||
case 'up':
|
||||
return <CheckCircle2 className="h-4 w-4 text-green-500" />
|
||||
case 'down':
|
||||
return <XCircle className="h-4 w-4 text-red-500" />
|
||||
case 'pending':
|
||||
return <Clock className="h-4 w-4 text-yellow-500" />
|
||||
case 'maintenance':
|
||||
return <AlertCircle className="h-4 w-4 text-blue-500" />
|
||||
}
|
||||
}
|
||||
|
||||
const getStatusText = () => {
|
||||
const statusText = status.charAt(0).toUpperCase() + status.slice(1)
|
||||
const responseTimeText = `Response time: ${responseTime}ms`
|
||||
const certText = certDaysRemaining > 0
|
||||
? `SSL cert expires in ${certDaysRemaining} days`
|
||||
: 'SSL cert expired'
|
||||
|
||||
return `${statusText} • ${responseTimeText} • ${certText}`
|
||||
}
|
||||
|
||||
return (
|
||||
<TooltipProvider>
|
||||
<Tooltip>
|
||||
<TooltipTrigger>
|
||||
{getStatusIcon()}
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>
|
||||
<p>{getStatusText()}</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
)
|
||||
}
|
||||
|
||||
function ServiceSection({ title, services, metrics }: {
|
||||
title: string,
|
||||
services: ServiceCard[],
|
||||
metrics: Record<string, any>
|
||||
}) {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center">
|
||||
@@ -204,6 +262,12 @@ function ServiceSection({ title, services }: { title: string, services: ServiceC
|
||||
</div>
|
||||
<div className="grid grid-cols-2 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-4">
|
||||
{services.map((service) => {
|
||||
const serviceMetrics = metrics[service.monitorName || service.name] || {
|
||||
status: 'pending',
|
||||
responseTime: 0,
|
||||
certDaysRemaining: 0
|
||||
}
|
||||
|
||||
// Get background color based on service
|
||||
const bgColor = (() => {
|
||||
switch (service.name) {
|
||||
@@ -283,9 +347,16 @@ function ServiceSection({ title, services }: { title: string, services: ServiceC
|
||||
className="transition-transform hover:scale-105"
|
||||
>
|
||||
<Card className={bgColor}>
|
||||
<CardHeader className="flex flex-row items-center space-y-0 pb-2">
|
||||
<div className={iconColor}>{service.icon}</div>
|
||||
<CardTitle className="ml-2">{service.name}</CardTitle>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||
<div className="flex items-center">
|
||||
<div className={iconColor}>{service.icon}</div>
|
||||
<CardTitle className="ml-2">{service.name}</CardTitle>
|
||||
</div>
|
||||
<StatusIndicator
|
||||
status={serviceMetrics.status}
|
||||
responseTime={serviceMetrics.responseTime}
|
||||
certDaysRemaining={serviceMetrics.certDaysRemaining}
|
||||
/>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<CardDescription>{service.description}</CardDescription>
|
||||
@@ -300,6 +371,7 @@ function ServiceSection({ title, services }: { title: string, services: ServiceC
|
||||
}
|
||||
|
||||
function App() {
|
||||
const { metrics, loading, error } = useMetrics(import.meta.env.VITE_UPTIME_API_KEY)
|
||||
const systemServices = services.filter(s => s.category === 'system')
|
||||
const mediaServices = services.filter(s => s.category === 'media')
|
||||
const monitoringServices = services.filter(s => s.category === 'monitoring')
|
||||
@@ -313,12 +385,12 @@ function App() {
|
||||
<h1 className="text-4xl font-bold">Kent.pw Homepage</h1>
|
||||
<ThemeToggle />
|
||||
</div>
|
||||
<ServiceSection title="System" services={systemServices} />
|
||||
<ServiceSection title="Media" services={mediaServices} />
|
||||
<ServiceSection title="Monitoring" services={monitoringServices} />
|
||||
<ServiceSection title="Tools" services={toolServices} />
|
||||
<ServiceSection title="ACOT" services={acotServices} />
|
||||
<ServiceSection title="Home" services={homeServices} />
|
||||
<ServiceSection title="System" services={systemServices} metrics={metrics} />
|
||||
<ServiceSection title="Media" services={mediaServices} metrics={metrics} />
|
||||
<ServiceSection title="Monitoring" services={monitoringServices} metrics={metrics} />
|
||||
<ServiceSection title="Tools" services={toolServices} metrics={metrics} />
|
||||
<ServiceSection title="ACOT" services={acotServices} metrics={metrics} />
|
||||
<ServiceSection title="Home" services={homeServices} metrics={metrics} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user