system.query_log, system.metric_log, system.part_log, system.text_log, system.asynchronous_metric_log) are enabled in the default server configuration. They are sorted by event_date first (system.asynchronous_metric_log by metric first), which is why the queries filter on event_date in addition to event_time: the server then reads only the recent data.
Server start time
system.text_log:
Starting ClickHouse followed by its version, revision and build identifier when it starts. Every row is one start of the server, so two rows close to each other mean a restart. The last messages before a stop are not a reliable marker: a server that is terminated abruptly does not write them.
Failed queries by error
A query that fails is written tosystem.query_log with the type ExceptionBeforeStart or ExceptionWhileProcessing:
normalized_query_hash is the same for queries that differ only in literal values, so query_patterns tells you whether one statement fails repeatedly or many different ones fail. The query log is a better source for alerts than the counters of system.errors, which also count exceptions that the server handled internally: see Why does system.errors show errors for queries that succeeded?.
Queries that exceeded the memory limit
Error code 241 isMEMORY_LIMIT_EXCEEDED. This query groups such failures by hour and by query pattern and returns one query_id per group to look at:
241 with another code to track a different error, for example 202 for TOO_MANY_SIMULTANEOUS_QUERIES. See Memory limit exceeded for query for what to do about the error itself.
Peak CPU usage
system.metric_log stores, for every collection interval, how much each profile event grew. The interval is collect_interval_milliseconds in the metric_log section of the server configuration, 1000 (one second) by default. OSCPUVirtualTimeMicroseconds is the CPU time used by the server, so dividing it by the length of the interval in microseconds gives the number of CPU cores that were busy during the interval:
peak_cpu_cores with the number of cores available to the server. If your server collects the metrics at another interval, change the first line of the query: with the wrong value the result is off by the ratio of the two intervals, for example twice too high for a two-second interval.
CPU wait
OSCPUWaitMicroseconds is the time that threads were ready to run but waited for a CPU core. Collection intervals in which the threads of the server waited, in total, for longer than the interval lasts (more than one second with the default interval) indicate that the server had more work than cores:
Memory tracked by the server
MemoryTracking is the total amount of memory tracked by the server.
Memory used compared with the memory available
system.asynchronous_metric_log keeps the history of the metrics that the server calculates periodically. MemoryResident is the physical memory used by the server process. CGroupMemoryTotal is the memory limit of the cgroup (container) the server runs in, and is zero or absent when there is no such limit, in which case OSMemoryTotal, the memory of the host, applies:
Load average
LoadAverage15 is the load of the whole host averaged over 15 minutes; LoadAverage1 and LoadAverage5 are also available:
Failed merges and mutations
Every merge and every mutation of a part is recorded insystem.part_log. A non-zero error is the code of the exception that stopped it:
Run the queries on all servers of a cluster
Each server has its own system tables. To query all of them at once, wrap the table inclusterAllReplicas and add hostName() to the result. In ClickHouse Cloud the cluster is named default; on a self-managed cluster use the name from system.clusters: