diff options
Diffstat (limited to 'plugins/plugin_avg/src/lib.rs')
-rw-r--r-- | plugins/plugin_avg/src/lib.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/plugins/plugin_avg/src/lib.rs b/plugins/plugin_avg/src/lib.rs index 47ff0aa4..45202c9b 100644 --- a/plugins/plugin_avg/src/lib.rs +++ b/plugins/plugin_avg/src/lib.rs @@ -21,11 +21,12 @@ use tracing::Instrument; pub struct AvgPluginBuilder; -#[derive(serde::Deserialize, Debug)] +#[derive(serde::Deserialize, Debug, tedge_api::Config)] struct AvgConfig { - #[serde(with = "humantime_serde")] - timeframe: std::time::Duration, + /// The duration of the time window to calculate the average for + timeframe: tedge_lib::config::Humantime, + /// The name of the plugin to send the result to target: String, /// Whether to report a 0 (zero) if there are zero measurements in the timeframe @@ -47,6 +48,10 @@ impl<PD: PluginDirectory> PluginBuilder<PD> for AvgPluginBuilder { "avg" } + fn kind_configuration() -> Option<tedge_api::ConfigDescription> { + Some(<AvgConfig as tedge_api::AsConfig>::as_config()) + } + async fn verify_configuration( &self, config: &PluginConfiguration, @@ -121,7 +126,7 @@ impl Plugin for AvgPlugin { values: self.values.clone(), }; let (stopper, mainloop) = - tedge_lib::mainloop::Mainloop::ticking_every(self.config.timeframe, state); + tedge_lib::mainloop::Mainloop::ticking_every(self.config.timeframe.into_duration(), state); self.stopper = Some(stopper); let _ = tokio::spawn( |