50 {0.1, 0.5, 1.0, 2.0, 5.0, 10.0, 25.0, 50.0, 100.0, 250.0, 500.0, 1000.0, 2500.0, 5000.0,
66 std::vector<std::pair<double, uint64_t>>
buckets;
67 std::map<std::string, std::string>
labels;
74 [[nodiscard]]
auto to_prometheus(
const std::string& name)
const -> std::string;
80 [[nodiscard]]
auto to_json() const -> std::
string;
134 void record(
double value);
140 [[nodiscard]]
auto count() const -> uint64_t;
146 [[nodiscard]] auto
sum() const ->
double;
152 [[nodiscard]] auto min() const ->
double;
158 [[nodiscard]] auto max() const ->
double;
164 [[nodiscard]] auto mean() const ->
double;
173 [[nodiscard]] auto percentile(
double p) const ->
double;
179 [[nodiscard]] auto p50() const ->
double {
return percentile(0.50); }
185 [[nodiscard]]
auto p95() const ->
double {
return percentile(0.95); }
191 [[nodiscard]]
auto p99() const ->
double {
return percentile(0.99); }
197 [[nodiscard]]
auto p999() const ->
double {
return percentile(0.999); }
203 [[nodiscard]]
auto buckets() const -> std::vector<std::pair<
double, uint64_t>>;
210 [[nodiscard]] auto snapshot(const std::map<std::
string, std::
string>&
labels = {})
const
211 -> histogram_snapshot;
223 size_t bucket_count_{0};
224 std::atomic<uint64_t> count_{0};
225 std::atomic<double> sum_{0.0};
226 std::atomic<double> min_{std::numeric_limits<double>::infinity()};
227 std::atomic<double> max_{-std::numeric_limits<double>::infinity()};
235 [[nodiscard]]
auto find_bucket(
double value)
const -> size_t;
241 void update_min(
double value);
247 void update_max(
double value);
253 void add_to_sum(
double value);
Thread-safe histogram for capturing value distributions.
histogram(const histogram &)=delete
auto p999() const -> double
Get 99.9th percentile.
auto p99() const -> double
Get 99th percentile.
auto operator=(const histogram &) -> histogram &=delete
std::vector< double > boundaries_
auto p95() const -> double
Get 95th percentile.
std::unique_ptr< std::atomic< uint64_t >[]> bucket_counts_
~histogram()=default
Destructor.
Configuration for histogram bucket boundaries.
std::vector< double > bucket_boundaries
Explicit bucket boundaries (upper bounds)
static auto default_latency_config() -> histogram_config
Create default configuration for network latencies.
Immutable snapshot of histogram state for export.
std::map< double, double > percentiles
Percentile -> value mapping.
std::map< std::string, std::string > labels
Additional metric labels.
uint64_t count
Total number of observations.
auto to_json() const -> std::string
Export histogram as JSON.
double sum
Sum of all observed values.
double min_value
Minimum observed value.
std::vector< std::pair< double, uint64_t > > buckets
Boundary -> cumulative count.
auto to_prometheus(const std::string &name) const -> std::string
Export histogram in Prometheus format.
double max_value
Maximum observed value.