[][src]Trait collectd_plugin::Plugin

pub trait Plugin: Send + Sync + UnwindSafe + RefUnwindSafe {
    fn capabilities(&self) -> PluginCapabilities { ... }
fn log(&self, _lvl: LogLevel, _msg: &str) -> Result<(), Box<dyn Error>> { ... }
fn read_values(&self) -> Result<(), Box<dyn Error>> { ... }
fn write_values(&self, _list: ValueList) -> Result<(), Box<dyn Error>> { ... }
fn flush(
        &self,
        _timeout: Option<Duration>,
        _identifier: Option<&str>
    ) -> Result<(), Box<dyn Error>> { ... } }

An individual plugin that is capable of reporting values to collectd, receiving values from other plugins, or logging messages. A plugin must implement Sync + Send as collectd could be sending values to be written or logged concurrently. The Rust compiler will ensure that everything not thread safe is wrapped in a Mutex (or another compatible datastructure)

Provided methods

fn capabilities(&self) -> PluginCapabilities

A plugin's capabilities. By default a plugin does nothing, but can advertise that it can configure itself and / or report values.

fn log(&self, _lvl: LogLevel, _msg: &str) -> Result<(), Box<dyn Error>>

Customizes how a message of a given level is logged. If the message isn't valid UTF-8, an allocation is done to replace all invalid characters with the UTF-8 replacement character

fn read_values(&self) -> Result<(), Box<dyn Error>>

This function is called when collectd expects the plugin to report values, which will occur at the Interval defined in the global config (but can be overridden). Implementations that expect to report values need to have at least have a capability of READ. An error in reporting values will cause collectd to backoff exponentially until a delay of a day is reached.

fn write_values(&self, _list: ValueList) -> Result<(), Box<dyn Error>>

Collectd is giving you reported values, do with them as you please. If writing values is expensive, prefer to buffer them in some way and register a flush callback to write.

fn flush(
    &self,
    _timeout: Option<Duration>,
    _identifier: Option<&str>
) -> Result<(), Box<dyn Error>>

Flush values to be written that are older than given duration. If an identifier is given, then only those buffered values should be flushed.

Loading content...

Implementors

Loading content...