2016-10-24 04:06:27 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <thread>
|
|
|
|
#include <mutex>
|
|
|
|
#include <condition_variable>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <string>
|
2019-01-14 19:22:09 +00:00
|
|
|
#include <Common/ThreadPool.h>
|
2020-04-19 20:49:13 +00:00
|
|
|
#include <Common/MemoryStatisticsOS.h>
|
2016-10-24 04:06:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class Context;
|
|
|
|
|
|
|
|
|
|
|
|
/** Periodically (each minute, starting at 30 seconds offset)
|
|
|
|
* calculates and updates some metrics,
|
|
|
|
* that are not updated automatically (so, need to be asynchronously calculated).
|
|
|
|
*/
|
|
|
|
class AsynchronousMetrics
|
|
|
|
{
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
AsynchronousMetrics(Context & context_)
|
|
|
|
: context(context_), thread([this] { run(); })
|
|
|
|
{
|
|
|
|
}
|
2016-10-24 04:06:27 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
~AsynchronousMetrics();
|
2016-10-24 04:06:27 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
using Value = double;
|
|
|
|
using Container = std::unordered_map<std::string, Value>;
|
2016-10-24 04:06:27 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Returns copy of all values.
|
|
|
|
Container getValues() const;
|
2016-10-24 04:06:27 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
Context & context;
|
2016-10-24 04:06:27 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
bool quit {false};
|
|
|
|
std::mutex wait_mutex;
|
|
|
|
std::condition_variable wait_cond;
|
2016-10-24 04:06:27 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Container container;
|
|
|
|
mutable std::mutex container_mutex;
|
2016-10-24 04:06:27 +00:00
|
|
|
|
2020-04-21 18:49:19 +00:00
|
|
|
#if defined(OS_LINUX)
|
2020-04-19 20:49:13 +00:00
|
|
|
MemoryStatisticsOS memory_stat;
|
2020-04-21 18:49:19 +00:00
|
|
|
#endif
|
|
|
|
|
2019-01-14 19:22:09 +00:00
|
|
|
ThreadFromGlobalPool thread;
|
2016-10-24 04:06:27 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void run();
|
|
|
|
void update();
|
2016-10-24 04:06:27 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void set(const std::string & name, Value value);
|
2016-10-24 04:06:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|