2019-08-13 14:31:46 +00:00
|
|
|
#pragma once
|
2019-08-18 00:04:58 +00:00
|
|
|
|
2019-08-13 14:31:46 +00:00
|
|
|
#include <Interpreters/SystemLog.h>
|
2019-08-18 00:04:58 +00:00
|
|
|
#include <Common/ProfileEvents.h>
|
|
|
|
#include <Common/CurrentMetrics.h>
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <atomic>
|
|
|
|
#include <ctime>
|
|
|
|
|
2019-08-13 14:31:46 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2019-08-18 00:04:58 +00:00
|
|
|
/** MetricLog is a log of metric values measured at regular time interval.
|
|
|
|
*/
|
2019-08-13 14:31:46 +00:00
|
|
|
|
|
|
|
struct MetricLogElement
|
|
|
|
{
|
|
|
|
time_t event_time{};
|
2019-08-15 16:09:43 +00:00
|
|
|
UInt64 milliseconds{};
|
2019-08-13 14:47:19 +00:00
|
|
|
|
2019-08-18 00:04:58 +00:00
|
|
|
std::vector<ProfileEvents::Count> profile_events;
|
|
|
|
std::vector<CurrentMetrics::Metric> current_metrics;
|
|
|
|
|
2019-08-13 14:31:46 +00:00
|
|
|
static std::string name() { return "MetricLog"; }
|
|
|
|
static Block createBlock();
|
|
|
|
void appendToBlock(Block & block) const;
|
|
|
|
};
|
|
|
|
|
2019-08-18 00:04:58 +00:00
|
|
|
|
2019-08-13 14:31:46 +00:00
|
|
|
class MetricLog : public SystemLog<MetricLogElement>
|
|
|
|
{
|
|
|
|
using SystemLog<MetricLogElement>::SystemLog;
|
2019-08-13 16:47:12 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
/// Launches a background thread to collect metrics with interval
|
|
|
|
void startCollectMetric(size_t collect_interval_milliseconds_);
|
|
|
|
|
|
|
|
/// Stop background thread. Call before shutdown.
|
|
|
|
void stopCollectMetric();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void metricThreadFunction();
|
|
|
|
|
|
|
|
ThreadFromGlobalPool metric_flush_thread;
|
|
|
|
size_t collect_interval_milliseconds;
|
|
|
|
std::atomic<bool> is_shutdown_metric_thread{false};
|
2019-08-13 14:31:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|