feat: add cache hit rate line to token usage trend chart
Add a purple dashed line showing cache hit rate percentage (cache_read / (cache_read + cache_creation)) on a secondary right Y-axis (0-100%). Applies to both user and admin dashboards.
This commit is contained in:
@@ -64,7 +64,8 @@ const chartColors = computed(() => ({
|
|||||||
input: '#3b82f6',
|
input: '#3b82f6',
|
||||||
output: '#10b981',
|
output: '#10b981',
|
||||||
cacheCreation: '#f59e0b',
|
cacheCreation: '#f59e0b',
|
||||||
cacheRead: '#06b6d4'
|
cacheRead: '#06b6d4',
|
||||||
|
cacheHitRate: '#8b5cf6'
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const chartData = computed(() => {
|
const chartData = computed(() => {
|
||||||
@@ -104,6 +105,19 @@ const chartData = computed(() => {
|
|||||||
backgroundColor: `${chartColors.value.cacheRead}20`,
|
backgroundColor: `${chartColors.value.cacheRead}20`,
|
||||||
fill: true,
|
fill: true,
|
||||||
tension: 0.3
|
tension: 0.3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Cache Hit Rate',
|
||||||
|
data: props.trendData.map((d) => {
|
||||||
|
const total = d.cache_read_tokens + d.cache_creation_tokens
|
||||||
|
return total > 0 ? (d.cache_read_tokens / total) * 100 : 0
|
||||||
|
}),
|
||||||
|
borderColor: chartColors.value.cacheHitRate,
|
||||||
|
backgroundColor: `${chartColors.value.cacheHitRate}20`,
|
||||||
|
borderDash: [5, 5],
|
||||||
|
fill: false,
|
||||||
|
tension: 0.3,
|
||||||
|
yAxisID: 'yPercent'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -132,6 +146,9 @@ const lineOptions = computed(() => ({
|
|||||||
tooltip: {
|
tooltip: {
|
||||||
callbacks: {
|
callbacks: {
|
||||||
label: (context: any) => {
|
label: (context: any) => {
|
||||||
|
if (context.dataset.yAxisID === 'yPercent') {
|
||||||
|
return `${context.dataset.label}: ${context.raw.toFixed(1)}%`
|
||||||
|
}
|
||||||
return `${context.dataset.label}: ${formatTokens(context.raw)}`
|
return `${context.dataset.label}: ${formatTokens(context.raw)}`
|
||||||
},
|
},
|
||||||
footer: (tooltipItems: any) => {
|
footer: (tooltipItems: any) => {
|
||||||
@@ -168,6 +185,21 @@ const lineOptions = computed(() => ({
|
|||||||
},
|
},
|
||||||
callback: (value: string | number) => formatTokens(Number(value))
|
callback: (value: string | number) => formatTokens(Number(value))
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
yPercent: {
|
||||||
|
position: 'right' as const,
|
||||||
|
min: 0,
|
||||||
|
max: 100,
|
||||||
|
grid: {
|
||||||
|
drawOnChartArea: false
|
||||||
|
},
|
||||||
|
ticks: {
|
||||||
|
color: chartColors.value.cacheHitRate,
|
||||||
|
font: {
|
||||||
|
size: 10
|
||||||
|
},
|
||||||
|
callback: (value: string | number) => `${value}%`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
|||||||
Reference in New Issue
Block a user