Metrics system scaffold
This commit is contained in:
64
src/metric.cpp
Normal file
64
src/metric.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
#include "metric.hpp"
|
||||
#include <mutex>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace metric {
|
||||
struct Counter::State {};
|
||||
struct Gauge::State {};
|
||||
struct Histogram::State {};
|
||||
struct Metric {
|
||||
|
||||
static std::mutex mutex;
|
||||
|
||||
struct MetricKey {
|
||||
std::string_view name;
|
||||
std::vector<std::pair<std::string, std::string>> labels;
|
||||
};
|
||||
|
||||
struct PerThreadState {
|
||||
std::unordered_map<MetricKey, Counter::State> counters;
|
||||
std::unordered_map<MetricKey, Histogram::State> histograms;
|
||||
};
|
||||
|
||||
static std::unordered_map<std::thread::id, PerThreadState> perThreadState;
|
||||
|
||||
struct ThreadInit {
|
||||
ThreadInit() {
|
||||
std::unique_lock<std::mutex> _{mutex};
|
||||
perThreadState[std::this_thread::get_id()] = {};
|
||||
}
|
||||
~ThreadInit() {
|
||||
std::unique_lock<std::mutex> _{mutex};
|
||||
perThreadState.erase(std::this_thread::get_id());
|
||||
}
|
||||
};
|
||||
static thread_local ThreadInit thread_init;
|
||||
};
|
||||
|
||||
void Counter::inc(double x) {}
|
||||
void Gauge::inc(double x) {}
|
||||
void Gauge::dec(double x) {}
|
||||
void Gauge::set(double x) {}
|
||||
void Histogram::observe(double x) {}
|
||||
|
||||
template <>
|
||||
Counter Family<Counter>::create(
|
||||
std::initializer_list<std::pair<std::string_view, std::string_view>>) {}
|
||||
template <>
|
||||
Gauge Family<Gauge>::create(
|
||||
std::initializer_list<std::pair<std::string_view, std::string_view>>) {}
|
||||
template <>
|
||||
Histogram Family<Histogram>::create(
|
||||
std::initializer_list<std::pair<std::string_view, std::string_view>>) {}
|
||||
|
||||
Family<Counter> create_counter(std::string_view name, std::string_view help) {}
|
||||
Family<Gauge> create_gauge(std::string_view name, std::string_view help) {}
|
||||
Family<Histogram> create_histogram(std::string_view name, std::string_view help,
|
||||
std::initializer_list<double> buckets) {}
|
||||
|
||||
std::span<std::string_view> render(ArenaAllocator &) {}
|
||||
|
||||
} // namespace metric
|
||||
Reference in New Issue
Block a user