Skip to main content

PushgatewayExporter

Struct PushgatewayExporter 

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

Pushgateway 导出器。

将指标推送到 Prometheus Pushgateway。

§两种模式

  • 内存模式(默认)push 仅记录到内存 Vec,不发起网络请求。用于单元测试。
  • 真实 HTTP PUT 模式:启用 push-gateway feature 后,push 会向 config.endpoint 发起 HTTP PUT 请求,推送指标文本到 Pushgateway。

§Feature 切换

[dependencies]
sz-orm-observability = { version = "1.2", features = ["push-gateway"] }

Implementations§

Source§

impl PushgatewayExporter

Source

pub fn new(config: PushgatewayConfig) -> Self

创建新的 Pushgateway 导出器

Source

pub fn push(&self, metrics_text: impl Into<String>) -> Result<(), String>

推送指标到 Pushgateway

§行为
  • 内存模式(默认):将指标文本记录到内存 Vec,不发起网络请求。
  • HTTP PUT 模式(push-gateway feature):向 config.endpoint 发起 HTTP PUT 请求,URL 格式为 {endpoint}/metrics/job/{job}[/instance/{instance}]。 请求体为 Prometheus exposition format 文本。
§错误

HTTP 模式下,网络错误或非 2xx 响应码会返回 Err。 内存模式永远返回 Ok

Source

pub fn push_from_registry( &self, registry: &MetricsRegistry, ) -> Result<(), String>

从 MetricsRegistry 渲染并推送

Source

pub fn snapshots(&self) -> Vec<PushSnapshot>

获取推送历史快照

Source

pub fn push_count(&self) -> usize

获取推送次数

Source

pub fn clear(&self)

清空推送历史

Source

pub fn config(&self) -> &PushgatewayConfig

获取配置引用

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.