Trait Plugin

Source
pub trait Plugin:
    Send
    + Sync
    + UnwindSafe
    + RefUnwindSafe {
    // Provided methods
    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>> { ... }
}
Expand description

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§

Source

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.

Source

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

Source

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.

Source

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.

Source

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.

Implementors§