Metrics system scaffold

This commit is contained in:
2025-08-28 17:04:53 -04:00
parent ed6e6ea9fe
commit 9c89eba6c8
2 changed files with 127 additions and 0 deletions

64
src/metric.cpp Normal file
View 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