changes after review

This commit is contained in:
Nikita Mikhaylov 2019-08-14 15:54:41 +03:00
parent a3d4fbd07d
commit 15bbf080f3
4 changed files with 22 additions and 13 deletions

View File

@ -329,6 +329,15 @@
<table>text_log</table>
<flush_interval_milliseconds>7500</flush_interval_milliseconds>
</text_log>
<!-- Uncomment to write metric log into table.
Metric log contains rows with current values of ProfileEvents, CurrentMetrics collected with "collect_interval_milliseconds" interval.
<metric_log>
<database>system</database>
<table>metric_log</table>
<flush_interval_milliseconds>7500</flush_interval_milliseconds>
<collect_interval_milliseconds>1000</collect_interval_milliseconds>
</metric_log>
-->
<!-- Parameters for embedded dictionaries, used in Yandex.Metrica.

View File

@ -11,8 +11,8 @@ Block MetricLogElement::createBlock()
{
ColumnsWithTypeAndName columns_with_type_and_name;
columns_with_type_and_name.emplace_back(std::make_shared<DataTypeDate>(), "event_date");
columns_with_type_and_name.emplace_back(std::make_shared<DataTypeDateTime>(), "event_time");
columns_with_type_and_name.emplace_back(DataTypeDate(), "event_date");
columns_with_type_and_name.emplace_back(DataTypeDateTime(), "event_time");
//ProfileEvents
for (size_t i = 0, end = ProfileEvents::end(); i < end; ++i)
@ -20,7 +20,7 @@ Block MetricLogElement::createBlock()
std::string name;
name += "ProfileEvent_";
name += ProfileEvents::getName(ProfileEvents::Event(i));
columns_with_type_and_name.emplace_back(std::make_shared<DataTypeUInt64>(), name);
columns_with_type_and_name.emplace_back(DataTypeUInt64(), name);
}
//CurrentMetrics
@ -29,7 +29,7 @@ Block MetricLogElement::createBlock()
std::string name;
name += "CurrentMetric_";
name += CurrentMetrics::getName(ProfileEvents::Event(i));
columns_with_type_and_name.emplace_back(std::make_shared<DataTypeInt64>(), name);
columns_with_type_and_name.emplace_back(DataTypeInt64(), name);
}
return Block(columns_with_type_and_name);
@ -47,7 +47,7 @@ void MetricLogElement::appendToBlock(Block & block) const
//ProfileEvents
for (size_t i = 0, end = ProfileEvents::end(); i < end; ++i)
{
const UInt64 value = ProfileEvents::global_counters[i];
const UInt64 value = ProfileEvents::global_counters[i].load(std::memory_order_relaxed);
columns[iter++]->insert(value);
}
@ -76,21 +76,22 @@ void MetricLog::stopCollectMetric()
void MetricLog::metricThreadFunction()
{
auto desired_timepoint = std::chrono::system_clock::now();
while (true)
{
try
{
const auto prev_timepoint = std::chrono::system_clock::now();
const auto prev_timepoint = desired_timepoint;
if (is_shutdown_metric_thread)
break;
MetricLogElement elem;
elem.event_time = std::time(nullptr);
elem.event_time = std::chrono::system_clock::to_time_t(prev_timepoint);
this->add(elem);
const auto next_timepoint = prev_timepoint + std::chrono::milliseconds(collect_interval_milliseconds);
std::this_thread::sleep_until(next_timepoint);
desired_timepoint = prev_timepoint + std::chrono::milliseconds(collect_interval_milliseconds);
std::this_thread::sleep_until(desired_timepoint);
}
catch (...)
{

View File

@ -53,8 +53,7 @@ SystemLogs::SystemLogs(Context & global_context, const Poco::Util::AbstractConfi
if (metric_log)
{
constexpr size_t DEFAULT_METRIC_LOG_COLLECT_INTERVAL_MILLISECONDS = 1000;
size_t collect_interval_milliseconds = config.getUInt64("metric_log.collect_interval_milliseconds", DEFAULT_METRIC_LOG_COLLECT_INTERVAL_MILLISECONDS);
size_t collect_interval_milliseconds = config.getUInt64("metric_log.collect_interval_milliseconds");
metric_log->startCollectMetric(collect_interval_milliseconds);
}

View File

@ -1,5 +1,5 @@
select sleep(2) format Null;
select sleep(2) format Null; --More than collect_interval_milliseconds
system flush logs;
select count()>0 from system.metric_log
select count()>0 from system.metric_log