Skip to content

Commit 65b6bd6

Browse files
add filters for metrics
1 parent 8be91b6 commit 65b6bd6

File tree

3 files changed

+342
-171
lines changed

3 files changed

+342
-171
lines changed

app/app/metrics/page.tsx

Lines changed: 10 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,17 @@ import {
88
ClockIcon,
99
HeartIcon,
1010
HardDriveIcon,
11-
InfoIcon,
1211
ChartSplineIcon,
1312
ServerCrashIcon,
1413
} from "lucide-react";
15-
import { Area, AreaChart, Line, LineChart, XAxis, YAxis } from "recharts";
16-
import {
17-
type ChartConfig,
18-
ChartContainer,
19-
ChartTooltip,
20-
ChartTooltipContent,
21-
} from "@/components/ui/chart";
2214
import { Badge } from "@/components/ui/badge";
2315
import { ScrollArea } from "@/components/ui/scroll-area";
2416
import { MetricCard } from "@/components/ui/metric-card";
2517
import { Spinner } from "@/components/ui/spinner";
18+
import { GaugeChart } from "@/components/metrics/gauge-chart";
2619
import dayjs from "dayjs";
2720
import relativeTime from "dayjs/plugin/relativeTime";
28-
import {
29-
parseBytes,
30-
formatUptime,
31-
getFormatter,
32-
processGaugeData,
33-
} from "@/lib/utils";
21+
import { parseBytes, formatUptime } from "@/lib/utils";
3422

3523
dayjs.extend(relativeTime);
3624

@@ -162,145 +150,14 @@ export default function MetricsPage() {
162150
TiKV Overview
163151
</div>
164152
<div className="grid gap-4 pb-30 grid-cols-1 md:grid-cols-3 3xl:grid-cols-4 ">
165-
{data?.tikv?.gauges.map((gauge: any, i: number) => {
166-
const { data: chartData, series } = processGaugeData(
167-
gauge.points
168-
);
169-
170-
const formatter = getFormatter(gauge.unit);
171-
172-
const dynamicConfig: ChartConfig = {
173-
...series.reduce((acc, key, index) => {
174-
const colorVar = `--chart-${(index % 5) + 1}`;
175-
acc[key] = {
176-
label: key,
177-
color: `var(${colorVar})`,
178-
};
179-
return acc;
180-
}, {} as Record<string, { label: string; color: string }>),
181-
};
182-
183-
return (
184-
<MetricCard key={gauge.name + i}>
185-
<div className="font-semibold text-gray-500 mb-10 flex items-center justify-between">
186-
<span>{gauge.name}</span>
187-
</div>
188-
<ChartContainer config={dynamicConfig}>
189-
{series.length > 1 ? (
190-
<LineChart data={chartData}>
191-
<ChartTooltip
192-
content={
193-
<ChartTooltipContent
194-
formatter={(value, name, item) => (
195-
<div className="flex flex-1 justify-between items-center gap-4">
196-
<div className="flex items-center gap-2">
197-
<div
198-
className="h-2.5 w-2.5 shrink-0 rounded-[2px]"
199-
style={{ backgroundColor: item.color }}
200-
/>
201-
<span className="text-muted-foreground truncate max-w-[150px]">
202-
{name}
203-
</span>
204-
</div>
205-
<span className="font-mono font-medium">
206-
{formatter(value as number)}
207-
</span>
208-
</div>
209-
)}
210-
/>
211-
}
212-
/>
213-
<XAxis
214-
dataKey="ts"
215-
tickFormatter={(value) =>
216-
dayjs(value).format("HH:mm")
217-
}
218-
/>
219-
<YAxis tickFormatter={formatter} width={70} />
220-
{series.slice(0, 10).map((key) => (
221-
<Line
222-
key={key}
223-
dataKey={key}
224-
type="monotone"
225-
stroke={dynamicConfig[key]?.color}
226-
strokeWidth={2}
227-
dot={false}
228-
/>
229-
))}
230-
</LineChart>
231-
) : (
232-
<AreaChart data={chartData}>
233-
<ChartTooltip
234-
content={
235-
<ChartTooltipContent
236-
formatter={(value, name, item) => (
237-
<div className="flex flex-1 justify-between items-center gap-4">
238-
<div className="flex items-center gap-2">
239-
<div
240-
className="h-2.5 w-2.5 shrink-0 rounded-[2px]"
241-
style={{ backgroundColor: item.color }}
242-
/>
243-
<span className="text-muted-foreground truncate max-w-[150px]">
244-
{name}
245-
</span>
246-
</div>
247-
<span className="font-mono font-medium">
248-
{formatter(value as number)}
249-
</span>
250-
</div>
251-
)}
252-
/>
253-
}
254-
/>
255-
<XAxis
256-
dataKey="ts"
257-
tickFormatter={(value) =>
258-
dayjs(value).format("HH:mm")
259-
}
260-
/>
261-
<YAxis tickFormatter={formatter} width={70} />
262-
<defs>
263-
{series.map((key, index) => (
264-
<linearGradient
265-
key={key}
266-
id={`gradient-${i}-${index}`}
267-
x1="0"
268-
y1="0"
269-
x2="0"
270-
y2="1"
271-
>
272-
<stop
273-
offset="5%"
274-
stopColor={dynamicConfig[key]?.color}
275-
stopOpacity={0.5}
276-
/>
277-
<stop
278-
offset="95%"
279-
stopColor={dynamicConfig[key]?.color}
280-
stopOpacity={0.1}
281-
/>
282-
</linearGradient>
283-
))}
284-
</defs>
285-
{series.map((key, index) => (
286-
<Area
287-
key={key}
288-
dataKey={key}
289-
type="basis"
290-
fill={`url(#gradient-${i}-${index})`}
291-
fillOpacity={0.2}
292-
stroke={dynamicConfig[key]?.color}
293-
/>
294-
))}
295-
</AreaChart>
296-
)}
297-
</ChartContainer>
298-
<div className="text-xs text-gray-600 flex items-center gap-1">
299-
<InfoIcon size={12} /> {gauge.description}
300-
</div>
301-
</MetricCard>
302-
);
303-
})}
153+
{data?.tikv?.gauges.map((gauge: any, i: number) => (
154+
<GaugeChart
155+
key={gauge.name + i}
156+
gauge={gauge}
157+
index={i}
158+
stores={data?.pd?.stores || []}
159+
/>
160+
))}
304161
</div>
305162
</ScrollArea>
306163
)}

0 commit comments

Comments
 (0)