reorganized web-app
This commit is contained in:
parent
5c87f068d6
commit
b67fe48f72
31 changed files with 1781 additions and 431 deletions
|
|
@ -2,95 +2,91 @@
|
|||
* Cache Statistics Card Component
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Card } from '../../../components/ui/Card';
|
||||
import type { CacheStats } from '../types';
|
||||
import { Card, CardHeader, CardContent } from '@/components/ui/Card';
|
||||
import { ConnectionStatus } from './StatusBadge';
|
||||
import { formatBytes, formatNumber, formatPercentage } from '../utils/formatters';
|
||||
|
||||
interface CacheStatsCardProps {
|
||||
stats: CacheStats;
|
||||
}
|
||||
|
||||
export function CacheStatsCard({ stats }: CacheStatsCardProps) {
|
||||
const formatBytes = (bytes: number) => {
|
||||
const mb = bytes / 1024 / 1024;
|
||||
return mb.toFixed(2) + ' MB';
|
||||
};
|
||||
|
||||
const hitRate = stats.stats && (stats.stats.hits + stats.stats.misses) > 0
|
||||
? (stats.stats.hits / (stats.stats.hits + stats.stats.misses) * 100).toFixed(1)
|
||||
: '0';
|
||||
? (stats.stats.hits / (stats.stats.hits + stats.stats.misses) * 100)
|
||||
: 0;
|
||||
|
||||
return (
|
||||
<Card className="p-6">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<h3 className="text-lg font-semibold">Cache (Dragonfly)</h3>
|
||||
<span className={`px-2 py-1 rounded text-xs font-medium ${
|
||||
stats.connected ? 'text-green-600 bg-green-100' : 'text-red-600 bg-red-100'
|
||||
}`}>
|
||||
{stats.connected ? 'Connected' : 'Disconnected'}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{stats.connected ? (
|
||||
<div className="space-y-4">
|
||||
{stats.memoryUsage && (
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<div className="text-sm text-gray-600">Memory Used</div>
|
||||
<div className="text-xl font-semibold">{formatBytes(stats.memoryUsage.used)}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-sm text-gray-600">Peak Memory</div>
|
||||
<div className="text-xl font-semibold">{formatBytes(stats.memoryUsage.peak)}</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{stats.stats && (
|
||||
<>
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<div className="text-sm text-gray-600">Hit Rate</div>
|
||||
<div className="text-xl font-semibold">{hitRate}%</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-sm text-gray-600">Total Keys</div>
|
||||
<div className="text-xl font-semibold">{stats.stats.keys.toLocaleString()}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-4 text-sm">
|
||||
<div>
|
||||
<span className="text-gray-600">Hits:</span> {stats.stats.hits.toLocaleString()}
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-gray-600">Misses:</span> {stats.stats.misses.toLocaleString()}
|
||||
</div>
|
||||
{stats.stats.evictedKeys !== undefined && (
|
||||
<div>
|
||||
<span className="text-gray-600">Evicted:</span> {stats.stats.evictedKeys.toLocaleString()}
|
||||
</div>
|
||||
)}
|
||||
{stats.stats.expiredKeys !== undefined && (
|
||||
<div>
|
||||
<span className="text-gray-600">Expired:</span> {stats.stats.expiredKeys.toLocaleString()}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{stats.uptime && (
|
||||
<div className="text-sm text-gray-600">
|
||||
Uptime: {Math.floor(stats.uptime / 3600)}h {Math.floor((stats.uptime % 3600) / 60)}m
|
||||
</div>
|
||||
)}
|
||||
<Card className="p-4">
|
||||
<CardHeader className="p-0 pb-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-base font-semibold text-text-primary">Cache (Dragonfly)</h3>
|
||||
<ConnectionStatus connected={stats.connected} size="md" />
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-center py-8 text-gray-500">
|
||||
Cache service is not available
|
||||
</div>
|
||||
)}
|
||||
</CardHeader>
|
||||
|
||||
<CardContent className="p-0">
|
||||
{stats.connected ? (
|
||||
<div className="space-y-3">
|
||||
{stats.memoryUsage && (
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<div className="text-sm text-text-secondary">Memory Used</div>
|
||||
<div className="text-lg font-semibold text-text-primary">{formatBytes(stats.memoryUsage.used)}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-sm text-text-secondary">Peak Memory</div>
|
||||
<div className="text-lg font-semibold text-text-primary">{formatBytes(stats.memoryUsage.peak)}</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{stats.stats && (
|
||||
<>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<div className="text-sm text-text-secondary">Hit Rate</div>
|
||||
<div className="text-lg font-semibold text-text-primary">{formatPercentage(hitRate)}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-sm text-text-secondary">Total Keys</div>
|
||||
<div className="text-lg font-semibold text-text-primary">{formatNumber(stats.stats.keys)}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-3 text-sm">
|
||||
<div>
|
||||
<span className="text-text-secondary">Hits:</span> <span className="text-text-primary">{formatNumber(stats.stats.hits)}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-text-secondary">Misses:</span> <span className="text-text-primary">{formatNumber(stats.stats.misses)}</span>
|
||||
</div>
|
||||
{stats.stats.evictedKeys !== undefined && (
|
||||
<div>
|
||||
<span className="text-text-secondary">Evicted:</span> <span className="text-text-primary">{formatNumber(stats.stats.evictedKeys)}</span>
|
||||
</div>
|
||||
)}
|
||||
{stats.stats.expiredKeys !== undefined && (
|
||||
<div>
|
||||
<span className="text-text-secondary">Expired:</span> <span className="text-text-primary">{formatNumber(stats.stats.expiredKeys)}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{stats.uptime && (
|
||||
<div className="text-sm text-text-secondary">
|
||||
Uptime: {Math.floor(stats.uptime / 3600)}h {Math.floor((stats.uptime % 3600) / 60)}m
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-center py-8 text-text-secondary">
|
||||
Cache service is not available
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
import { Card, CardHeader, CardContent } from '@/components/ui/Card';
|
||||
import { ConnectionStatus } from './StatusBadge';
|
||||
import { formatPercentage } from '../utils/formatters';
|
||||
import type { DatabaseStats } from '../types';
|
||||
|
||||
interface DatabaseCardProps {
|
||||
database: DatabaseStats;
|
||||
}
|
||||
|
||||
export function DatabaseCard({ database }: DatabaseCardProps) {
|
||||
const getDbIcon = (type: string) => {
|
||||
switch (type) {
|
||||
case 'postgres':
|
||||
return '🐘';
|
||||
case 'mongodb':
|
||||
return '🍃';
|
||||
case 'questdb':
|
||||
return '⚡';
|
||||
default:
|
||||
return '💾';
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Card className="p-4">
|
||||
<CardHeader className="p-0 pb-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center space-x-2">
|
||||
<span className="text-2xl">{getDbIcon(database.type)}</span>
|
||||
<h4 className="font-semibold text-text-primary">{database.name}</h4>
|
||||
</div>
|
||||
<ConnectionStatus connected={database.connected} />
|
||||
</div>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent className="p-0">
|
||||
{database.connected ? (
|
||||
<div className="space-y-2">
|
||||
{database.latency !== undefined && (
|
||||
<div>
|
||||
<div className="text-sm text-text-secondary">Latency</div>
|
||||
<div className="text-base font-semibold text-text-primary">{database.latency}ms</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{database.pool && (
|
||||
<div>
|
||||
<div className="text-sm text-text-secondary mb-1">Connection Pool</div>
|
||||
<div className="grid grid-cols-2 gap-2 text-xs">
|
||||
<div>
|
||||
<span className="text-text-secondary">Active:</span>{' '}
|
||||
<span className="text-text-primary">{database.pool.active}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-text-secondary">Idle:</span>{' '}
|
||||
<span className="text-text-primary">{database.pool.idle}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-text-secondary">Size:</span>{' '}
|
||||
<span className="text-text-primary">{database.pool.size}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-text-secondary">Max:</span>{' '}
|
||||
<span className="text-text-primary">{database.pool.max}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{database.pool.max > 0 && (
|
||||
<div className="mt-2">
|
||||
<div className="w-full bg-surface-tertiary rounded-full h-2">
|
||||
<div
|
||||
className="bg-primary-500 h-2 rounded-full transition-all"
|
||||
style={{ width: `${(database.pool.size / database.pool.max) * 100}%` }}
|
||||
/>
|
||||
</div>
|
||||
<div className="text-xs text-text-muted mt-1">
|
||||
{formatPercentage((database.pool.size / database.pool.max) * 100, 0)} utilized
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{database.type === 'mongodb' && database.stats && (
|
||||
<div className="text-xs text-text-secondary">
|
||||
<div>Version: <span className="text-text-primary">{database.stats.version}</span></div>
|
||||
{database.stats.connections && (
|
||||
<div>
|
||||
Connections:{' '}
|
||||
<span className="text-text-primary">
|
||||
{database.stats.connections.current}/{database.stats.connections.available}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-center py-4 text-text-secondary">
|
||||
Database is not available
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
|
@ -2,102 +2,18 @@
|
|||
* Database Statistics Grid Component
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Card } from '../../../components/ui/Card';
|
||||
import type { DatabaseStats } from '../types';
|
||||
import { DatabaseCard } from './DatabaseCard';
|
||||
|
||||
interface DatabaseStatsGridProps {
|
||||
databases: DatabaseStats[];
|
||||
}
|
||||
|
||||
export function DatabaseStatsGrid({ databases }: DatabaseStatsGridProps) {
|
||||
const getDbIcon = (type: string) => {
|
||||
switch (type) {
|
||||
case 'postgres':
|
||||
return '🐘';
|
||||
case 'mongodb':
|
||||
return '🍃';
|
||||
case 'questdb':
|
||||
return '⚡';
|
||||
default:
|
||||
return '💾';
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-3">
|
||||
{databases.map((db) => (
|
||||
<Card key={db.type} className="p-6">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<div className="flex items-center space-x-2">
|
||||
<span className="text-2xl">{getDbIcon(db.type)}</span>
|
||||
<h4 className="font-semibold">{db.name}</h4>
|
||||
</div>
|
||||
<span className={`px-2 py-1 rounded text-xs font-medium ${
|
||||
db.connected ? 'text-green-600 bg-green-100' : 'text-red-600 bg-red-100'
|
||||
}`}>
|
||||
{db.connected ? 'Connected' : 'Disconnected'}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{db.connected ? (
|
||||
<div className="space-y-3">
|
||||
{db.latency !== undefined && (
|
||||
<div>
|
||||
<div className="text-sm text-gray-600">Latency</div>
|
||||
<div className="text-lg font-semibold">{db.latency}ms</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{db.pool && (
|
||||
<div>
|
||||
<div className="text-sm text-gray-600 mb-1">Connection Pool</div>
|
||||
<div className="grid grid-cols-2 gap-2 text-sm">
|
||||
<div>
|
||||
<span className="text-gray-600">Active:</span> {db.pool.active}
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-gray-600">Idle:</span> {db.pool.idle}
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-gray-600">Size:</span> {db.pool.size}
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-gray-600">Max:</span> {db.pool.max}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{db.pool.max > 0 && (
|
||||
<div className="mt-2">
|
||||
<div className="w-full bg-gray-200 rounded-full h-2">
|
||||
<div
|
||||
className="bg-blue-600 h-2 rounded-full"
|
||||
style={{ width: `${(db.pool.size / db.pool.max) * 100}%` }}
|
||||
/>
|
||||
</div>
|
||||
<div className="text-xs text-gray-500 mt-1">
|
||||
{((db.pool.size / db.pool.max) * 100).toFixed(0)}% utilized
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{db.type === 'mongodb' && db.stats && (
|
||||
<div className="text-xs text-gray-600">
|
||||
<div>Version: {db.stats.version}</div>
|
||||
{db.stats.connections && (
|
||||
<div>Connections: {db.stats.connections.current}/{db.stats.connections.available}</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-center py-4 text-gray-500">
|
||||
Database is not available
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
<DatabaseCard key={db.type} database={db} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
import { Card, CardHeader, CardContent } from '@/components/ui/Card';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface MetricCardProps {
|
||||
title: string;
|
||||
value: string | number;
|
||||
subtitle?: string;
|
||||
icon?: React.ReactNode;
|
||||
valueClassName?: string;
|
||||
progress?: {
|
||||
value: number;
|
||||
max: number;
|
||||
label?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function MetricCard({
|
||||
title,
|
||||
value,
|
||||
subtitle,
|
||||
icon,
|
||||
valueClassName,
|
||||
progress
|
||||
}: MetricCardProps) {
|
||||
return (
|
||||
<Card className="p-3">
|
||||
<CardHeader className="p-0 pb-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<h4 className="text-sm font-medium text-text-secondary">{title}</h4>
|
||||
{icon && <div className="text-text-muted">{icon}</div>}
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent className="p-0">
|
||||
<div className={cn('text-xl font-semibold text-text-primary', valueClassName)}>
|
||||
{value}
|
||||
</div>
|
||||
{subtitle && (
|
||||
<p className="text-xs text-text-muted mt-1">{subtitle}</p>
|
||||
)}
|
||||
{progress && (
|
||||
<div className="mt-3">
|
||||
<div className="flex justify-between text-xs text-text-secondary mb-1">
|
||||
<span>{progress.label || 'Usage'}</span>
|
||||
<span>{((progress.value / progress.max) * 100).toFixed(0)}%</span>
|
||||
</div>
|
||||
<div className="w-full bg-surface-tertiary rounded-full h-2">
|
||||
<div
|
||||
className="bg-primary-500 h-2 rounded-full transition-all"
|
||||
style={{ width: `${Math.min((progress.value / progress.max) * 100, 100)}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
/**
|
||||
* Proxy Stats Card Component
|
||||
*/
|
||||
|
||||
import type { ProxyStats } from '../types';
|
||||
import { Card, CardHeader, CardContent } from '@/components/ui/Card';
|
||||
import { StatusBadge } from './StatusBadge';
|
||||
import { formatPercentage } from '../utils/formatters';
|
||||
|
||||
interface ProxyStatsCardProps {
|
||||
stats: ProxyStats;
|
||||
}
|
||||
|
||||
export function ProxyStatsCard({ stats }: ProxyStatsCardProps) {
|
||||
const successRate = stats.totalProxies > 0
|
||||
? (stats.workingProxies / stats.totalProxies) * 100
|
||||
: 0;
|
||||
|
||||
const formatDate = (dateString?: string) => {
|
||||
if (!dateString) return 'Never';
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleString();
|
||||
};
|
||||
|
||||
return (
|
||||
<Card className="p-4">
|
||||
<CardHeader className="p-0 pb-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<h2 className="text-base font-semibold text-text-primary">Proxy Status</h2>
|
||||
<StatusBadge
|
||||
variant={stats.enabled ? 'success' : 'default'}
|
||||
size="md"
|
||||
>
|
||||
{stats.enabled ? 'Enabled' : 'Disabled'}
|
||||
</StatusBadge>
|
||||
</div>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent className="p-0">
|
||||
{stats.enabled ? (
|
||||
<div className="space-y-3">
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<p className="text-sm text-text-secondary">Total Proxies</p>
|
||||
<p className="text-xl font-bold text-text-primary">{stats.totalProxies}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm text-text-secondary">Success Rate</p>
|
||||
<p className="text-xl font-bold text-text-primary">{formatPercentage(successRate)}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<p className="text-sm text-text-secondary">Working</p>
|
||||
<p className="text-base font-semibold text-success">{stats.workingProxies}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm text-text-secondary">Failed</p>
|
||||
<p className="text-base font-semibold text-danger">{stats.failedProxies}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="border-t border-border pt-3 space-y-2">
|
||||
<div className="flex justify-between text-sm">
|
||||
<span className="text-text-secondary">Last Update:</span>
|
||||
<span className="font-medium text-text-primary">{formatDate(stats.lastUpdate)}</span>
|
||||
</div>
|
||||
<div className="flex justify-between text-sm">
|
||||
<span className="text-text-secondary">Last Fetch:</span>
|
||||
<span className="font-medium text-text-primary">{formatDate(stats.lastFetchTime)}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{stats.totalProxies === 0 && (
|
||||
<div className="bg-warning/10 border border-warning rounded p-3 text-sm text-warning">
|
||||
No proxies available. Check WebShare API configuration.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-center py-8 text-text-secondary">
|
||||
<p>Proxy service is disabled</p>
|
||||
<p className="text-sm mt-2">Enable it in the configuration to use proxies</p>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
|
@ -2,9 +2,10 @@
|
|||
* Queue Statistics Table Component
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Card } from '../../../components/ui/Card';
|
||||
import type { QueueStats } from '../types';
|
||||
import { Card, CardHeader, CardContent } from '@/components/ui/Card';
|
||||
import { formatNumber } from '../utils/formatters';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface QueueStatsTableProps {
|
||||
queues: QueueStats[];
|
||||
|
|
@ -13,65 +14,91 @@ interface QueueStatsTableProps {
|
|||
export function QueueStatsTable({ queues }: QueueStatsTableProps) {
|
||||
const totalJobs = (queue: QueueStats) => {
|
||||
const { jobs } = queue;
|
||||
return jobs.waiting + jobs.active + jobs.completed + jobs.failed + jobs.delayed + jobs.paused;
|
||||
return jobs.waiting + jobs.active + jobs.completed + jobs.failed + jobs.delayed + jobs.paused +
|
||||
(jobs.prioritized || 0) + (jobs['waiting-children'] || 0);
|
||||
};
|
||||
|
||||
return (
|
||||
<Card className="p-6">
|
||||
<h3 className="text-lg font-semibold mb-4">Queue Statistics</h3>
|
||||
<Card className="p-4">
|
||||
<CardHeader className="p-0 pb-3">
|
||||
<h3 className="text-base font-semibold text-text-primary">Queue Statistics</h3>
|
||||
</CardHeader>
|
||||
|
||||
{queues.length > 0 ? (
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-sm">
|
||||
<thead>
|
||||
<tr className="border-b">
|
||||
<th className="text-left py-2 px-3">Queue</th>
|
||||
<th className="text-center py-2 px-3">Status</th>
|
||||
<th className="text-right py-2 px-3">Waiting</th>
|
||||
<th className="text-right py-2 px-3">Active</th>
|
||||
<th className="text-right py-2 px-3">Completed</th>
|
||||
<th className="text-right py-2 px-3">Failed</th>
|
||||
<th className="text-right py-2 px-3">Delayed</th>
|
||||
<th className="text-right py-2 px-3">Total</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{queues.map((queue) => (
|
||||
<tr key={queue.name} className="border-b hover:bg-gray-50">
|
||||
<td className="py-2 px-3 font-medium">{queue.name}</td>
|
||||
<td className="py-2 px-3 text-center">
|
||||
<span className={`inline-block w-2 h-2 rounded-full ${
|
||||
queue.connected ? 'bg-green-500' : 'bg-red-500'
|
||||
}`} />
|
||||
</td>
|
||||
<td className="py-2 px-3 text-right">{queue.jobs.waiting.toLocaleString()}</td>
|
||||
<td className="py-2 px-3 text-right">
|
||||
{queue.jobs.active > 0 ? (
|
||||
<span className="text-blue-600 font-medium">{queue.jobs.active}</span>
|
||||
) : (
|
||||
queue.jobs.active
|
||||
)}
|
||||
</td>
|
||||
<td className="py-2 px-3 text-right">{queue.jobs.completed.toLocaleString()}</td>
|
||||
<td className="py-2 px-3 text-right">
|
||||
{queue.jobs.failed > 0 ? (
|
||||
<span className="text-red-600 font-medium">{queue.jobs.failed}</span>
|
||||
) : (
|
||||
queue.jobs.failed
|
||||
)}
|
||||
</td>
|
||||
<td className="py-2 px-3 text-right">{queue.jobs.delayed.toLocaleString()}</td>
|
||||
<td className="py-2 px-3 text-right font-medium">{totalJobs(queue).toLocaleString()}</td>
|
||||
<CardContent className="p-0">
|
||||
{queues.length > 0 ? (
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-xs">
|
||||
<thead>
|
||||
<tr className="border-b border-border">
|
||||
<th className="text-left py-2 px-3 text-text-secondary font-medium">Queue</th>
|
||||
<th className="text-center py-2 px-3 text-text-secondary font-medium">Status</th>
|
||||
<th className="text-right py-2 px-3 text-text-secondary font-medium">Waiting</th>
|
||||
<th className="text-right py-2 px-3 text-text-secondary font-medium">Active</th>
|
||||
<th className="text-right py-2 px-3 text-text-secondary font-medium">Completed</th>
|
||||
<th className="text-right py-2 px-3 text-text-secondary font-medium">Failed</th>
|
||||
<th className="text-right py-2 px-3 text-text-secondary font-medium">Delayed</th>
|
||||
<th className="text-right py-2 px-3 text-text-secondary font-medium">Prioritized</th>
|
||||
<th className="text-right py-2 px-3 text-text-secondary font-medium">Children</th>
|
||||
<th className="text-right py-2 px-3 text-text-secondary font-medium">Workers</th>
|
||||
<th className="text-right py-2 px-3 text-text-secondary font-medium">Total</th>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-center py-8 text-gray-500">
|
||||
No queue data available
|
||||
</div>
|
||||
)}
|
||||
</thead>
|
||||
<tbody>
|
||||
{queues.map((queue) => (
|
||||
<tr key={queue.name} className="border-b border-border hover:bg-surface-tertiary/50 transition-colors">
|
||||
<td className="py-2 px-3 font-medium text-text-primary">{queue.name}</td>
|
||||
<td className="py-2 px-3 text-center">
|
||||
<span className={cn(
|
||||
'inline-block w-2 h-2 rounded-full',
|
||||
queue.connected ? 'bg-success' : 'bg-danger'
|
||||
)} />
|
||||
</td>
|
||||
<td className="py-2 px-3 text-right text-text-primary">{formatNumber(queue.jobs.waiting)}</td>
|
||||
<td className="py-2 px-3 text-right">
|
||||
{queue.jobs.active > 0 ? (
|
||||
<span className="text-primary-400 font-medium">{formatNumber(queue.jobs.active)}</span>
|
||||
) : (
|
||||
<span className="text-text-primary">{queue.jobs.active}</span>
|
||||
)}
|
||||
</td>
|
||||
<td className="py-2 px-3 text-right text-text-primary">{formatNumber(queue.jobs.completed)}</td>
|
||||
<td className="py-2 px-3 text-right">
|
||||
{queue.jobs.failed > 0 ? (
|
||||
<span className="text-danger font-medium">{formatNumber(queue.jobs.failed)}</span>
|
||||
) : (
|
||||
<span className="text-text-primary">{queue.jobs.failed}</span>
|
||||
)}
|
||||
</td>
|
||||
<td className="py-2 px-3 text-right text-text-primary">{formatNumber(queue.jobs.delayed)}</td>
|
||||
<td className="py-2 px-3 text-right">
|
||||
{queue.jobs.prioritized && queue.jobs.prioritized > 0 ? (
|
||||
<span className="text-primary-300 font-medium">{formatNumber(queue.jobs.prioritized)}</span>
|
||||
) : (
|
||||
<span className="text-text-primary">0</span>
|
||||
)}
|
||||
</td>
|
||||
<td className="py-2 px-3 text-right">
|
||||
{queue.jobs['waiting-children'] && queue.jobs['waiting-children'] > 0 ? (
|
||||
<span className="text-warning font-medium">{formatNumber(queue.jobs['waiting-children'])}</span>
|
||||
) : (
|
||||
<span className="text-text-primary">0</span>
|
||||
)}
|
||||
</td>
|
||||
<td className="py-2 px-3 text-right text-text-primary">
|
||||
{queue.workers ? `${queue.workers.count}/${queue.workers.concurrency}` : '-'}
|
||||
</td>
|
||||
<td className="py-2 px-3 text-right font-medium text-text-primary">{formatNumber(totalJobs(queue))}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-center py-6 text-text-secondary text-sm">
|
||||
No queue data available
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
import { Card, CardHeader, CardContent } from '@/components/ui/Card';
|
||||
import { ServiceStatusIndicator, HealthStatus } from './StatusBadge';
|
||||
import { formatUptime } from '../utils/formatters';
|
||||
import type { ServiceStatus } from '../types';
|
||||
|
||||
interface ServiceCardProps {
|
||||
service: ServiceStatus;
|
||||
}
|
||||
|
||||
export function ServiceCard({ service }: ServiceCardProps) {
|
||||
return (
|
||||
<Card className="p-3">
|
||||
<CardHeader className="p-0 pb-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="font-semibold text-sm capitalize text-text-primary">
|
||||
{service.name.replace(/-/g, ' ')}
|
||||
</h3>
|
||||
<ServiceStatusIndicator status={service.status} />
|
||||
</div>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent className="p-0 space-y-1.5 text-xs">
|
||||
<div className="flex justify-between">
|
||||
<span className="text-text-secondary">Status:</span>
|
||||
<span className="font-medium capitalize text-text-primary">{service.status}</span>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-between">
|
||||
<span className="text-text-secondary">Port:</span>
|
||||
<span className="font-medium text-text-primary">{service.port || 'N/A'}</span>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-between">
|
||||
<span className="text-text-secondary">Version:</span>
|
||||
<span className="font-medium text-text-primary">{service.version}</span>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-between">
|
||||
<span className="text-text-secondary">Uptime:</span>
|
||||
<span className="font-medium text-text-primary">{formatUptime(service.uptime)}</span>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-between items-center">
|
||||
<span className="text-text-secondary">Health:</span>
|
||||
<HealthStatus healthy={service.healthy} />
|
||||
</div>
|
||||
|
||||
{service.error && (
|
||||
<div className="mt-2 text-xs text-danger bg-danger/10 p-2 rounded">
|
||||
Error: {service.error}
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
/**
|
||||
* Service Status Grid Component
|
||||
*/
|
||||
|
||||
import type { ServiceStatus } from '../types';
|
||||
import { ServiceCard } from './ServiceCard';
|
||||
|
||||
interface ServiceStatusGridProps {
|
||||
services: ServiceStatus[];
|
||||
}
|
||||
|
||||
export function ServiceStatusGrid({ services }: ServiceStatusGridProps) {
|
||||
return (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3">
|
||||
{services.map((service) => (
|
||||
<ServiceCard key={service.name} service={service} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
import { cn } from '@/lib/utils';
|
||||
|
||||
type BadgeVariant = 'success' | 'danger' | 'warning' | 'default';
|
||||
|
||||
interface StatusBadgeProps {
|
||||
children: React.ReactNode;
|
||||
variant?: BadgeVariant;
|
||||
className?: string;
|
||||
size?: 'sm' | 'md';
|
||||
}
|
||||
|
||||
const variantStyles: Record<BadgeVariant, string> = {
|
||||
success: 'text-success bg-success/10',
|
||||
danger: 'text-danger bg-danger/10',
|
||||
warning: 'text-warning bg-warning/10',
|
||||
default: 'text-text-secondary bg-text-secondary/10',
|
||||
};
|
||||
|
||||
const sizeStyles = {
|
||||
sm: 'px-2 py-0.5 text-xs',
|
||||
md: 'px-3 py-1 text-sm',
|
||||
};
|
||||
|
||||
export function StatusBadge({
|
||||
children,
|
||||
variant = 'default',
|
||||
className,
|
||||
size = 'sm'
|
||||
}: StatusBadgeProps) {
|
||||
return (
|
||||
<span className={cn(
|
||||
'rounded-full font-medium',
|
||||
variantStyles[variant],
|
||||
sizeStyles[size],
|
||||
className
|
||||
)}>
|
||||
{children}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
interface ConnectionStatusProps {
|
||||
connected: boolean;
|
||||
size?: 'sm' | 'md';
|
||||
}
|
||||
|
||||
export function ConnectionStatus({ connected, size = 'sm' }: ConnectionStatusProps) {
|
||||
return (
|
||||
<StatusBadge variant={connected ? 'success' : 'danger'} size={size}>
|
||||
{connected ? 'Connected' : 'Disconnected'}
|
||||
</StatusBadge>
|
||||
);
|
||||
}
|
||||
|
||||
interface HealthStatusProps {
|
||||
healthy: boolean;
|
||||
size?: 'sm' | 'md';
|
||||
}
|
||||
|
||||
export function HealthStatus({ healthy, size = 'sm' }: HealthStatusProps) {
|
||||
return (
|
||||
<StatusBadge variant={healthy ? 'success' : 'danger'} size={size}>
|
||||
{healthy ? 'Healthy' : 'Unhealthy'}
|
||||
</StatusBadge>
|
||||
);
|
||||
}
|
||||
|
||||
interface ServiceStatusIndicatorProps {
|
||||
status: 'running' | 'stopped' | 'error';
|
||||
}
|
||||
|
||||
export function ServiceStatusIndicator({ status }: ServiceStatusIndicatorProps) {
|
||||
const statusColors = {
|
||||
running: 'bg-success',
|
||||
stopped: 'bg-text-muted',
|
||||
error: 'bg-danger',
|
||||
};
|
||||
|
||||
return <div className={cn('w-3 h-3 rounded-full', statusColors[status])} />;
|
||||
}
|
||||
|
|
@ -2,75 +2,88 @@
|
|||
* System Health Card Component
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Card } from '../../../components/ui/Card';
|
||||
import type { SystemHealth } from '../types';
|
||||
import { Card, CardHeader, CardContent } from '@/components/ui/Card';
|
||||
import { StatusBadge } from './StatusBadge';
|
||||
import { formatUptime, formatBytes, formatPercentage } from '../utils/formatters';
|
||||
|
||||
interface SystemHealthCardProps {
|
||||
health: SystemHealth;
|
||||
}
|
||||
|
||||
export function SystemHealthCard({ health }: SystemHealthCardProps) {
|
||||
const statusColor = {
|
||||
healthy: 'text-green-600 bg-green-100',
|
||||
degraded: 'text-yellow-600 bg-yellow-100',
|
||||
unhealthy: 'text-red-600 bg-red-100',
|
||||
const statusVariant = {
|
||||
healthy: 'success' as const,
|
||||
degraded: 'warning' as const,
|
||||
unhealthy: 'danger' as const,
|
||||
}[health.status];
|
||||
|
||||
const formatUptime = (ms: number) => {
|
||||
const seconds = Math.floor(ms / 1000);
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
const hours = Math.floor(minutes / 60);
|
||||
const days = Math.floor(hours / 24);
|
||||
|
||||
if (days > 0) return `${days}d ${hours % 24}h`;
|
||||
if (hours > 0) return `${hours}h ${minutes % 60}m`;
|
||||
if (minutes > 0) return `${minutes}m ${seconds % 60}s`;
|
||||
return `${seconds}s`;
|
||||
};
|
||||
|
||||
const formatBytes = (bytes: number) => {
|
||||
const gb = bytes / 1024 / 1024 / 1024;
|
||||
return gb.toFixed(2) + ' GB';
|
||||
};
|
||||
|
||||
return (
|
||||
<Card className="p-6">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<h3 className="text-lg font-semibold">System Health</h3>
|
||||
<span className={`px-3 py-1 rounded-full text-sm font-medium ${statusColor}`}>
|
||||
{health.status.toUpperCase()}
|
||||
</span>
|
||||
</div>
|
||||
<Card className="p-4">
|
||||
<CardHeader className="p-0 pb-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-base font-semibold text-text-primary">System Health</h3>
|
||||
<StatusBadge variant={statusVariant} size="md">
|
||||
{health.status.toUpperCase()}
|
||||
</StatusBadge>
|
||||
</div>
|
||||
</CardHeader>
|
||||
|
||||
<div className="space-y-4">
|
||||
<CardContent className="p-0 space-y-3">
|
||||
<div>
|
||||
<div className="text-sm text-gray-600">Uptime</div>
|
||||
<div className="text-2xl font-semibold">{formatUptime(health.uptime)}</div>
|
||||
<div className="text-sm text-text-secondary">Uptime</div>
|
||||
<div className="text-xl font-semibold text-text-primary">{formatUptime(health.uptime)}</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div className="text-sm text-gray-600">Memory Usage</div>
|
||||
<div className="text-sm text-text-secondary">System Memory</div>
|
||||
<div className="mt-1">
|
||||
<div className="flex justify-between text-sm">
|
||||
<div className="flex justify-between text-sm text-text-primary">
|
||||
<span>{formatBytes(health.memory.used)} / {formatBytes(health.memory.total)}</span>
|
||||
<span>{health.memory.percentage.toFixed(1)}%</span>
|
||||
<span>{formatPercentage(health.memory.percentage)}</span>
|
||||
</div>
|
||||
<div className="mt-1 w-full bg-gray-200 rounded-full h-2">
|
||||
<div className="mt-1 w-full bg-surface-tertiary rounded-full h-2">
|
||||
<div
|
||||
className="bg-blue-600 h-2 rounded-full"
|
||||
style={{ width: `${health.memory.percentage}%` }}
|
||||
className="bg-primary-500 h-2 rounded-full transition-all"
|
||||
style={{ width: `${Math.min(health.memory.percentage, 100)}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{health.memory.available !== undefined && (
|
||||
<div className="mt-2 text-xs text-text-muted">
|
||||
Available: {formatBytes(health.memory.available)} (excludes cache/buffers)
|
||||
</div>
|
||||
)}
|
||||
{health.memory.heap && (
|
||||
<div className="mt-1 text-xs text-text-muted">
|
||||
Node.js Heap: {formatBytes(health.memory.heap.used)} / {formatBytes(health.memory.heap.total)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{health.cpu && (
|
||||
<div>
|
||||
<div className="text-sm text-text-secondary">CPU Usage</div>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="text-lg font-semibold text-text-primary">{health.cpu.usage}%</div>
|
||||
{health.cpu.cores && (
|
||||
<span className="text-sm text-text-secondary">{health.cpu.cores} cores</span>
|
||||
)}
|
||||
</div>
|
||||
{health.cpu.loadAverage && (
|
||||
<div className="text-xs text-text-muted mt-1">
|
||||
Load: {health.cpu.loadAverage.map(l => l.toFixed(2)).join(', ')}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{health.errors && health.errors.length > 0 && (
|
||||
<div>
|
||||
<div className="text-sm text-gray-600 mb-2">Issues</div>
|
||||
<div className="text-sm text-text-secondary mb-2">Issues</div>
|
||||
<ul className="space-y-1">
|
||||
{health.errors.map((error, index) => (
|
||||
<li key={index} className="text-sm text-red-600">
|
||||
<li key={index} className="text-sm text-danger">
|
||||
• {error}
|
||||
</li>
|
||||
))}
|
||||
|
|
@ -78,10 +91,10 @@ export function SystemHealthCard({ health }: SystemHealthCardProps) {
|
|||
</div>
|
||||
)}
|
||||
|
||||
<div className="text-xs text-gray-500">
|
||||
<div className="text-xs text-text-muted">
|
||||
Last updated: {new Date(health.timestamp).toLocaleTimeString()}
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
|
@ -5,4 +5,10 @@
|
|||
export { SystemHealthCard } from './SystemHealthCard';
|
||||
export { CacheStatsCard } from './CacheStatsCard';
|
||||
export { QueueStatsTable } from './QueueStatsTable';
|
||||
export { DatabaseStatsGrid } from './DatabaseStatsGrid';
|
||||
export { DatabaseStatsGrid } from './DatabaseStatsGrid';
|
||||
export { ServiceStatusGrid } from './ServiceStatusGrid';
|
||||
export { ProxyStatsCard } from './ProxyStatsCard';
|
||||
export { StatusBadge, ConnectionStatus, HealthStatus, ServiceStatusIndicator } from './StatusBadge';
|
||||
export { MetricCard } from './MetricCard';
|
||||
export { ServiceCard } from './ServiceCard';
|
||||
export { DatabaseCard } from './DatabaseCard';
|
||||
Loading…
Add table
Add a link
Reference in a new issue