|
| 1 | +import { ColumnFormat } from '@/components/data-table/column-defs' |
| 2 | +import { type QueryConfig } from '@/lib/types/query-config' |
| 3 | + |
| 4 | +export type Row = { |
| 5 | + host: string |
| 6 | + readable_total_rows: string |
| 7 | + readable_total_bytes: string |
| 8 | + readable_primary_key_size: string |
| 9 | + readable_marks_bytes: string |
| 10 | + part_count: number |
| 11 | + last_modification_time: string |
| 12 | +} |
| 13 | + |
| 14 | +export const config: QueryConfig = { |
| 15 | + name: 'count-in-replicas', |
| 16 | + description: 'Count across replicas for all tables in the cluster', |
| 17 | + sql: ` |
| 18 | + SELECT |
| 19 | + hostName() AS host, |
| 20 | +
|
| 21 | + sum(rows) AS total_rows, |
| 22 | + formatReadableQuantity(total_rows) AS readable_total_rows, |
| 23 | + (100 * total_rows / max(total_rows) OVER ()) AS pct_total_rows, |
| 24 | +
|
| 25 | + sum(bytes) AS total_bytes, |
| 26 | + formatReadableSize(sum(bytes)) AS readable_total_bytes, |
| 27 | + (100 * total_bytes / max(total_bytes) OVER ()) AS pct_total_bytes, |
| 28 | +
|
| 29 | + countDistinct(database) AS database_count, |
| 30 | + countDistinct(database || table) AS table_count, |
| 31 | +
|
| 32 | + countIf(active) as active_part_count, |
| 33 | + (100 * active_part_count / max(active_part_count) OVER ()) AS pct_active_part_count, |
| 34 | +
|
| 35 | + count() as all_part_count, |
| 36 | + (100 * all_part_count / max(all_part_count) OVER ()) AS pct_all_part_count, |
| 37 | +
|
| 38 | + sum(primary_key_size) AS primary_key_size, |
| 39 | + formatReadableSize(primary_key_size) AS readable_primary_key_size, |
| 40 | + (100 * primary_key_size / max(primary_key_size) OVER ()) AS pct_primary_key_size, |
| 41 | +
|
| 42 | + sum(marks_bytes) AS marks_bytes, |
| 43 | + formatReadableSize(marks_bytes) AS readable_marks_bytes, |
| 44 | + (100 * marks_bytes / max(marks_bytes) OVER ()) AS pct_marks_bytes, |
| 45 | +
|
| 46 | + max(modification_time) AS last_modification_time |
| 47 | +
|
| 48 | + FROM clusterAllReplicas({cluster: String}, system.parts) |
| 49 | + WHERE active |
| 50 | + GROUP BY 1 |
| 51 | + ORDER BY |
| 52 | + 1 ASC, |
| 53 | + 2 DESC |
| 54 | + `, |
| 55 | + columns: [ |
| 56 | + 'host', |
| 57 | + 'readable_total_rows', |
| 58 | + 'readable_total_bytes', |
| 59 | + 'readable_primary_key_size', |
| 60 | + 'readable_marks_bytes', |
| 61 | + 'active_part_count', |
| 62 | + 'all_part_count', |
| 63 | + 'last_modification_time', |
| 64 | + 'database_count', |
| 65 | + 'table_count', |
| 66 | + ], |
| 67 | + columnFormats: { |
| 68 | + readable_total_rows: ColumnFormat.BackgroundBar, |
| 69 | + readable_total_bytes: ColumnFormat.BackgroundBar, |
| 70 | + readable_primary_key_size: ColumnFormat.BackgroundBar, |
| 71 | + readable_marks_bytes: ColumnFormat.BackgroundBar, |
| 72 | + active_part_count: ColumnFormat.BackgroundBar, |
| 73 | + all_part_count: ColumnFormat.BackgroundBar, |
| 74 | + database_count: ColumnFormat.BackgroundBar, |
| 75 | + table_count: ColumnFormat.BackgroundBar, |
| 76 | + }, |
| 77 | +} |
0 commit comments