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>
|
2023-04-06 17:00:51 +00:00
|
|
|
#include <Common/ThreadPool_fwd.h>
|
2022-01-10 19:01:41 +00:00
|
|
|
#include <Core/NamesAndTypes.h>
|
|
|
|
#include <Core/NamesAndAliases.h>
|
2024-01-12 15:39:22 +00:00
|
|
|
#include <Storages/ColumnsDescription.h>
|
2019-08-18 00:04:58 +00:00
|
|
|
|
|
|
|
#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-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"; }
|
2024-01-12 15:39:22 +00:00
|
|
|
static ColumnsDescription getColumnsDescription();
|
2021-06-28 11:42:21 +00:00
|
|
|
static NamesAndAliases getNamesAndAliases() { return {}; }
|
2020-05-21 20:15:18 +00:00
|
|
|
void appendToBlock(MutableColumns & columns) const;
|
2022-04-17 21:49:39 +00:00
|
|
|
static const char * getCustomColumnList() { return nullptr; }
|
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();
|
|
|
|
|
2023-04-06 17:00:51 +00:00
|
|
|
std::unique_ptr<ThreadFromGlobalPool> metric_flush_thread;
|
2019-08-13 16:47:12 +00:00
|
|
|
size_t collect_interval_milliseconds;
|
|
|
|
std::atomic<bool> is_shutdown_metric_thread{false};
|
2019-08-13 14:31:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|