2016-01-20 21:32:01 +00:00
|
|
|
#include <DB/Common/CurrentMetrics.h>
|
|
|
|
#include <DB/Columns/ColumnString.h>
|
|
|
|
#include <DB/DataTypes/DataTypeString.h>
|
|
|
|
#include <DB/DataTypes/DataTypesNumberFixed.h>
|
|
|
|
#include <DB/DataStreams/OneBlockInputStream.h>
|
|
|
|
#include <DB/Storages/System/StorageSystemMetrics.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
StorageSystemMetrics::StorageSystemMetrics(const std::string & name_)
|
|
|
|
: name(name_),
|
|
|
|
columns
|
|
|
|
{
|
2016-05-28 07:48:40 +00:00
|
|
|
{"metric", std::make_shared<DataTypeString>()},
|
|
|
|
{"value", std::make_shared<DataTypeInt64>()},
|
2016-01-20 21:32:01 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
StoragePtr StorageSystemMetrics::create(const std::string & name_)
|
|
|
|
{
|
2016-08-26 21:25:05 +00:00
|
|
|
return make_shared(name_);
|
2016-01-20 21:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BlockInputStreams StorageSystemMetrics::read(
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
check(column_names);
|
|
|
|
processed_stage = QueryProcessingStage::FetchColumns;
|
|
|
|
|
|
|
|
Block block;
|
|
|
|
|
|
|
|
ColumnWithTypeAndName col_metric;
|
|
|
|
col_metric.name = "metric";
|
2016-05-28 07:48:40 +00:00
|
|
|
col_metric.type = std::make_shared<DataTypeString>();
|
2016-05-28 05:31:36 +00:00
|
|
|
col_metric.column = std::make_shared<ColumnString>();
|
2016-01-20 21:32:01 +00:00
|
|
|
block.insert(col_metric);
|
|
|
|
|
|
|
|
ColumnWithTypeAndName col_value;
|
|
|
|
col_value.name = "value";
|
2016-05-28 07:48:40 +00:00
|
|
|
col_value.type = std::make_shared<DataTypeInt64>();
|
2016-05-28 05:31:36 +00:00
|
|
|
col_value.column = std::make_shared<ColumnInt64>();
|
2016-01-20 21:32:01 +00:00
|
|
|
block.insert(col_value);
|
|
|
|
|
2016-10-24 04:06:27 +00:00
|
|
|
for (size_t i = 0, end = CurrentMetrics::end(); i < end; ++i)
|
2016-01-20 21:32:01 +00:00
|
|
|
{
|
2016-07-31 03:53:16 +00:00
|
|
|
auto value = CurrentMetrics::values[i].load(std::memory_order_relaxed);
|
2016-01-20 21:32:01 +00:00
|
|
|
|
2016-01-21 01:47:28 +00:00
|
|
|
col_metric.column->insert(String(CurrentMetrics::getDescription(CurrentMetrics::Metric(i))));
|
|
|
|
col_value.column->insert(value);
|
2016-01-20 21:32:01 +00:00
|
|
|
}
|
|
|
|
|
2016-05-28 12:22:22 +00:00
|
|
|
return BlockInputStreams(1, std::make_shared<OneBlockInputStream>(block));
|
2016-01-20 21:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|