/** * The ClickHouse census: where a cluster's CPU goes, read from its own system * tables over a window. W is the write share (inserts into the logs table plus * its merges, over node CPU), Q the read share (SELECTs over node CPU), with * the hourly peak, rows and bytes per table, and tables no SELECT touched. * Read only. Every SQL statement sent is kept in `queries`. */ import { type ChQuery } from './clickhouse-rows-tick.js'; /** Tag on every census statement, so the census never counts its own reads. */ export declare const CENSUS_TAG = "log10x_census"; export interface CensusOptions { nowSec: number; days: number; database: string; table: string; /** Cluster for clusterAllReplicas over the system logs; undefined reads one node. */ cluster?: string; /** The ClickHouse user the census runs as, named in GRANT lines. */ user: string; } export type DenominatorSource = 'metric_log' | 'asynchronous_metric_log' | 'attributed'; export interface Unreadable { table: string; reason: 'grant' | 'error'; message: string; grant?: string; } export interface ReadShape { user: string; shape: string; selects: number; cpu_seconds: number; share_of_node: number | null; read_rows: number; read_bytes: number; } export interface TableWritten { table: string; new_parts: number; rows_written: number; bytes_written: number; rows_merged: number; /** Rows merged over rows written. */ write_amplification: number | null; } export interface TableStored { table: string; rows: number; bytes_on_disk: number; compressed_bytes: number; uncompressed_bytes: number; compression_ratio: number | null; } export interface TableRead { table: string; selects: number; last_read: string; } export interface NeverRead { table: string; engine: string; rows: number; bytes_on_disk: number; } export interface HourCpu { hour: string; node_cpu_seconds: number; cores: number; write_cpu_seconds: number; read_cpu_seconds: number; } export interface CensusReport { target_table: string; database: string; cluster: string | null; window: { from: string; to: string; days: number; }; window_found: { first_hour: string | null; last_hour: string | null; hours: number; }; denominator: DenominatorSource; merge_cpu_method: 'profile_events' | 'duration' | 'none'; ttl_split: boolean; cpu_seconds: { node_total: number; insert_table: number; merge_table: number; ttl_merge_table: number; insert_all: number; merge_all: number; ttl_merge_all: number; select: number; other_queries: number; }; selects: number; /** W on the target table: its inserts and merges (ordinary and TTL) over node CPU. */ w_share: number | null; w_parts: { insert: number; merge: number; ttl_merge: number; } | null; /** The same over every table on the node. */ w_share_all_tables: number | null; q_share: number | null; /** Node CPU no log attributes (replication, moves, log flushes); printed, never folded into W or Q. */ residual_share: number | null; peak: { hour: string; cores: number; mean_cores: number; peak_to_mean: number; w_at_peak: number | null; q_at_peak: number | null; } | null; hours: HourCpu[]; top_shapes: ReadShape[]; tables_written: TableWritten[]; tables_stored: TableStored[]; tables_read: TableRead[]; /** Tables system.tables listed in the database; never_read is only meaningful above zero. */ tables_listed: number; never_read: NeverRead[]; unreadable: Unreadable[]; missing_logs: string[]; notes: string[]; queries: string[]; } /** The connection failed outright (network, authentication), not one table. */ export declare class CensusConnectError extends Error { } /** re2 for `INSERT INTO [TABLE] [db.]tbl`, quoted or not, written as a ClickHouse string literal body. */ export declare function insertIntoRegex(db: string, tbl: string): string; export declare function censusSql(o: CensusOptions, fromSec: number, toSec: number): { columns: string; nodeCpu: string; nodeCpuAsync: string; queryCpu: string; mergeCpu: (method: "profile_events" | "duration", ttlSplit: boolean) => string; shapes: string; written: string; stored: string; reads: string; tables: string; }; export declare function grantFor(table: string, user: string, cluster: string | undefined, message?: string): string; /** Every grant the census needs, for the not-configured answer. SHOW TABLES makes the database visible in system.tables and system.parts. */ export declare function censusGrants(user: string, database: string, cluster?: string): string[]; export declare function runCensus(ch: ChQuery, o: CensusOptions): Promise; export declare function pct(x: number | null | undefined): string; /** The value to pass as compute_write_share: two decimals, or two significant digits below 0.1. */ export declare function writeShareArg(w: number): number; export declare function renderCensusMarkdown(r: CensusReport): string;