pub trait Collector: Debug + Send + Sync + 'static {
    // Required method
    fn encode(&self, encoder: DescriptorEncoder<'_>) -> Result<(), Error>;
}
Expand description

The Collector abstraction allows users to provide additional metrics and their description on each scrape.

An example use-case is an exporter that retrieves a set of operating system metrics ad-hoc on each scrape.

Register a Collector with a Registry via Registry::register_collector.

#[derive(Debug)]
struct MyCollector {}

impl Collector for MyCollector {
    fn encode(&self, mut encoder: DescriptorEncoder) -> Result<(), std::fmt::Error> {
        let counter = ConstCounter::new(42);
        let metric_encoder = encoder.encode_descriptor(
            "my_counter",
            "some help",
            None,
            counter.metric_type(),
        )?;
        counter.encode(metric_encoder)?;
        Ok(())
    }
}

Required Methods§

source

fn encode(&self, encoder: DescriptorEncoder<'_>) -> Result<(), Error>

Once the Collector is registered, this method is called on each scrape.

Implementors§