ClickHouse/src/Interpreters/MetricLog.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

59 lines
1.4 KiB
C++
Raw Normal View History

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 <Common/ThreadPool_fwd.h>
#include <Core/NamesAndTypes.h>
#include <Core/NamesAndAliases.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"; }
static NamesAndTypesList getNamesAndTypes();
static NamesAndAliases getNamesAndAliases() { return {}; }
void appendToBlock(MutableColumns & columns) const;
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();
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
};
}