点击上方“IT那活儿”公众号--专注于企业全栈运维技术分享,不管IT什么活儿,干就完了!!!
前 言
<database> 系统日志表所在的数据库。这个选项目前已经不推荐使用。所有的系统日表都位于system库中。 <table> 接收数据写入的系统日志表。 <partition_by> 指定PARTITION BY表达式,用以分区。 <ttl> 指定系统日志表TTL选项,用以指定分区生命周期。 <flush_interval_milliseconds> 指定日志表数据刷新到磁盘的时间间隔。 <engine> 指定完整的表引擎定义。(以ENGINE = 开头)。这个选项与partition_by以及ttl冲突。如果与两者一起设置,服务启动时会抛出异常并且退出。
query_log
列:
type (Enum8) 执行查询时的事件类型. 值: 'QueryStart' = 1 查询成功启动. 'QueryFinish' = 2 查询成功完成. 'ExceptionBeforeStart' = 3 查询执行前有异常. 'ExceptionWhileProcessing' = 4 查询执行期间有异常. event_date (Date) 查询开始日期. event_time (DateTime) 查询开始时间. event_time_microseconds (DateTime64) 查询开始时间(毫秒精度). query_start_time (DateTime) 查询执行的开始时间. query_start_time_microseconds (DateTime64) 查询执行的开始时间(毫秒精度). query_duration_ms (UInt64) 查询消耗的时间(毫秒). read_rows (UInt64) 从参与了查询的所有表和表函数读取的总行数. 包括:普通的子查询, IN 和 JOIN的子查询. 对于分布式查询 read_rows 包括在所有副本上读取的行总数。每个副本发送它的 read_rows 值,并且查询的服务器-发起方汇总所有接收到的和本地的值。缓存卷不会影响此值。 read_bytes (UInt64) 从参与了查询的所有表和表函数读取的总字节数. 包括:普通的子查询, IN 和 JOIN的子查询. 对于分布式查询 read_bytes 包括在所有副本上读取的字节总数。每个副本发送它的 read_bytes 值,并且查询的服务器-发起方汇总所有接收到的和本地的值。缓存卷不会影响此值。 written_rows (UInt64) 对于 INSERT 查询,为写入的行数。对于其他查询,值为0。 written_bytes (UInt64) 对于 INSERT 查询时,为写入的字节数。对于其他查询,值为0。 result_rows (UInt64) SELECT查询结果的行数,或INSERT 的行数。 result_bytes (UInt64) 存储查询结果的RAM量. memory_usage (UInt64) 查询使用的内存. query (String) 查询语句. exception (String) 异常信息. exception_code (Int32) 异常码. stack_trace (String) Stack Trace. 如果查询成功完成,则为空字符串。 is_initial_query (UInt8) 查询类型. 可能的值: 1 — 客户端发起的查询. 0 — 由另一个查询发起的,作为分布式查询的一部分. user (String) 发起查询的用户. query_id (String) 查询ID. address (IPv6) 发起查询的客户端IP地址. port (UInt16) 发起查询的客户端端口. initial_user (String) 初始查询的用户名(用于分布式查询执行). initial_query_id (String) 运行初始查询的ID(用于分布式查询执行). initial_address (IPv6) 运行父查询的IP地址. initial_port (UInt16) 发起父查询的客户端端口. interface (UInt8) 发起查询的接口. 可能的值: 1 — TCP. 2 — HTTP. os_user (String) 运行 clickhouse-client的操作系统用户名. client_hostname (String) 运行clickhouse-client 或其他TCP客户端的机器的主机名。 client_name (String) clickhouse-client 或其他TCP客户端的名称。 client_revision (UInt32) clickhouse-client 或其他TCP客户端的Revision。 client_version_major (UInt32) clickhouse-client 或其他TCP客户端的Major version。 client_version_minor (UInt32) clickhouse-client 或其他TCP客户端的Minor version。 client_version_patch (UInt32) clickhouse-client 或其他TCP客户端的Patch component。 http_method (UInt8) 发起查询的HTTP方法. 可能值: 0 — TCP接口的查询. 1 — GET 2 — POST http_user_agent (String) The UserAgent The UserAgent header passed in the HTTP request。 quota_key (String) 在quotas 配置里设置的“quota key” (见 keyed). revision (UInt32) ClickHouse revision. ProfileEvents (Map(String, UInt64))) Counters that measure different metrics. The description of them could be found in the table 系统。活动 Settings (Map(String, String)) Names of settings that were changed when the client ran the query. To enable logging changes to settings, set the log_query_settings 参数为1。 thread_ids (Array(UInt64)) 参与查询的线程数. Settings.Names (Array(String)) 客户端运行查询时更改的设置的名称。要启用对设置的日志记录更改,请将log_query_settings参数设置为1。 Settings.Values (Array(String)) Settings.Names 列中列出的设置的值。
<query_log>
<database>system</database>
<table>query_log</table>
<partition_by>toYYYYMMDD(event_date)</partition_by>
<ttl>event_date + INTERVAL 90 DAY DELETE</ttl>
<flush_interval_milliseconds>7500</flush_interval_milliseconds>
</query_log>
metric_log
<metric_log>
<database>system</database>
<table>metric_log</table>
<partition_by>toYYYYMMDD(event_date)</partition_by>
<ttl>event_date + INTERVAL 90 DAY DELETE</ttl>
<flush_interval_milliseconds>7500</flush_interval_milliseconds>
<collect_interval_milliseconds>1000</collect_interval_milliseconds>
</metric_log>
备注:collect_interval_milliseconds表示收集metrics和events数据的时间周期。
trace_log
通过配置query_profiler_real_time_period_ns 和 query_profiler_cpu_time_period_ns两个参数设置采集频率。 要分析日志,需要使用 addressToLine, addressToSymbol 和 demangle 内省功能。 开启内省功能SET allow_introspection_functions=1,默认为关闭。
SELECT
count(),
arrayStringConcat(arrayMap(x -> concat(demangle(addressToSymbol(x)), '\n ', addressToLine(x)), trace), '\n') AS sym
FROM system.trace_log
WHERE (query_id = 'ebca3574-ad0a-400a-9cbc-dca382f5998c') AND (event_date = today())
GROUP BY trace
ORDER BY count() DESC
LIMIT 10
event_date (日期) — Date of sampling moment.
event_time (日期时间) — Timestamp of the sampling moment.
timestamp_ns (UInt64) — Timestamp of the sampling moment in nanoseconds.
revision (UInt32) — ClickHouse server build revision.
通过以下方式连接到服务器 clickhouse-client,你看到的字符串类似于 Connected to ClickHouse server version 19.18.1.. 该字段包含 revision,但不是 version 的服务器。
timer_type (枚举8) — Timer type:
Real 表示挂钟时间。
CPU 表示CPU时间。
thread_number (UInt32) — Thread identifier.
query_id (字符串) — Query identifier that can be used to get details about a query that was running from the query_log 系统表.
trace (数组(UInt64)) — Stack trace at the moment of sampling. Each element is a virtual memory address inside ClickHouse server process.
<trace_log>
<database>system</database>
<table>trace_log</table>
<partition_by>toYYYYMMDD(event_date)</partition_by>
<ttl>event_date + INTERVAL 90 DAY DELETE</ttl>
<flush_interval_milliseconds>7500</flush_interval_milliseconds>
</trace_log>
part_log
hostname (LowCardinality(字符串)) 执行查询的服务器的主机名。 query_id (字符串) 创建此数据部件的查询的标识符。INSERT event_type (枚举8) 数据部分发生的事件的类型。可以具有以下值之一: NewPart— 插入新的数据部分。 MergeParts— 合并数据部分。 DownloadPart— 下载数据部分。 RemovePart— 使用 DETACH PARTITION 删除或分离数据部分。 MutatePart— 数据部分的变异。 MovePart— 将数据部分从一个磁盘移动到另一个磁盘。 merge_reason (枚举8)— 类型为 的事件原因。可以具有以下值之一:MERGE_PARTS NotAMerge— 当前事件的类型不是 。MERGE_PARTS RegularMerge— 一些常规合并。 TTLDeleteMerge— 清理过期数据。 TTLRecompressMerge— 用 重新压缩数据部分。 merge_algorithm (枚举8) 将事件的合并算法与类型 .可以具有以下值之一: MERGE_PARTS Undecided Horizontal Vertical event_date (日期) 活动日期。 event_time (日期时间) 活动时间。 event_time_microseconds (日期时间64) 以微秒为精度的事件时间。 duration_ms (UInt64) 持续时间。 database (字符串) 数据部分所在的数据库的名称。 table (字符串) 数据部分所在的表的名称。 part_name (字符串) 数据部分的名称。 partition_id (字符串) 插入数据部分的分区的 ID。如果分区为 ,则该列采用该值。alltuple() path_on_disk (字符串) 包含数据部件文件的文件夹的绝对路径。 rows (UInt64) 数据部分中的行数。 size_in_bytes (UInt64) 数据部分的大小(以字节为单位)。 merged_from (数组(String)) 组成当前部件的部件名称数组(合并后)。 bytes_uncompressed (UInt64) 未压缩字节的大小。 read_rows (UInt64) 在合并期间读取的行数。 read_bytes (UInt64) 合并期间读取的字节数。 peak_memory_usage (Int64) 此线程上下文中分配的内存量和释放的内存量之间的最大差值。 error (UInt16) 发生错误的代码编号。 exception (字符串) 发生错误的短信。
<part_log>
<database>system</database>
<table>part_log</table>
<partition_by>toYYYYMMDD(event_date)</partition_by>
<ttl>event_date + INTERVAL 90 DAY DELETE</ttl>
<flush_interval_milliseconds>7500</flush_interval_milliseconds> </part_log>
asynchronous_metric_log
hostname (LowCardinality(字符串)) 执行查询的服务器的主机名。 event_date (日期) 活动日期。 event_time (日期时间) 活动时间。 metric (字符串) 指标名称。 value (浮动64) 指标值。
<asynchronous_metric_log>
<database>system</database>
<table>asynchronous_metric_log</table>
<partition_by>toYYYYMMDD(event_date)</partition_by>
<ttl>event_date + INTERVAL 90 DAY DELETE</ttl>
<flush_interval_milliseconds>7500</flush_interval_milliseconds>
</asynchronous_metric_log>
系统日志表清理
ALTER table system.trace_log on cluster xxxxxx DROP PARTITION xxxxxx;
<ttl>event_date + INTERVAL 30 DAY DELETE</ttl>
ALTER TABLE system.query_log ON CLUSTER default_cluster MODIFY TTL event_date + INTERVAL 30 DAY DELETE;

本文作者:刘 能(上海新炬中北团队)
本文来源:“IT那活儿”公众号





