2017-04-01 09:19:00 +00:00
|
|
|
#include <Columns/ColumnsNumber.h>
|
|
|
|
#include <Columns/ColumnString.h>
|
|
|
|
#include <Columns/ColumnFixedString.h>
|
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
|
|
|
#include <DataTypes/DataTypeDateTime.h>
|
|
|
|
#include <DataTypes/DataTypeDate.h>
|
|
|
|
#include <DataTypes/DataTypeString.h>
|
|
|
|
#include <DataTypes/DataTypeFixedString.h>
|
2018-05-17 16:01:41 +00:00
|
|
|
#include <DataTypes/DataTypeArray.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Interpreters/QueryLog.h>
|
|
|
|
#include <Common/ClickHouseRevision.h>
|
2016-10-27 17:48:12 +00:00
|
|
|
#include <Poco/Net/IPAddress.h>
|
2016-10-26 22:27:38 +00:00
|
|
|
#include <array>
|
2015-06-26 19:23:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2016-10-27 17:48:12 +00:00
|
|
|
Block QueryLogElement::createBlock()
|
2015-06-26 19:23:25 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
return
|
|
|
|
{
|
2017-12-14 01:43:19 +00:00
|
|
|
{ColumnUInt8::create(), std::make_shared<DataTypeUInt8>(), "type"},
|
|
|
|
{ColumnUInt16::create(), std::make_shared<DataTypeDate>(), "event_date"},
|
|
|
|
{ColumnUInt32::create(), std::make_shared<DataTypeDateTime>(), "event_time"},
|
|
|
|
{ColumnUInt32::create(), std::make_shared<DataTypeDateTime>(), "query_start_time"},
|
|
|
|
{ColumnUInt64::create(), std::make_shared<DataTypeUInt64>(), "query_duration_ms"},
|
2016-05-28 07:48:40 +00:00
|
|
|
|
2017-12-14 01:43:19 +00:00
|
|
|
{ColumnUInt64::create(), std::make_shared<DataTypeUInt64>(), "read_rows"},
|
|
|
|
{ColumnUInt64::create(), std::make_shared<DataTypeUInt64>(), "read_bytes"},
|
2016-05-28 07:48:40 +00:00
|
|
|
|
2017-12-14 01:43:19 +00:00
|
|
|
{ColumnUInt64::create(), std::make_shared<DataTypeUInt64>(), "written_rows"},
|
|
|
|
{ColumnUInt64::create(), std::make_shared<DataTypeUInt64>(), "written_bytes"},
|
2016-12-06 20:55:13 +00:00
|
|
|
|
2017-12-14 01:43:19 +00:00
|
|
|
{ColumnUInt64::create(), std::make_shared<DataTypeUInt64>(), "result_rows"},
|
|
|
|
{ColumnUInt64::create(), std::make_shared<DataTypeUInt64>(), "result_bytes"},
|
2016-05-28 07:48:40 +00:00
|
|
|
|
2017-12-14 01:43:19 +00:00
|
|
|
{ColumnUInt64::create(), std::make_shared<DataTypeUInt64>(), "memory_usage"},
|
2016-05-28 07:48:40 +00:00
|
|
|
|
2017-12-14 01:43:19 +00:00
|
|
|
{ColumnString::create(), std::make_shared<DataTypeString>(), "query"},
|
|
|
|
{ColumnString::create(), std::make_shared<DataTypeString>(), "exception"},
|
|
|
|
{ColumnString::create(), std::make_shared<DataTypeString>(), "stack_trace"},
|
2016-05-28 07:48:40 +00:00
|
|
|
|
2017-12-14 01:43:19 +00:00
|
|
|
{ColumnUInt8::create(), std::make_shared<DataTypeUInt8>(), "is_initial_query"},
|
2016-10-24 21:40:39 +00:00
|
|
|
|
2017-12-14 01:43:19 +00:00
|
|
|
{ColumnString::create(), std::make_shared<DataTypeString>(), "user"},
|
|
|
|
{ColumnString::create(), std::make_shared<DataTypeString>(), "query_id"},
|
|
|
|
{ColumnFixedString::create(16), std::make_shared<DataTypeFixedString>(16), "address"},
|
|
|
|
{ColumnUInt16::create(), std::make_shared<DataTypeUInt16>(), "port"},
|
2016-10-24 21:40:39 +00:00
|
|
|
|
2017-12-14 01:43:19 +00:00
|
|
|
{ColumnString::create(), std::make_shared<DataTypeString>(), "initial_user"},
|
|
|
|
{ColumnString::create(), std::make_shared<DataTypeString>(), "initial_query_id"},
|
|
|
|
{ColumnFixedString::create(16), std::make_shared<DataTypeFixedString>(16), "initial_address"},
|
|
|
|
{ColumnUInt16::create(), std::make_shared<DataTypeUInt16>(), "initial_port"},
|
2016-10-24 21:40:39 +00:00
|
|
|
|
2017-12-14 01:43:19 +00:00
|
|
|
{ColumnUInt8::create(), std::make_shared<DataTypeUInt8>(), "interface"},
|
2016-10-24 21:40:39 +00:00
|
|
|
|
2017-12-14 01:43:19 +00:00
|
|
|
{ColumnString::create(), std::make_shared<DataTypeString>(), "os_user"},
|
|
|
|
{ColumnString::create(), std::make_shared<DataTypeString>(), "client_hostname"},
|
|
|
|
{ColumnString::create(), std::make_shared<DataTypeString>(), "client_name"},
|
|
|
|
{ColumnUInt32::create(), std::make_shared<DataTypeUInt32>(), "client_revision"},
|
2016-10-24 21:40:39 +00:00
|
|
|
|
2017-12-14 01:43:19 +00:00
|
|
|
{ColumnUInt8::create(), std::make_shared<DataTypeUInt8>(), "http_method"},
|
|
|
|
{ColumnString::create(), std::make_shared<DataTypeString>(), "http_user_agent"},
|
2016-10-24 21:40:39 +00:00
|
|
|
|
2017-12-14 01:43:19 +00:00
|
|
|
{ColumnString::create(), std::make_shared<DataTypeString>(), "quota_key"},
|
2016-11-16 05:09:41 +00:00
|
|
|
|
2017-12-14 01:43:19 +00:00
|
|
|
{ColumnUInt32::create(), std::make_shared<DataTypeUInt32>(), "revision"},
|
2018-05-17 16:01:41 +00:00
|
|
|
|
|
|
|
{ std::make_shared<DataTypeArray>(std::make_shared<DataTypeUInt32>()), "thread_numbers" },
|
|
|
|
{ std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>()), "ProfileEvents.Names" },
|
|
|
|
{ std::make_shared<DataTypeArray>(std::make_shared<DataTypeUInt64>()), "ProfileEvents.Values" },
|
|
|
|
{ std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>()), "Settings.Names" },
|
|
|
|
{ std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>()), "Settings.Values" }
|
2017-04-01 07:20:54 +00:00
|
|
|
};
|
2015-06-26 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-24 21:40:39 +00:00
|
|
|
static std::array<char, 16> IPv6ToBinary(const Poco::Net::IPAddress & address)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
std::array<char, 16> res;
|
|
|
|
|
|
|
|
if (Poco::Net::IPAddress::IPv6 == address.family())
|
|
|
|
{
|
|
|
|
memcpy(res.data(), address.addr(), 16);
|
|
|
|
}
|
|
|
|
else if (Poco::Net::IPAddress::IPv4 == address.family())
|
|
|
|
{
|
2017-04-02 17:37:49 +00:00
|
|
|
/// Convert to IPv6-mapped address.
|
2017-04-01 07:20:54 +00:00
|
|
|
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;
|
2016-10-24 21:40:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-27 17:48:12 +00:00
|
|
|
void QueryLogElement::appendToBlock(Block & block) const
|
2015-06-26 19:23:25 +00:00
|
|
|
{
|
2017-12-15 18:23:05 +00:00
|
|
|
MutableColumns columns = block.mutateColumns();
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t i = 0;
|
2016-10-24 21:40:39 +00:00
|
|
|
|
2017-12-15 18:23:05 +00:00
|
|
|
columns[i++]->insert(UInt64(type));
|
|
|
|
columns[i++]->insert(UInt64(DateLUT::instance().toDayNum(event_time)));
|
|
|
|
columns[i++]->insert(UInt64(event_time));
|
|
|
|
columns[i++]->insert(UInt64(query_start_time));
|
|
|
|
columns[i++]->insert(UInt64(query_duration_ms));
|
|
|
|
|
|
|
|
columns[i++]->insert(UInt64(read_rows));
|
|
|
|
columns[i++]->insert(UInt64(read_bytes));
|
2016-10-24 21:40:39 +00:00
|
|
|
|
2017-12-15 18:23:05 +00:00
|
|
|
columns[i++]->insert(UInt64(written_rows));
|
|
|
|
columns[i++]->insert(UInt64(written_bytes));
|
2015-07-01 05:18:54 +00:00
|
|
|
|
2017-12-15 18:23:05 +00:00
|
|
|
columns[i++]->insert(UInt64(result_rows));
|
|
|
|
columns[i++]->insert(UInt64(result_bytes));
|
2016-12-06 20:55:13 +00:00
|
|
|
|
2017-12-15 18:23:05 +00:00
|
|
|
columns[i++]->insert(UInt64(memory_usage));
|
2015-07-01 05:18:54 +00:00
|
|
|
|
2017-12-15 18:23:05 +00:00
|
|
|
columns[i++]->insertData(query.data(), query.size());
|
|
|
|
columns[i++]->insertData(exception.data(), exception.size());
|
|
|
|
columns[i++]->insertData(stack_trace.data(), stack_trace.size());
|
2015-07-01 05:18:54 +00:00
|
|
|
|
2017-12-15 18:23:05 +00:00
|
|
|
columns[i++]->insert(UInt64(client_info.query_kind == ClientInfo::QueryKind::INITIAL_QUERY));
|
2015-07-01 05:18:54 +00:00
|
|
|
|
2017-12-15 18:23:05 +00:00
|
|
|
columns[i++]->insert(client_info.current_user);
|
|
|
|
columns[i++]->insert(client_info.current_query_id);
|
|
|
|
columns[i++]->insertData(IPv6ToBinary(client_info.current_address.host()).data(), 16);
|
|
|
|
columns[i++]->insert(UInt64(client_info.current_address.port()));
|
2015-07-01 05:18:54 +00:00
|
|
|
|
2017-12-15 18:23:05 +00:00
|
|
|
columns[i++]->insert(client_info.initial_user);
|
|
|
|
columns[i++]->insert(client_info.initial_query_id);
|
|
|
|
columns[i++]->insertData(IPv6ToBinary(client_info.initial_address.host()).data(), 16);
|
|
|
|
columns[i++]->insert(UInt64(client_info.initial_address.port()));
|
2015-07-01 05:18:54 +00:00
|
|
|
|
2017-12-15 18:23:05 +00:00
|
|
|
columns[i++]->insert(UInt64(client_info.interface));
|
2015-06-26 19:23:25 +00:00
|
|
|
|
2017-12-15 18:23:05 +00:00
|
|
|
columns[i++]->insert(client_info.os_user);
|
|
|
|
columns[i++]->insert(client_info.client_hostname);
|
|
|
|
columns[i++]->insert(client_info.client_name);
|
|
|
|
columns[i++]->insert(UInt64(client_info.client_revision));
|
2015-12-09 03:30:54 +00:00
|
|
|
|
2017-12-15 18:23:05 +00:00
|
|
|
columns[i++]->insert(UInt64(client_info.http_method));
|
|
|
|
columns[i++]->insert(client_info.http_user_agent);
|
2015-06-26 19:23:25 +00:00
|
|
|
|
2017-12-15 18:23:05 +00:00
|
|
|
columns[i++]->insert(client_info.quota_key);
|
2015-06-26 19:23:25 +00:00
|
|
|
|
2017-12-15 18:23:05 +00:00
|
|
|
columns[i++]->insert(UInt64(ClickHouseRevision::get()));
|
2016-11-16 05:09:41 +00:00
|
|
|
|
2018-05-17 16:01:41 +00:00
|
|
|
{
|
|
|
|
Array threads_array;
|
|
|
|
threads_array.reserve(thread_numbers.size());
|
|
|
|
for (const UInt32 thread_number : thread_numbers)
|
|
|
|
threads_array.emplace_back(UInt64(thread_number));
|
|
|
|
columns[i++]->insert(threads_array);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (profile_counters)
|
|
|
|
{
|
|
|
|
auto column_names = columns[i++].get();
|
|
|
|
auto column_values = columns[i++].get();
|
|
|
|
profile_counters->dumpToArrayColumns(column_names, column_values, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
columns[i++]->insertDefault();
|
|
|
|
columns[i++]->insertDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (query_settings)
|
|
|
|
{
|
|
|
|
auto column_names = columns[i++].get();
|
|
|
|
auto column_values = columns[i++].get();
|
|
|
|
query_settings->dumpToArrayColumns(column_names, column_values, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
columns[i++]->insertDefault();
|
|
|
|
columns[i++]->insertDefault();
|
|
|
|
}
|
|
|
|
|
2017-12-15 18:23:05 +00:00
|
|
|
block.setColumns(std::move(columns));
|
2015-06-26 19:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|