2017-04-01 09:19:00 +00:00
|
|
|
#include <Columns/ColumnString.h>
|
|
|
|
#include <DataTypes/DataTypeString.h>
|
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
2018-03-01 16:52:24 +00:00
|
|
|
#include <DataTypes/DataTypeArray.h>
|
|
|
|
#include <DataTypes/DataTypeTuple.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <DataStreams/OneBlockInputStream.h>
|
|
|
|
#include <Interpreters/ProcessList.h>
|
|
|
|
#include <Storages/System/StorageSystemProcesses.h>
|
|
|
|
#include <Interpreters/Context.h>
|
2018-03-01 16:52:24 +00:00
|
|
|
#include <Storages/System/VirtualColumnsProcessor.h>
|
2013-09-03 20:21:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2015-01-21 03:56:28 +00:00
|
|
|
StorageSystemProcesses::StorageSystemProcesses(const std::string & name_)
|
2017-04-01 07:20:54 +00:00
|
|
|
: name(name_)
|
2018-01-25 14:42:39 +00:00
|
|
|
{
|
2018-03-13 14:18:11 +00:00
|
|
|
setColumns(ColumnsDescription({
|
2017-04-01 07:20:54 +00:00
|
|
|
{ "is_initial_query", std::make_shared<DataTypeUInt8>() },
|
|
|
|
|
|
|
|
{ "user", std::make_shared<DataTypeString>() },
|
|
|
|
{ "query_id", std::make_shared<DataTypeString>() },
|
2017-12-02 02:47:12 +00:00
|
|
|
{ "address", std::make_shared<DataTypeString>() },
|
2017-04-01 07:20:54 +00:00
|
|
|
{ "port", std::make_shared<DataTypeUInt16>() },
|
|
|
|
|
|
|
|
{ "initial_user", std::make_shared<DataTypeString>() },
|
|
|
|
{ "initial_query_id", std::make_shared<DataTypeString>() },
|
2017-12-02 02:47:12 +00:00
|
|
|
{ "initial_address", std::make_shared<DataTypeString>() },
|
2017-04-01 07:20:54 +00:00
|
|
|
{ "initial_port", std::make_shared<DataTypeUInt16>() },
|
|
|
|
|
|
|
|
{ "interface", std::make_shared<DataTypeUInt8>() },
|
|
|
|
|
2017-12-02 02:47:12 +00:00
|
|
|
{ "os_user", std::make_shared<DataTypeString>() },
|
|
|
|
{ "client_hostname", std::make_shared<DataTypeString>() },
|
|
|
|
{ "client_name", std::make_shared<DataTypeString>() },
|
|
|
|
{ "client_version_major", std::make_shared<DataTypeUInt64>() },
|
|
|
|
{ "client_version_minor", std::make_shared<DataTypeUInt64>() },
|
|
|
|
{ "client_revision", std::make_shared<DataTypeUInt64>() },
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-12-02 02:47:12 +00:00
|
|
|
{ "http_method", std::make_shared<DataTypeUInt8>() },
|
|
|
|
{ "http_user_agent", std::make_shared<DataTypeString>() },
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
{ "quota_key", std::make_shared<DataTypeString>() },
|
|
|
|
|
2017-12-02 02:47:12 +00:00
|
|
|
{ "elapsed", std::make_shared<DataTypeFloat64>() },
|
2018-03-09 21:12:52 +00:00
|
|
|
{ "is_cancelled", std::make_shared<DataTypeUInt8>() },
|
2017-12-02 02:47:12 +00:00
|
|
|
{ "read_rows", std::make_shared<DataTypeUInt64>() },
|
|
|
|
{ "read_bytes", std::make_shared<DataTypeUInt64>() },
|
|
|
|
{ "total_rows_approx", std::make_shared<DataTypeUInt64>() },
|
|
|
|
{ "written_rows", std::make_shared<DataTypeUInt64>() },
|
|
|
|
{ "written_bytes", std::make_shared<DataTypeUInt64>() },
|
|
|
|
{ "memory_usage", std::make_shared<DataTypeInt64>() },
|
2018-03-09 23:09:28 +00:00
|
|
|
{ "peak_memory_usage", std::make_shared<DataTypeInt64>() },
|
2018-03-10 17:03:57 +00:00
|
|
|
{ "query", std::make_shared<DataTypeString>() },
|
2018-03-13 14:18:11 +00:00
|
|
|
}));
|
2018-03-01 16:52:24 +00:00
|
|
|
|
|
|
|
virtual_columns = ColumnsWithTypeAndName{
|
|
|
|
{
|
|
|
|
std::make_shared<DataTypeArray>(std::make_shared<DataTypeUInt32>()),
|
|
|
|
"thread_numbers"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
std::make_shared<DataTypeArray>(std::make_shared<DataTypeTuple>(
|
|
|
|
DataTypes{std::make_shared<DataTypeString>(), std::make_shared<DataTypeUInt64 >()})),
|
|
|
|
"profile_counters"
|
|
|
|
}
|
|
|
|
};
|
2013-09-03 20:21:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BlockInputStreams StorageSystemProcesses::read(
|
2017-04-01 07:20:54 +00:00
|
|
|
const Names & column_names,
|
2017-12-02 02:47:12 +00:00
|
|
|
const SelectQueryInfo &,
|
2017-04-01 07:20:54 +00:00
|
|
|
const Context & context,
|
|
|
|
QueryProcessingStage::Enum & processed_stage,
|
2017-12-02 02:47:12 +00:00
|
|
|
const size_t /*max_block_size*/,
|
|
|
|
const unsigned /*num_streams*/)
|
2013-09-03 20:21:28 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
processed_stage = QueryProcessingStage::FetchColumns;
|
|
|
|
|
2018-03-01 16:52:24 +00:00
|
|
|
auto virtual_columns_processor = getVirtualColumnsProcessor();
|
|
|
|
bool has_thread_numbers, has_profile_counters;
|
|
|
|
Names real_columns = virtual_columns_processor.process(column_names, {&has_thread_numbers, &has_profile_counters});
|
|
|
|
check(real_columns);
|
|
|
|
|
|
|
|
Block res_block = getSampleBlock().cloneEmpty();
|
|
|
|
virtual_columns_processor.appendVirtualColumns(res_block);
|
|
|
|
MutableColumns res_columns = res_block.cloneEmptyColumns();
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2018-03-01 16:52:24 +00:00
|
|
|
ProcessList::Info info = context.getProcessList().getInfo(has_thread_numbers, has_profile_counters);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
for (const auto & process : info)
|
|
|
|
{
|
|
|
|
size_t i = 0;
|
2017-12-16 00:49:03 +00:00
|
|
|
res_columns[i++]->insert(UInt64(process.client_info.query_kind == ClientInfo::QueryKind::INITIAL_QUERY));
|
|
|
|
res_columns[i++]->insert(process.client_info.current_user);
|
|
|
|
res_columns[i++]->insert(process.client_info.current_query_id);
|
|
|
|
res_columns[i++]->insert(process.client_info.current_address.host().toString());
|
|
|
|
res_columns[i++]->insert(UInt64(process.client_info.current_address.port()));
|
|
|
|
res_columns[i++]->insert(process.client_info.initial_user);
|
|
|
|
res_columns[i++]->insert(process.client_info.initial_query_id);
|
|
|
|
res_columns[i++]->insert(process.client_info.initial_address.host().toString());
|
|
|
|
res_columns[i++]->insert(UInt64(process.client_info.initial_address.port()));
|
|
|
|
res_columns[i++]->insert(UInt64(process.client_info.interface));
|
|
|
|
res_columns[i++]->insert(process.client_info.os_user);
|
|
|
|
res_columns[i++]->insert(process.client_info.client_hostname);
|
|
|
|
res_columns[i++]->insert(process.client_info.client_name);
|
|
|
|
res_columns[i++]->insert(process.client_info.client_version_major);
|
|
|
|
res_columns[i++]->insert(process.client_info.client_version_minor);
|
|
|
|
res_columns[i++]->insert(UInt64(process.client_info.client_revision));
|
|
|
|
res_columns[i++]->insert(UInt64(process.client_info.http_method));
|
|
|
|
res_columns[i++]->insert(process.client_info.http_user_agent);
|
|
|
|
res_columns[i++]->insert(process.client_info.quota_key);
|
|
|
|
res_columns[i++]->insert(process.elapsed_seconds);
|
2018-03-09 21:12:52 +00:00
|
|
|
res_columns[i++]->insert(UInt64(process.is_cancelled));
|
2017-12-16 00:49:03 +00:00
|
|
|
res_columns[i++]->insert(UInt64(process.read_rows));
|
|
|
|
res_columns[i++]->insert(UInt64(process.read_bytes));
|
|
|
|
res_columns[i++]->insert(UInt64(process.total_rows));
|
|
|
|
res_columns[i++]->insert(UInt64(process.written_rows));
|
|
|
|
res_columns[i++]->insert(UInt64(process.written_bytes));
|
|
|
|
res_columns[i++]->insert(process.memory_usage);
|
2018-03-09 23:09:28 +00:00
|
|
|
res_columns[i++]->insert(process.peak_memory_usage);
|
2017-12-16 00:49:03 +00:00
|
|
|
res_columns[i++]->insert(process.query);
|
2018-03-01 16:52:24 +00:00
|
|
|
|
|
|
|
if (has_thread_numbers)
|
|
|
|
{
|
|
|
|
Array thread_numbers;
|
|
|
|
thread_numbers.reserve(process.thread_numbers.size());
|
|
|
|
|
|
|
|
for (const UInt32 thread_number : process.thread_numbers)
|
|
|
|
thread_numbers.emplace_back(UInt64(thread_number));
|
|
|
|
|
|
|
|
res_columns[i++]->insert(std::move(thread_numbers));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_profile_counters)
|
|
|
|
{
|
|
|
|
Array profile_counters;
|
|
|
|
profile_counters.reserve(ProfileEvents::Counters::num_counters);
|
|
|
|
|
|
|
|
for (ProfileEvents::Event event = 0; event < ProfileEvents::Counters::num_counters; ++event)
|
|
|
|
{
|
|
|
|
Array name_and_counter{
|
|
|
|
String(ProfileEvents::getDescription(event)),
|
|
|
|
UInt64((*process.profile_counters)[event].load(std::memory_order_relaxed))
|
|
|
|
};
|
|
|
|
|
|
|
|
profile_counters.emplace_back(Tuple(std::move(name_and_counter)));
|
|
|
|
}
|
|
|
|
|
|
|
|
res_columns[i++]->insert(std::move(profile_counters));
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
|
2018-03-01 16:52:24 +00:00
|
|
|
return BlockInputStreams(1, std::make_shared<OneBlockInputStream>(res_block.cloneWithColumns(std::move(res_columns))));
|
2013-09-03 20:21:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|