Skip to main content

Summary

Struct Summary 

Source
pub struct Summary { /* private fields */ }
Expand description

Summary 指标,基于排序数组计算分位数。

与 Prometheus Summary 类似,记录所有观测值并按需计算分位数。 适合样本量可控的场景;超大规模样本应考虑 T-Digest 近似算法。

Implementations§

Source§

impl Summary

Source

pub fn new( name: impl Into<String>, help: impl Into<String>, quantiles: Vec<f64>, ) -> Self

创建新的 Summary 指标

§参数
  • name:指标名(如 request_duration_seconds
  • help:帮助文本
  • quantiles:要计算的分位数列表(如 [0.5, 0.9, 0.99]
Source

pub fn observe(&self, value: f64)

观测一个值

Source

pub fn quantile(&self, q: f64) -> Option<f64>

计算指定分位数的值(0.0..=1.0)

使用最近排名法(Nearest Rank):rank = ceil(p * n),至少为 1。 返回 None 表示无样本或分位数超出范围。

Source

pub fn quantiles(&self) -> Vec<(f64, Option<f64>)>

计算所有预配置分位数,返回 (分位数, 值) 列表

Source

pub fn count(&self) -> u64

样本计数

Source

pub fn sum(&self) -> f64

样本总和

Source

pub fn name(&self) -> &str

指标名

Source

pub fn render(&self) -> String

渲染为 Prometheus 文本格式

Source

pub fn reset(&self)

重置所有样本

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.