Skip to main content

LabeledHistogram

Struct LabeledHistogram 

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

带标签的 Histogram 扩展。

标准 crate::Histogram 不支持在同一指标名下按标签区分。 LabeledHistogram 通过标签集合区分同一指标名的不同时间序列。

Implementations§

Source§

impl LabeledHistogram

Source

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

创建带标签的直方图

§参数
  • name:指标名
  • help:帮助文本
  • buckets:bucket 边界(无需包含 +Inf,会自动追加)
Source

pub fn observe(&self, labels: &HashMap<String, String>, value: f64)

观测一个带标签的值

§参数
  • labels:标签键值对(顺序无关,内部会排序)
  • value:观测值
Source

pub fn count(&self, labels: &HashMap<String, String>) -> u64

获取指定标签组合的样本计数

Source

pub fn label_combination_count(&self) -> usize

获取所有标签组合数量

Source

pub fn render(&self) -> String

渲染为 Prometheus 文本格式

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, !>

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.