2013-09-03 20:21:28 +00:00
|
|
|
#include <DB/Columns/ColumnString.h>
|
|
|
|
#include <DB/DataTypes/DataTypeString.h>
|
2017-03-12 10:13:45 +00:00
|
|
|
#include <DB/DataTypes/DataTypesNumber.h>
|
2013-09-03 20:21:28 +00:00
|
|
|
#include <DB/DataStreams/OneBlockInputStream.h>
|
2015-06-21 06:06:04 +00:00
|
|
|
#include <DB/Interpreters/ProcessList.h>
|
2015-09-24 03:50:09 +00:00
|
|
|
#include <DB/Storages/System/StorageSystemProcesses.h>
|
2016-12-08 02:49:04 +00:00
|
|
|
#include <DB/Interpreters/Context.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_)
|
|
|
|
: name(name_)
|
2014-09-12 16:05:29 +00:00
|
|
|
, columns{
|
2016-10-24 21:40:39 +00:00
|
|
|
{ "is_initial_query", std::make_shared<DataTypeUInt8>() },
|
|
|
|
|
|
|
|
{ "user", std::make_shared<DataTypeString>() },
|
|
|
|
{ "query_id", std::make_shared<DataTypeString>() },
|
|
|
|
{ "address", std::make_shared<DataTypeString>() },
|
|
|
|
{ "port", std::make_shared<DataTypeUInt16>() },
|
|
|
|
|
|
|
|
{ "initial_user", std::make_shared<DataTypeString>() },
|
|
|
|
{ "initial_query_id", std::make_shared<DataTypeString>() },
|
|
|
|
{ "initial_address", std::make_shared<DataTypeString>() },
|
|
|
|
{ "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>() },
|
|
|
|
{ "client_version_major", std::make_shared<DataTypeUInt64>() },
|
|
|
|
{ "client_version_minor", std::make_shared<DataTypeUInt64>() },
|
|
|
|
{ "client_revision", std::make_shared<DataTypeUInt64>() },
|
|
|
|
|
|
|
|
{ "http_method", std::make_shared<DataTypeUInt8>() },
|
|
|
|
{ "http_user_agent", std::make_shared<DataTypeString>() },
|
|
|
|
|
2016-11-16 05:09:41 +00:00
|
|
|
{ "quota_key", std::make_shared<DataTypeString>() },
|
|
|
|
|
2016-10-24 21:40:39 +00:00
|
|
|
{ "elapsed", std::make_shared<DataTypeFloat64>() },
|
2016-12-06 20:55:13 +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>() },
|
2016-10-24 21:40:39 +00:00
|
|
|
{ "memory_usage", std::make_shared<DataTypeInt64>() },
|
2016-12-06 20:55:13 +00:00
|
|
|
{ "query", std::make_shared<DataTypeString>() }
|
2014-09-12 16:05:29 +00:00
|
|
|
}
|
2013-09-03 20:21:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-21 03:56:28 +00:00
|
|
|
StoragePtr StorageSystemProcesses::create(const std::string & name_)
|
2013-09-03 20:21:28 +00:00
|
|
|
{
|
2016-08-26 21:25:05 +00:00
|
|
|
return make_shared(name_);
|
2013-09-03 20:21:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BlockInputStreams StorageSystemProcesses::read(
|
2014-12-17 11:53:17 +00:00
|
|
|
const Names & column_names,
|
|
|
|
ASTPtr query,
|
|
|
|
const Context & context,
|
|
|
|
const Settings & settings,
|
|
|
|
QueryProcessingStage::Enum & processed_stage,
|
|
|
|
const size_t max_block_size,
|
|
|
|
const unsigned threads)
|
2013-09-03 20:21:28 +00:00
|
|
|
{
|
|
|
|
check(column_names);
|
|
|
|
processed_stage = QueryProcessingStage::FetchColumns;
|
|
|
|
|
2016-01-20 21:32:01 +00:00
|
|
|
ProcessList::Info info = context.getProcessList().getInfo();
|
|
|
|
|
2016-10-24 21:40:39 +00:00
|
|
|
Block block = getSampleBlock();
|
|
|
|
|
2016-01-20 21:32:01 +00:00
|
|
|
for (const auto & process : info)
|
2013-09-03 20:21:28 +00:00
|
|
|
{
|
2016-10-24 21:40:39 +00:00
|
|
|
size_t i = 0;
|
2017-01-02 20:12:12 +00:00
|
|
|
block.getByPosition(i++).column->insert(UInt64(process.client_info.query_kind == ClientInfo::QueryKind::INITIAL_QUERY));
|
|
|
|
block.getByPosition(i++).column->insert(process.client_info.current_user);
|
|
|
|
block.getByPosition(i++).column->insert(process.client_info.current_query_id);
|
|
|
|
block.getByPosition(i++).column->insert(process.client_info.current_address.host().toString());
|
|
|
|
block.getByPosition(i++).column->insert(UInt64(process.client_info.current_address.port()));
|
|
|
|
block.getByPosition(i++).column->insert(process.client_info.initial_user);
|
|
|
|
block.getByPosition(i++).column->insert(process.client_info.initial_query_id);
|
|
|
|
block.getByPosition(i++).column->insert(process.client_info.initial_address.host().toString());
|
|
|
|
block.getByPosition(i++).column->insert(UInt64(process.client_info.initial_address.port()));
|
|
|
|
block.getByPosition(i++).column->insert(UInt64(process.client_info.interface));
|
|
|
|
block.getByPosition(i++).column->insert(process.client_info.os_user);
|
|
|
|
block.getByPosition(i++).column->insert(process.client_info.client_hostname);
|
|
|
|
block.getByPosition(i++).column->insert(process.client_info.client_name);
|
|
|
|
block.getByPosition(i++).column->insert(process.client_info.client_version_major);
|
|
|
|
block.getByPosition(i++).column->insert(process.client_info.client_version_minor);
|
|
|
|
block.getByPosition(i++).column->insert(UInt64(process.client_info.client_revision));
|
|
|
|
block.getByPosition(i++).column->insert(UInt64(process.client_info.http_method));
|
|
|
|
block.getByPosition(i++).column->insert(process.client_info.http_user_agent);
|
|
|
|
block.getByPosition(i++).column->insert(process.client_info.quota_key);
|
|
|
|
block.getByPosition(i++).column->insert(process.elapsed_seconds);
|
|
|
|
block.getByPosition(i++).column->insert(process.read_rows);
|
|
|
|
block.getByPosition(i++).column->insert(process.read_bytes);
|
|
|
|
block.getByPosition(i++).column->insert(process.total_rows);
|
|
|
|
block.getByPosition(i++).column->insert(process.written_rows);
|
|
|
|
block.getByPosition(i++).column->insert(process.written_bytes);
|
|
|
|
block.getByPosition(i++).column->insert(process.memory_usage);
|
|
|
|
block.getByPosition(i++).column->insert(process.query);
|
2013-09-03 20:21:28 +00:00
|
|
|
}
|
2014-09-12 16:05:29 +00:00
|
|
|
|
2016-05-28 12:22:22 +00:00
|
|
|
return BlockInputStreams(1, std::make_shared<OneBlockInputStream>(block));
|
2013-09-03 20:21:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|