Skip to content

Commit b209397

Browse files
authored
Merge pull request #241 from duyet/chore/ui
feat: add zookeeper current metrics
2 parents e16e600 + 84d469a commit b209397

File tree

6 files changed

+121
-3
lines changed

6 files changed

+121
-3
lines changed

app/[query]/more/zookeeper.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,8 @@ export const zookeeperConfig: QueryConfig = {
5454
lastHours: 24 * 7,
5555
},
5656
],
57+
'break',
58+
'zookeeper-uptime',
59+
'zookeeper-summary-table',
5760
],
5861
}

app/[query]/tables/replication-queue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const replicationQueueConfig: QueryConfig = {
99
database || '.' || table as table
1010
FROM system.replication_queue
1111
ORDER BY is_currently_executing DESC, create_time DESC
12-
LIMIT 5000
12+
LIMIT 1000
1313
`,
1414
columns: [
1515
'table',

components/charts/replication-summary-table.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export async function ChartReplicationSummaryTable({
2222
COUNT() as total
2323
FROM system.replication_queue
2424
GROUP BY 1, 2
25+
ORDER BY total DESC
2526
`
2627
const data = await fetchData<
2728
{
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { ChartCard } from '@/components/chart-card'
2+
import { type ChartProps } from '@/components/charts/chart-props'
3+
import {
4+
Table,
5+
TableBody,
6+
TableCell,
7+
TableHead,
8+
TableHeader,
9+
TableRow,
10+
} from '@/components/ui/table'
11+
import { fetchData } from '@/lib/clickhouse'
12+
import { cn } from '@/lib/utils'
13+
14+
export async function ChartZookeeperSummaryTable({
15+
title = 'ZooKeeper Current Metrics',
16+
className,
17+
}: ChartProps) {
18+
const query = `
19+
SELECT metric, value, description
20+
FROM system.metrics
21+
WHERE metric LIKE 'ZooKeeper%'
22+
`
23+
const data = await fetchData<
24+
{
25+
metric: string
26+
value: string
27+
desc: string
28+
}[]
29+
>({ query })
30+
31+
const headers = Object.keys(data?.[0] || {})
32+
33+
return (
34+
<ChartCard
35+
title={title}
36+
className={cn('justify-between', className)}
37+
sql={query}
38+
>
39+
<div className="flex flex-col justify-between p-0">
40+
<Table className={className}>
41+
<TableHeader>
42+
<TableRow>
43+
{headers.map((header) => (
44+
<TableHead key={header}>{header}</TableHead>
45+
))}
46+
</TableRow>
47+
</TableHeader>
48+
<TableBody>
49+
{data.map((row, idx) => (
50+
<TableRow key={idx}>
51+
{Object.values(row).map((value, i) => {
52+
return <TableCell key={i}>{value || ''} </TableCell>
53+
})}
54+
</TableRow>
55+
))}
56+
</TableBody>
57+
</Table>
58+
</div>
59+
</ChartCard>
60+
)
61+
}
62+
63+
export default ChartZookeeperSummaryTable
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { ChartCard } from '@/components/chart-card'
2+
import { type ChartProps } from '@/components/charts/chart-props'
3+
import { fetchData } from '@/lib/clickhouse'
4+
import { cn } from '@/lib/utils'
5+
6+
import { CardMultiMetrics } from '../tremor/card-multi-metrics'
7+
8+
export async function ChartZookeeperUptime({
9+
title = 'Zookeeper Uptime',
10+
className,
11+
}: ChartProps) {
12+
const query =
13+
'SELECT formatReadableTimeDelta(zookeeperSessionUptime()) AS uptime'
14+
15+
const rows = await fetchData<
16+
{
17+
uptime: string
18+
}[]
19+
>({ query })
20+
21+
const uptime = rows[0] || { uptime: 'N/A' }
22+
23+
return (
24+
<ChartCard
25+
title={title}
26+
className={cn('justify-between', className)}
27+
sql={query}
28+
>
29+
<div className="flex flex-col justify-between p-0">
30+
<CardMultiMetrics
31+
primary={
32+
<span className="flex flex-row items-center gap-2">
33+
{uptime.uptime}
34+
</span>
35+
}
36+
items={[]}
37+
className="p-2"
38+
/>
39+
<div className="pl-2 text-sm text-muted-foreground"></div>
40+
</div>
41+
</ChartCard>
42+
)
43+
}
44+
45+
export default ChartZookeeperUptime

components/related-charts.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export async function RelatedCharts({
5050

5151
return (
5252
<div className={cn('mb-5 grid gap-5', gridCols, className)}>
53-
{charts.map(([_name, Chart, props], i) => {
53+
{charts.map(([name, Chart, props], i) => {
5454
let className = ''
5555

5656
// If next chart is a break, add a 'col-span-2' class to the current chart
@@ -61,6 +61,9 @@ export async function RelatedCharts({
6161
// | chart2 | chart3 |
6262
// -----------------------
6363
if (charts[i + 1] && charts[i + 1][0] === 'break') {
64+
console.debug(
65+
`${name} add col-span-2 due to next chart being a break`
66+
)
6467
className = 'col-span-2'
6568
}
6669

@@ -73,7 +76,10 @@ export async function RelatedCharts({
7376
// | chart3 |
7477
// -----------------------
7578
if (charts.length > 2 && i === charts.length - 1 && col === 2) {
76-
className = 'col-span-2'
79+
className = 'auto-cols-max'
80+
console.debug(
81+
`${name} add classname ${className} due to this chart is at the end of the row`
82+
)
7783
}
7884

7985
return (

0 commit comments

Comments
 (0)