diff --git a/apps/web/app/ai-metrics/components/chart.tsx b/apps/web/app/ai-metrics/components/chart.tsx index da3aff4..9f9af91 100644 --- a/apps/web/app/ai-metrics/components/chart.tsx +++ b/apps/web/app/ai-metrics/components/chart.tsx @@ -9,6 +9,7 @@ import { ResponsiveContainer, XAxis, YAxis, + Cell, } from "recharts"; import { @@ -17,6 +18,8 @@ import { ChartTooltipContent, } from "@/components/ui/chart"; +import { getGradient } from "@/lib/utils"; + interface CombinedMetricsChartProps { data: Array<{ name: string; @@ -31,6 +34,24 @@ export function CombinedMetricsChart({ data }: CombinedMetricsChartProps) { const formatLatency = (value: number) => `${value.toLocaleString()}ms`; const formatTokens = (value: number) => `${value.toLocaleString()}`; + const barColors = [ + "#FF6B6B", // Coral Red + "#4ECDC4", // Turquoise + "#45B7D1", // Sky Blue + "#96CEB4", // Sage Green + "#FFEEAD", // Cream Yellow + "#D4A5A5", // Dusty Rose + "#9B5DE5", // Purple + "#F15BB5", // Pink + "#00BBF9", // Bright Blue + "#00F5D4", // Mint + "#FEE440", // Yellow + "#FF99C8", // Light Pink + "#A8E6CF", // Mint Green + "#FFB3BA", // Light Red + "#BFCFF7", // Lavender + ]; + return ( - + } - cursor={{ fill: "rgba(0, 0, 0, 0.1)" }} + cursor={{ fill: "rgba(255, 255, 255, 0.1)" }} /> + opacity={0.9} + > + {data.map((entry, index) => ( + + ))} + diff --git a/apps/web/app/ai-metrics/components/dashboard.tsx b/apps/web/app/ai-metrics/components/dashboard.tsx index ccfd2a5..3177125 100644 --- a/apps/web/app/ai-metrics/components/dashboard.tsx +++ b/apps/web/app/ai-metrics/components/dashboard.tsx @@ -37,6 +37,22 @@ const parseMetadata = (metadataString: string) => { export function MetricsDashboard({ metrics }: { metrics: Metric[] }) { const [selectedMetric, setSelectedMetric] = useState(null); + const totalRequests = metrics.length; + const totalTokens = metrics.reduce((sum, metric) => { + const metadata = parseMetadata(metric.metadata); + return sum + (metadata.tokenUsage?.total_tokens || 0); + }, 0); + const totalCost = metrics.reduce((sum, metric) => { + const metadata = parseMetadata(metric.metadata); + return sum + (metadata.cost || 0); + }, 0); + const cachedRequests = metrics.filter((m) => { + const metadata = parseMetadata(m.metadata); + return metadata.cached === "true"; + }).length; + const cachedPercentage = ((cachedRequests / totalRequests) * 100).toFixed(2); + const errorRequests = metrics.filter((m) => m.status === "error").length; + const combinedChartData = metrics.map((metric) => { const metadata = parseMetadata(metric.metadata); const tokenUsage = metadata.tokenUsage || {}; @@ -50,65 +66,121 @@ export function MetricsDashboard({ metrics }: { metrics: Metric[] }) { }); return ( -
- - - AI Provider Metrics - - Latency and token usage for different AI providers and models - - - - - - +
+
+ + + + Requests + + + {totalRequests} + + + + + + + Tokens + + + {(totalTokens / 1000).toFixed(1)}k + + + + + + + Cost + + + ${totalCost.toFixed(2)} + + + + + + + Cached + + + {cachedPercentage}% + + + + + + + Errors + + + {errorRequests} + + + +
+ +
+ + + AI Provider Metrics + + Latency and token usage for different AI providers and models + + + + + + + + + + Metrics Details + + Detailed information for each metric entry + + + + +
+ + + + Provider (Model) + Latency (ms) + Total Tokens + Status + Timestamp + + + + {metrics.map((metric) => { + const metadata = parseMetadata(metric.metadata); + const tokenUsage = metadata.tokenUsage || {}; + return ( + setSelectedMetric(metric)} + > + {`${metadata.provider} (${metadata.model})`} + {metric.value} + + {tokenUsage.total_tokens || "N/A"} + + {metric.status} + {metric.timestamp} + + ); + })} + +
+
+
+
+
+
- - - Metrics Details - - Detailed information for each metric entry - - - - -
- - - - Provider (Model) - Latency (ms) - Total Tokens - Status - Timestamp - - - - {metrics.map((metric) => { - const metadata = parseMetadata(metric.metadata); - const tokenUsage = metadata.tokenUsage || {}; - return ( - setSelectedMetric(metric)} - > - {`${metadata.provider} (${metadata.model})`} - {metric.value} - - {tokenUsage.total_tokens || "N/A"} - - {metric.status} - {metric.timestamp} - - ); - })} - -
-
-
-
-
{selectedMetric && (