1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
//! Collectd is a ubiquitous system statistics collection daemon.
//! `collectd_plugin` leverages Collectd's ability to dynamically load plugins and
//! creates an ergonomic, yet extremely low cost abstraction API to interface with
//! Collectd.
//!
//! Features:
//!
//! - No unnecessary allocations when submitting / receiving values, logging
//! - Register multiple plugin instances
//! - Automatic deserialization of plugin configs via [Serde](https://github.com/serde-rs/serde) (can opt-out)
//! - Deployment: compile against collectd version and scp to server
//! - Referenced Rust libraries are statically linked
//! - Help writing thread safe plugins thanks to the Rust compiler
//!
//! ## Usage
//!
//! Add to your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! collectd-plugin = "0.9.0"
//! ```
//!
//! [Serde](https://github.com/serde-rs/serde) support is enabled by default for configuration parsing.
//!
//! Then put this in your crate root:
//!
//! ```rust,ignore
//! extern crate collectd_plugin;
//! ```
//!
//! Rust 1.20 or later is needed to build.
//!
//! This repo is tested on the following:
//!
//! - Collectd 5.4 (Ubuntu 14.04)
//! - Collectd 5.5 (Ubuntu 16.04)
//! - Collectd 5.7 (and above) (Ubuntu 18.04)
//!
//! ## Quickstart
//!
//! Below is a complete plugin that dummy reports [load](https://en.wikipedia.org/wiki/Load_(computing)) values to collectd, as it registers a `READ` hook. For an implementation that reimplements Collectd's own load plugin, see [plugins/load](https://github.com/nickbabcock/collectd-rust-plugin/tree/master/plugins/load)
//!
//! ```rust
//! #[macro_use]
//! extern crate collectd_plugin;
//!
//! use collectd_plugin::{
//! ConfigItem, Plugin, PluginCapabilities, PluginManager, PluginRegistration, Value,
//! ValueListBuilder,
//! };
//! use std::error;
//!
//! #[derive(Default)]
//! struct MyPlugin;
//!
//! // A manager decides the name of the family of plugins and also registers one or more plugins based
//! // on collectd's configuration files
//! impl PluginManager for MyPlugin {
//! // A plugin needs a unique name to be referenced by collectd
//! fn name() -> &'static str {
//! "myplugin"
//! }
//!
//! // Our plugin might have configuration section in collectd.conf, which will be passed here if
//! // present. Our contrived plugin doesn't care about configuration so it returns only a single
//! // plugin (itself).
//! fn plugins(_config: Option<&[ConfigItem]>) -> Result<PluginRegistration, Box<error::Error>> {
//! Ok(PluginRegistration::Single(Box::new(MyPlugin)))
//! }
//! }
//!
//! impl Plugin for MyPlugin {
//! // We define that our plugin will only be reporting / submitting values to writers
//! fn capabilities(&self) -> PluginCapabilities {
//! PluginCapabilities::READ
//! }
//!
//! fn read_values(&self) -> Result<(), Box<error::Error>> {
//! // Create a list of values to submit to collectd. We'll be sending in a vector representing the
//! // "load" type. Short-term load is first (15.0) followed by mid-term and long-term. The number
//! // of values that you submit at a time depends on types.db in collectd configurations
//! let values = vec![Value::Gauge(15.0), Value::Gauge(10.0), Value::Gauge(12.0)];
//!
//! // Submit our values to collectd. A plugin can submit any number of times.
//! ValueListBuilder::new(Self::name(), "load")
//! .values(&values)
//! .submit()?;
//!
//! Ok(())
//! }
//! }
//!
//! // We pass in our plugin manager type
//! collectd_plugin!(MyPlugin);
//!
//! # fn main() {
//! # }
//! ```
#[macro_use]
extern crate bitflags;
extern crate chrono;
extern crate memchr;
#[cfg(feature = "serde")]
#[macro_use]
extern crate serde;
#[cfg(test)]
#[cfg(feature = "serde")]
#[macro_use]
extern crate serde_derive;
extern crate env_logger;
#[macro_use]
extern crate log;
#[cfg(feature = "serde")]
pub mod de;
#[cfg(feature = "serde")]
pub mod ser;
pub mod bindings;
pub mod internal;
#[macro_use]
mod api;
mod errors;
#[macro_use]
mod plugins;
pub use api::{
collectd_log, CdTime, CollectdLoggerBuilder, ConfigItem, ConfigValue, LogLevel, Value,
ValueList, ValueListBuilder, ValueReport,
};
pub use plugins::{
Plugin, PluginCapabilities, PluginManager, PluginManagerCapabilities, PluginRegistration,
};