Skip to content

Commit

Permalink
Fancy clusters page (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
fuziontech authored Aug 15, 2023
1 parent f657354 commit da57178
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 10 deletions.
47 changes: 39 additions & 8 deletions frontend/src/pages/Clusters/Clusters.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
import React, { useEffect, useState } from 'react'
import { Line } from '@ant-design/charts'
import { Card, Col, Row, Tooltip, notification } from 'antd'
import { InfoCircleOutlined } from '@ant-design/icons'
import { ColumnType } from 'antd/es/table'
import { Table, Col, Row, Tooltip, notification } from 'antd'

interface ClusterNode {
cluster: string
shard_num: number
shard_weight: number
replica_num: number
host_name: string
host_address: string
port: number
is_local: boolean
user: string
default_database: string
errors_count: number
slowdowns_count: number
estimated_recovery_time: number
}

interface Cluster {
cluster: string
nodes: ClusterNode[]
}

interface Clusters {
Expand All @@ -15,6 +31,7 @@ export default function Clusters() {
const [clusters, setClusters] = useState<Clusters>({
clusters: [],
})
const [loadingClusters, setLoadingClusters] = useState(false)

const loadData = async () => {
try {
Expand All @@ -31,10 +48,21 @@ export default function Clusters() {
loadData()
}, [])

const now = new Date()
const dayOfTheYear = Math.floor(
(now.getTime() - new Date(now.getFullYear(), 0, 0).getTime()) / (1000 * 60 * 60 * 24)
)
const columns: ColumnType<ClusterNode>[] = [
{ title: 'Cluster', dataIndex: 'cluster' },
{ title: 'Shard Number', dataIndex: 'shard_num' },
{ title: 'Shard Weight', dataIndex: 'shard_weight' },
{ title: 'Replica Number', dataIndex: 'replica_num' },
{ title: 'Host Name', dataIndex: 'host_name' },
{ title: 'Host Address', dataIndex: 'host_address' },
{ title: 'Port', dataIndex: 'port' },
{ title: 'Is Local', dataIndex: 'is_local' },
{ title: 'User', dataIndex: 'user' },
{ title: 'Default Database', dataIndex: 'default_database' },
{ title: 'Errors Count', dataIndex: 'errors_count' },
{ title: 'Slowdowns Count', dataIndex: 'slowdowns_count' },
{ title: 'Recovery Time', dataIndex: 'estimated_recovery_time' },
]

return (
<div>
Expand All @@ -43,7 +71,10 @@ export default function Clusters() {
<Row gutter={8} style={{ paddingBottom: 8 }}>
<ul>
{clusters.clusters.map((cluster) => (
<li key={cluster.cluster}>{cluster.cluster}</li>
<>
<h1 key={cluster.cluster}>{cluster.cluster}</h1>
<Table columns={columns} dataSource={cluster.nodes} loading={loadingClusters} />
</>
))}
</ul>
</Row>
Expand Down
12 changes: 10 additions & 2 deletions housewatch/clickhouse/clusters.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
from collections import defaultdict
from housewatch.clickhouse.client import run_query


def get_clusters():
QUERY = """Select cluster FROM system.clusters GROUP BY cluster"""
return run_query(QUERY)
QUERY = """Select * FROM system.clusters"""
res = run_query(QUERY)
clusters = defaultdict(list)
for c_node in res:
clusters[c_node["cluster"]].append(c_node)
accumulator = []
for cluster, nodes in clusters.items():
accumulator.append({"cluster": cluster, "nodes": nodes})
return accumulator


def get_cluster(cluster):
Expand Down

0 comments on commit da57178

Please sign in to comment.