#include #include #include #include #include #include #include #include #include #include namespace DB { Block QueryLogElement::createBlock() { return { {std::make_shared(), std::make_shared(), "type"}, {std::make_shared(), std::make_shared(), "event_date"}, {std::make_shared(), std::make_shared(), "event_time"}, {std::make_shared(), std::make_shared(), "query_start_time"}, {std::make_shared(), std::make_shared(), "query_duration_ms"}, {std::make_shared(), std::make_shared(), "read_rows"}, {std::make_shared(), std::make_shared(), "read_bytes"}, {std::make_shared(), std::make_shared(), "result_rows"}, {std::make_shared(), std::make_shared(), "result_bytes"}, {std::make_shared(), std::make_shared(), "memory_usage"}, {std::make_shared(), std::make_shared(), "query"}, {std::make_shared(), std::make_shared(), "exception"}, {std::make_shared(), std::make_shared(), "stack_trace"}, {std::make_shared(), std::make_shared(), "is_initial_query"}, {std::make_shared(), std::make_shared(), "user"}, {std::make_shared(), std::make_shared(), "query_id"}, {std::make_shared(16), std::make_shared(16), "address"}, {std::make_shared(), std::make_shared(), "port"}, {std::make_shared(), std::make_shared(), "initial_user"}, {std::make_shared(), std::make_shared(), "initial_query_id"}, {std::make_shared(16), std::make_shared(16), "initial_address"}, {std::make_shared(), std::make_shared(), "initial_port"}, {std::make_shared(), std::make_shared(), "interface"}, {std::make_shared(), std::make_shared(), "os_user"}, {std::make_shared(), std::make_shared(), "client_hostname"}, {std::make_shared(), std::make_shared(), "client_name"}, {std::make_shared(), std::make_shared(), "client_revision"}, {std::make_shared(), std::make_shared(), "http_method"}, {std::make_shared(), std::make_shared(), "http_user_agent"}, {std::make_shared(), std::make_shared(), "revision"}, }; } static std::array IPv6ToBinary(const Poco::Net::IPAddress & address) { std::array res; if (Poco::Net::IPAddress::IPv6 == address.family()) { memcpy(res.data(), address.addr(), 16); } else if (Poco::Net::IPAddress::IPv4 == address.family()) { /// Преобразуем в IPv6-mapped адрес. memset(res.data(), 0, 10); res[10] = '\xFF'; res[11] = '\xFF'; memcpy(&res[12], address.addr(), 4); } else memset(res.data(), 0, 16); return res; } void QueryLogElement::appendToBlock(Block & block) const { size_t i = 0; block.unsafeGetByPosition(i++).column->insert(UInt64(type)); block.unsafeGetByPosition(i++).column->insert(UInt64(DateLUT::instance().toDayNum(event_time))); block.unsafeGetByPosition(i++).column->insert(UInt64(event_time)); block.unsafeGetByPosition(i++).column->insert(UInt64(query_start_time)); block.unsafeGetByPosition(i++).column->insert(UInt64(query_duration_ms)); block.unsafeGetByPosition(i++).column->insert(UInt64(read_rows)); block.unsafeGetByPosition(i++).column->insert(UInt64(read_bytes)); block.unsafeGetByPosition(i++).column->insert(UInt64(result_rows)); block.unsafeGetByPosition(i++).column->insert(UInt64(result_bytes)); block.unsafeGetByPosition(i++).column->insert(UInt64(memory_usage)); block.unsafeGetByPosition(i++).column->insertData(query.data(), query.size()); block.unsafeGetByPosition(i++).column->insertData(exception.data(), exception.size()); block.unsafeGetByPosition(i++).column->insertData(stack_trace.data(), stack_trace.size()); block.unsafeGetByPosition(i++).column->insert(UInt64(client_info.query_kind == ClientInfo::QueryKind::INITIAL_QUERY)); block.unsafeGetByPosition(i++).column->insert(client_info.current_user); block.unsafeGetByPosition(i++).column->insert(client_info.current_query_id); block.unsafeGetByPosition(i++).column->insertData(IPv6ToBinary(client_info.current_address.host()).data(), 16); block.unsafeGetByPosition(i++).column->insert(UInt64(client_info.current_address.port())); block.unsafeGetByPosition(i++).column->insert(client_info.initial_user); block.unsafeGetByPosition(i++).column->insert(client_info.initial_query_id); block.unsafeGetByPosition(i++).column->insertData(IPv6ToBinary(client_info.initial_address.host()).data(), 16); block.unsafeGetByPosition(i++).column->insert(UInt64(client_info.initial_address.port())); block.unsafeGetByPosition(i++).column->insert(UInt64(client_info.interface)); block.unsafeGetByPosition(i++).column->insert(client_info.os_user); block.unsafeGetByPosition(i++).column->insert(client_info.client_hostname); block.unsafeGetByPosition(i++).column->insert(client_info.client_name); block.unsafeGetByPosition(i++).column->insert(UInt64(client_info.client_revision)); block.unsafeGetByPosition(i++).column->insert(UInt64(client_info.http_method)); block.unsafeGetByPosition(i++).column->insert(client_info.http_user_agent); block.unsafeGetByPosition(i++).column->insert(UInt64(ClickHouseRevision::get())); } }