#pragma once #include #include #include #include #define SYSTEM_PERIODIC_LOG_ELEMENTS(M) \ M(ErrorLogElement) \ M(MetricLogElement) namespace DB { template class PeriodicLog : public SystemLog { using SystemLog::SystemLog; using Base = SystemLog; public: using TimePoint = std::chrono::system_clock::time_point; /// Launches a background thread to collect metrics with periodic interval void startCollect(const String & thread_name, size_t collect_interval_milliseconds_); void shutdown() final; protected: /// Stop background thread void stopCollect(); virtual void stepFunction(TimePoint current_time) = 0; private: void threadFunction(); std::unique_ptr collecting_thread; size_t collect_interval_milliseconds; std::atomic is_shutdown_metric_thread{false}; }; }