2017-04-01 09:19:00 +00:00
|
|
|
#include <DataTypes/DataTypeString.h>
|
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
2018-03-01 16:52:24 +00:00
|
|
|
#include <DataTypes/DataTypeArray.h>
|
2021-01-21 04:15:44 +00:00
|
|
|
#include <DataTypes/DataTypeMap.h>
|
2019-06-15 14:20:32 +00:00
|
|
|
#include <DataTypes/DataTypeFactory.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Interpreters/ProcessList.h>
|
|
|
|
#include <Storages/System/StorageSystemProcesses.h>
|
|
|
|
#include <Interpreters/Context.h>
|
2019-03-22 12:08:30 +00:00
|
|
|
#include <Core/Settings.h>
|
2018-06-20 17:49:52 +00:00
|
|
|
#include <Interpreters/ProfileEventsExt.h>
|
2018-05-17 16:01:41 +00:00
|
|
|
#include <Common/typeid_cast.h>
|
2019-06-15 14:20:32 +00:00
|
|
|
#include <Common/IPv6ToBinary.h>
|
2018-05-17 16:01:41 +00:00
|
|
|
#include <Columns/ColumnsNumber.h>
|
|
|
|
#include <Columns/ColumnArray.h>
|
2013-09-03 20:21:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2018-07-24 14:28:56 +00:00
|
|
|
NamesAndTypesList StorageSystemProcesses::getNamesAndTypes()
|
2018-01-25 14:42:39 +00:00
|
|
|
{
|
2018-07-24 14:28:56 +00:00
|
|
|
return {
|
|
|
|
{"is_initial_query", std::make_shared<DataTypeUInt8>()},
|
|
|
|
|
|
|
|
{"user", std::make_shared<DataTypeString>()},
|
|
|
|
{"query_id", std::make_shared<DataTypeString>()},
|
2019-06-15 14:20:32 +00:00
|
|
|
{"address", DataTypeFactory::instance().get("IPv6")},
|
2018-07-24 14:28:56 +00:00
|
|
|
{"port", std::make_shared<DataTypeUInt16>()},
|
|
|
|
|
|
|
|
{"initial_user", std::make_shared<DataTypeString>()},
|
|
|
|
{"initial_query_id", std::make_shared<DataTypeString>()},
|
2019-06-15 14:20:32 +00:00
|
|
|
{"initial_address", DataTypeFactory::instance().get("IPv6")},
|
2018-07-24 14:28:56 +00:00
|
|
|
{"initial_port", std::make_shared<DataTypeUInt16>()},
|
|
|
|
|
|
|
|
{"interface", std::make_shared<DataTypeUInt8>()},
|
|
|
|
|
|
|
|
{"os_user", std::make_shared<DataTypeString>()},
|
|
|
|
{"client_hostname", std::make_shared<DataTypeString>()},
|
|
|
|
{"client_name", std::make_shared<DataTypeString>()},
|
2019-06-15 14:20:32 +00:00
|
|
|
{"client_revision", std::make_shared<DataTypeUInt64>()},
|
2018-07-24 14:28:56 +00:00
|
|
|
{"client_version_major", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"client_version_minor", std::make_shared<DataTypeUInt64>()},
|
2018-07-31 21:36:18 +00:00
|
|
|
{"client_version_patch", std::make_shared<DataTypeUInt64>()},
|
2018-07-24 14:28:56 +00:00
|
|
|
|
|
|
|
{"http_method", std::make_shared<DataTypeUInt8>()},
|
|
|
|
{"http_user_agent", std::make_shared<DataTypeString>()},
|
2021-01-21 22:55:45 +00:00
|
|
|
{"http_referer", std::make_shared<DataTypeString>()},
|
2020-12-01 21:07:20 +00:00
|
|
|
{"forwarded_for", std::make_shared<DataTypeString>()},
|
2018-07-24 14:28:56 +00:00
|
|
|
|
|
|
|
{"quota_key", std::make_shared<DataTypeString>()},
|
|
|
|
|
|
|
|
{"elapsed", std::make_shared<DataTypeFloat64>()},
|
|
|
|
{"is_cancelled", std::make_shared<DataTypeUInt8>()},
|
|
|
|
{"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>()},
|
|
|
|
{"peak_memory_usage", std::make_shared<DataTypeInt64>()},
|
|
|
|
{"query", std::make_shared<DataTypeString>()},
|
2018-08-14 20:29:42 +00:00
|
|
|
|
2020-02-02 20:01:13 +00:00
|
|
|
{"thread_ids", std::make_shared<DataTypeArray>(std::make_shared<DataTypeUInt64>())},
|
2021-01-21 04:15:44 +00:00
|
|
|
{"ProfileEvents", std::make_shared<DataTypeMap>(std::make_shared<DataTypeString>(), std::make_shared<DataTypeUInt64>())},
|
|
|
|
{"Settings", std::make_shared<DataTypeMap>(std::make_shared<DataTypeString>(), std::make_shared<DataTypeString>())},
|
2021-03-30 13:35:33 +00:00
|
|
|
|
|
|
|
{"current_database", std::make_shared<DataTypeString>()},
|
2018-07-24 14:28:56 +00:00
|
|
|
};
|
2013-09-03 20:21:28 +00:00
|
|
|
}
|
|
|
|
|
2021-06-28 11:42:21 +00:00
|
|
|
NamesAndAliases StorageSystemProcesses::getNamesAndAliases()
|
|
|
|
{
|
|
|
|
return
|
|
|
|
{
|
|
|
|
{"ProfileEvents.Names", {std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>())}, "mapKeys(ProfileEvents)"},
|
|
|
|
{"ProfileEvents.Values", {std::make_shared<DataTypeArray>(std::make_shared<DataTypeUInt64>())}, "mapValues(ProfileEvents)"}
|
|
|
|
};
|
|
|
|
}
|
2013-09-03 20:21:28 +00:00
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
void StorageSystemProcesses::fillData(MutableColumns & res_columns, ContextPtr context, const SelectQueryInfo &) const
|
2013-09-03 20:21:28 +00:00
|
|
|
{
|
2021-04-10 23:33:54 +00:00
|
|
|
ProcessList::Info info = context->getProcessList().getInfo(true, true, true);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
for (const auto & process : info)
|
|
|
|
{
|
|
|
|
size_t i = 0;
|
2019-06-15 14:20:32 +00:00
|
|
|
|
2018-10-22 08:54:54 +00:00
|
|
|
res_columns[i++]->insert(process.client_info.query_kind == ClientInfo::QueryKind::INITIAL_QUERY);
|
2019-06-15 14:20:32 +00:00
|
|
|
|
2017-12-16 00:49:03 +00:00
|
|
|
res_columns[i++]->insert(process.client_info.current_user);
|
|
|
|
res_columns[i++]->insert(process.client_info.current_query_id);
|
2019-06-15 14:20:32 +00:00
|
|
|
res_columns[i++]->insertData(IPv6ToBinary(process.client_info.current_address.host()).data(), 16);
|
2018-10-22 08:54:54 +00:00
|
|
|
res_columns[i++]->insert(process.client_info.current_address.port());
|
2019-06-15 14:20:32 +00:00
|
|
|
|
2017-12-16 00:49:03 +00:00
|
|
|
res_columns[i++]->insert(process.client_info.initial_user);
|
|
|
|
res_columns[i++]->insert(process.client_info.initial_query_id);
|
2019-06-15 14:20:32 +00:00
|
|
|
res_columns[i++]->insertData(IPv6ToBinary(process.client_info.initial_address.host()).data(), 16);
|
2018-10-22 08:54:54 +00:00
|
|
|
res_columns[i++]->insert(process.client_info.initial_address.port());
|
2019-06-15 14:20:32 +00:00
|
|
|
|
2017-12-16 00:49:03 +00:00
|
|
|
res_columns[i++]->insert(UInt64(process.client_info.interface));
|
2019-06-15 14:20:32 +00:00
|
|
|
|
2017-12-16 00:49:03 +00:00
|
|
|
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);
|
2020-09-17 12:15:05 +00:00
|
|
|
res_columns[i++]->insert(process.client_info.client_tcp_protocol_version);
|
2017-12-16 00:49:03 +00:00
|
|
|
res_columns[i++]->insert(process.client_info.client_version_major);
|
|
|
|
res_columns[i++]->insert(process.client_info.client_version_minor);
|
2018-07-31 21:36:18 +00:00
|
|
|
res_columns[i++]->insert(process.client_info.client_version_patch);
|
2019-06-15 14:20:32 +00:00
|
|
|
|
2017-12-16 00:49:03 +00:00
|
|
|
res_columns[i++]->insert(UInt64(process.client_info.http_method));
|
|
|
|
res_columns[i++]->insert(process.client_info.http_user_agent);
|
2021-01-21 22:55:45 +00:00
|
|
|
res_columns[i++]->insert(process.client_info.http_referer);
|
2020-12-01 21:07:20 +00:00
|
|
|
res_columns[i++]->insert(process.client_info.forwarded_for);
|
2019-06-15 14:20:32 +00:00
|
|
|
|
2017-12-16 00:49:03 +00:00
|
|
|
res_columns[i++]->insert(process.client_info.quota_key);
|
2019-06-15 14:20:32 +00:00
|
|
|
|
2017-12-16 00:49:03 +00:00
|
|
|
res_columns[i++]->insert(process.elapsed_seconds);
|
2018-10-22 08:54:54 +00:00
|
|
|
res_columns[i++]->insert(process.is_cancelled);
|
|
|
|
res_columns[i++]->insert(process.read_rows);
|
|
|
|
res_columns[i++]->insert(process.read_bytes);
|
|
|
|
res_columns[i++]->insert(process.total_rows);
|
|
|
|
res_columns[i++]->insert(process.written_rows);
|
|
|
|
res_columns[i++]->insert(process.written_bytes);
|
2017-12-16 00:49:03 +00:00
|
|
|
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
|
|
|
|
|
|
|
{
|
2018-05-17 16:01:41 +00:00
|
|
|
Array threads_array;
|
2020-02-02 02:27:15 +00:00
|
|
|
threads_array.reserve(process.thread_ids.size());
|
2020-02-02 20:01:13 +00:00
|
|
|
for (const UInt64 thread_id : process.thread_ids)
|
2020-02-02 02:27:15 +00:00
|
|
|
threads_array.emplace_back(thread_id);
|
2019-08-31 21:47:15 +00:00
|
|
|
res_columns[i++]->insert(threads_array);
|
|
|
|
}
|
2018-03-01 16:52:24 +00:00
|
|
|
|
2018-05-17 16:01:41 +00:00
|
|
|
{
|
2021-01-05 10:10:19 +00:00
|
|
|
IColumn * column = res_columns[i++].get();
|
2018-06-20 17:49:52 +00:00
|
|
|
|
|
|
|
if (process.profile_counters)
|
2021-01-05 10:10:19 +00:00
|
|
|
ProfileEvents::dumpToMapColumn(*process.profile_counters, column, true);
|
2018-06-20 17:49:52 +00:00
|
|
|
else
|
|
|
|
{
|
2021-01-05 10:10:19 +00:00
|
|
|
column->insertDefault();
|
2018-06-20 17:49:52 +00:00
|
|
|
}
|
2018-03-01 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-01-05 10:10:19 +00:00
|
|
|
IColumn * column = res_columns[i++].get();
|
2018-03-01 16:52:24 +00:00
|
|
|
|
2018-05-17 16:01:41 +00:00
|
|
|
if (process.query_settings)
|
2021-01-05 10:10:19 +00:00
|
|
|
process.query_settings->dumpToMapColumn(column, true);
|
2018-05-17 16:01:41 +00:00
|
|
|
else
|
2018-03-01 16:52:24 +00:00
|
|
|
{
|
2021-01-05 10:10:19 +00:00
|
|
|
column->insertDefault();
|
2018-03-01 16:52:24 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-30 13:35:33 +00:00
|
|
|
|
|
|
|
res_columns[i++]->insert(process.current_database);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2013-09-03 20:21:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|