1#pragma once
2
3#include <condition_variable>
4#include <mutex>
5#include <string>
6#include <thread>
7#include <vector>
8#include <optional>
9#include <Core/Types.h>
10#include <Common/ThreadPool.h>
11#include <Common/ProfileEvents.h>
12
13
14namespace Poco
15{
16 namespace Util
17 {
18 class AbstractConfiguration;
19 }
20}
21
22namespace DB
23{
24
25class AsynchronousMetrics;
26
27
28/** Automatically sends
29 * - delta values of ProfileEvents;
30 * - cumulative values of ProfileEvents;
31 * - values of CurrentMetrics;
32 * - values of AsynchronousMetrics;
33 * to Graphite at beginning of every minute.
34 */
35class MetricsTransmitter
36{
37public:
38 MetricsTransmitter(const Poco::Util::AbstractConfiguration & config, const std::string & config_name_, const AsynchronousMetrics & async_metrics_);
39 ~MetricsTransmitter();
40
41private:
42 void run();
43 void transmit(std::vector<ProfileEvents::Count> & prev_counters);
44
45 const AsynchronousMetrics & async_metrics;
46
47 std::string config_name;
48 UInt32 interval_seconds;
49 bool send_events;
50 bool send_events_cumulative;
51 bool send_metrics;
52 bool send_asynchronous_metrics;
53
54 bool quit = false;
55 std::mutex mutex;
56 std::condition_variable cond;
57 std::optional<ThreadFromGlobalPool> thread;
58
59 static inline constexpr auto profile_events_path_prefix = "ClickHouse.ProfileEvents.";
60 static inline constexpr auto profile_events_cumulative_path_prefix = "ClickHouse.ProfileEventsCumulative.";
61 static inline constexpr auto current_metrics_path_prefix = "ClickHouse.Metrics.";
62 static inline constexpr auto asynchronous_metrics_path_prefix = "ClickHouse.AsynchronousMetrics.";
63};
64
65}
66