1 | #include "QueryThreadLog.h" |
2 | #include <Columns/ColumnsNumber.h> |
3 | #include <Columns/ColumnString.h> |
4 | #include <Columns/ColumnFixedString.h> |
5 | #include <DataTypes/DataTypesNumber.h> |
6 | #include <DataTypes/DataTypeDateTime.h> |
7 | #include <DataTypes/DataTypeDate.h> |
8 | #include <DataTypes/DataTypeString.h> |
9 | #include <DataTypes/DataTypeArray.h> |
10 | #include <DataTypes/DataTypeFactory.h> |
11 | #include <Interpreters/QueryLog.h> |
12 | #include <Interpreters/ProfileEventsExt.h> |
13 | #include <Common/ClickHouseRevision.h> |
14 | #include <Poco/Net/IPAddress.h> |
15 | #include <array> |
16 | |
17 | |
18 | namespace DB |
19 | { |
20 | |
21 | Block QueryThreadLogElement::createBlock() |
22 | { |
23 | return |
24 | { |
25 | {std::make_shared<DataTypeDate>(), "event_date" }, |
26 | {std::make_shared<DataTypeDateTime>(), "event_time" }, |
27 | {std::make_shared<DataTypeDateTime>(), "query_start_time" }, |
28 | {std::make_shared<DataTypeUInt64>(), "query_duration_ms" }, |
29 | |
30 | {std::make_shared<DataTypeUInt64>(), "read_rows" }, |
31 | {std::make_shared<DataTypeUInt64>(), "read_bytes" }, |
32 | {std::make_shared<DataTypeUInt64>(), "written_rows" }, |
33 | {std::make_shared<DataTypeUInt64>(), "written_bytes" }, |
34 | {std::make_shared<DataTypeInt64>(), "memory_usage" }, |
35 | {std::make_shared<DataTypeInt64>(), "peak_memory_usage" }, |
36 | |
37 | {std::make_shared<DataTypeString>(), "thread_name" }, |
38 | {std::make_shared<DataTypeUInt32>(), "thread_number" }, |
39 | {std::make_shared<DataTypeInt32>(), "os_thread_id" }, |
40 | {std::make_shared<DataTypeUInt32>(), "master_thread_number" }, |
41 | {std::make_shared<DataTypeInt32>(), "master_os_thread_id" }, |
42 | {std::make_shared<DataTypeString>(), "query" }, |
43 | |
44 | {std::make_shared<DataTypeUInt8>(), "is_initial_query" }, |
45 | {std::make_shared<DataTypeString>(), "user" }, |
46 | {std::make_shared<DataTypeString>(), "query_id" }, |
47 | {DataTypeFactory::instance().get("IPv6" ), "address" }, |
48 | {std::make_shared<DataTypeUInt16>(), "port" }, |
49 | {std::make_shared<DataTypeString>(), "initial_user" }, |
50 | {std::make_shared<DataTypeString>(), "initial_query_id" }, |
51 | {DataTypeFactory::instance().get("IPv6" ), "initial_address" }, |
52 | {std::make_shared<DataTypeUInt16>(), "initial_port" }, |
53 | {std::make_shared<DataTypeUInt8>(), "interface" }, |
54 | {std::make_shared<DataTypeString>(), "os_user" }, |
55 | {std::make_shared<DataTypeString>(), "client_hostname" }, |
56 | {std::make_shared<DataTypeString>(), "client_name" }, |
57 | {std::make_shared<DataTypeUInt32>(), "client_revision" }, |
58 | {std::make_shared<DataTypeUInt32>(), "client_version_major" }, |
59 | {std::make_shared<DataTypeUInt32>(), "client_version_minor" }, |
60 | {std::make_shared<DataTypeUInt32>(), "client_version_patch" }, |
61 | {std::make_shared<DataTypeUInt8>(), "http_method" }, |
62 | {std::make_shared<DataTypeString>(), "http_user_agent" }, |
63 | {std::make_shared<DataTypeString>(), "quota_key" }, |
64 | |
65 | {std::make_shared<DataTypeUInt32>(), "revision" }, |
66 | |
67 | {std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>()), "ProfileEvents.Names" }, |
68 | {std::make_shared<DataTypeArray>(std::make_shared<DataTypeUInt64>()), "ProfileEvents.Values" } |
69 | }; |
70 | } |
71 | |
72 | void QueryThreadLogElement::appendToBlock(Block & block) const |
73 | { |
74 | MutableColumns columns = block.mutateColumns(); |
75 | |
76 | size_t i = 0; |
77 | |
78 | columns[i++]->insert(DateLUT::instance().toDayNum(event_time)); |
79 | columns[i++]->insert(event_time); |
80 | columns[i++]->insert(query_start_time); |
81 | columns[i++]->insert(query_duration_ms); |
82 | |
83 | columns[i++]->insert(read_rows); |
84 | columns[i++]->insert(read_bytes); |
85 | columns[i++]->insert(written_rows); |
86 | columns[i++]->insert(written_bytes); |
87 | |
88 | columns[i++]->insert(memory_usage); |
89 | columns[i++]->insert(peak_memory_usage); |
90 | |
91 | columns[i++]->insertData(thread_name.data(), thread_name.size()); |
92 | columns[i++]->insert(thread_number); |
93 | columns[i++]->insert(os_thread_id); |
94 | columns[i++]->insert(master_thread_number); |
95 | columns[i++]->insert(master_os_thread_id); |
96 | |
97 | columns[i++]->insertData(query.data(), query.size()); |
98 | |
99 | QueryLogElement::appendClientInfo(client_info, columns, i); |
100 | |
101 | columns[i++]->insert(ClickHouseRevision::get()); |
102 | |
103 | if (profile_counters) |
104 | { |
105 | auto column_names = columns[i++].get(); |
106 | auto column_values = columns[i++].get(); |
107 | dumpToArrayColumns(*profile_counters, column_names, column_values, true); |
108 | } |
109 | else |
110 | { |
111 | columns[i++]->insertDefault(); |
112 | columns[i++]->insertDefault(); |
113 | } |
114 | } |
115 | |
116 | } |
117 | |