44 std::chrono::seconds{60}, 6};
101 [[nodiscard]]
auto count() const -> uint64_t;
107 [[nodiscard]] auto
sum() const ->
double;
113 [[nodiscard]] auto
mean() const ->
double;
120 [[nodiscard]] auto
percentile(
double p) const ->
double;
151 [[nodiscard]]
auto snapshot(
const std::map<std::string, std::string>& labels = {})
const
152 -> histogram_snapshot;
Thread-safe histogram for capturing value distributions.
Time-windowed histogram for tracking recent latency distributions.
auto percentile(double p) const -> double
Calculate percentile value for current window.
void reset()
Reset all data.
sliding_histogram_config config_
std::chrono::milliseconds bucket_duration_
auto mean() const -> double
Get mean of all observations in current window.
auto operator=(const sliding_histogram &) -> sliding_histogram &=delete
auto p50() const -> double
Get 50th percentile (median) for current window.
std::deque< std::unique_ptr< time_bucket > > buckets_
void expire_old_buckets()
Expire old buckets outside the window.
auto aggregate() const -> histogram_snapshot
Create aggregated histogram from all buckets.
auto sum() const -> double
Get sum of all observations in current window.
auto count() const -> uint64_t
Get total number of observations in current window.
auto p99() const -> double
Get 99th percentile for current window.
auto p95() const -> double
Get 95th percentile for current window.
void record(double value)
Record a value observation.
~sliding_histogram()=default
Destructor.
sliding_histogram(sliding_histogram_config cfg=sliding_histogram_config::default_config())
Construct sliding histogram with configuration.
auto get_current_bucket() -> time_bucket &
Get or create current time bucket.
auto window_duration() const -> std::chrono::seconds
Get the window duration.
sliding_histogram(const sliding_histogram &)=delete
auto snapshot(const std::map< std::string, std::string > &labels={}) const -> histogram_snapshot
Create snapshot aggregating all time buckets in current window.
auto p999() const -> double
Get 99.9th percentile for current window.
Histogram metric implementation for latency distribution tracking.
Configuration for histogram bucket boundaries.
static auto default_latency_config() -> histogram_config
Create default configuration for network latencies.
Immutable snapshot of histogram state for export.
std::chrono::steady_clock::time_point start_time
time_bucket(const histogram_config &cfg)
Configuration for sliding window histogram.
std::chrono::seconds window_duration
Total window duration.
static auto default_config() -> sliding_histogram_config
Create default configuration (60 second window, 6 buckets = 10s each)
size_t bucket_count
Number of time buckets.
histogram_config hist_config
Histogram bucket configuration.