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{};
|
2020-11-03 13:59:17 +00:00
|
|
|
Decimal64 event_time_microseconds{};
|
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"; }
|
2021-06-28 11:42:21 +00:00
|
|
|
static NamesAndTypesList getNamesAndTypes();
|
|
|
|
static NamesAndAliases getNamesAndAliases() { return {}; }
|
2020-05-21 20:15:18 +00:00
|
|
|
void appendToBlock(MutableColumns & columns) const;
|
2019-08-13 14:31:46 +00:00
|
|
|
};
|
|
|
|
|
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:
|
2020-04-13 01:33:05 +00:00
|
|
|
void shutdown() override;
|
|
|
|
|
2019-08-13 16:47:12 +00:00
|
|
|
/// 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
|
|
|
};
|
|
|
|
|
|
|
|
}
|