Metrics system scaffold
This commit is contained in:
63
src/metric.hpp
Normal file
63
src/metric.hpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include "arena_allocator.hpp"
|
||||
#include <initializer_list>
|
||||
#include <span>
|
||||
#include <string_view>
|
||||
#include <type_traits>
|
||||
|
||||
namespace metric {
|
||||
|
||||
struct Counter {
|
||||
void inc(double = 1.0);
|
||||
|
||||
private:
|
||||
Counter();
|
||||
friend struct Metric;
|
||||
struct State;
|
||||
State *p;
|
||||
};
|
||||
|
||||
struct Gauge {
|
||||
void inc(double = 1.0);
|
||||
void dec(double = 1.0);
|
||||
void set(double);
|
||||
|
||||
private:
|
||||
Gauge();
|
||||
friend struct Metric;
|
||||
struct State;
|
||||
State *p;
|
||||
};
|
||||
|
||||
struct Histogram {
|
||||
void observe(double);
|
||||
|
||||
private:
|
||||
Histogram();
|
||||
friend struct Metric;
|
||||
struct State;
|
||||
State *p;
|
||||
};
|
||||
|
||||
template <class T> struct Family {
|
||||
static_assert(std::is_same_v<T, Counter> || std::is_same_v<T, Gauge> ||
|
||||
std::is_same_v<T, Histogram>);
|
||||
T create(
|
||||
std::initializer_list<std::pair<std::string_view, std::string_view>>);
|
||||
|
||||
private:
|
||||
friend struct Metric;
|
||||
std::string_view name;
|
||||
std::string_view help;
|
||||
};
|
||||
|
||||
// All std::string_view's should point to static memory
|
||||
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