Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Plugin status monitoring #25

Merged
merged 7 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
workspace = { members = ["paws_config", "paws_install"] }
workspace = { members = ["paws_config", "paws_install", "paws_monitoring"] }
[package]
name = "kittypaws"
version = "0.1.0"
Expand All @@ -18,7 +18,10 @@ libloading = "0.5"
serde_yaml = "0.9.34"
paws_config = { path = "paws_config" }
paws_install = { path = "paws_install" }
paws_monitoring = { path = "paws_monitoring" }
iso8601 = { version = "0.6.1", features = ["serde"] }
serde = { version = "1.0.197", features = ["derive"] }
pyo3 = {"version" = "0.17.3", features = ["auto-initialize"]}
pyo3 = { version = "0.17.3", features = ["auto-initialize"] }
clap = { version = "4.5.4", features = ["derive"] }
uuid = { version = "1.10.0", features = ["v4"] }

12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,21 @@ https://github.com/subatiq/kittypaws-timeburglar
```yaml
plugins:
- name: plugin01
config01: yes
config02: 42
options:
config01: yes
config02: 42
...

- name: plugin01:
config03: yes
config02: 44
options:
config03: yes
config02: 44
...
```

### Run duration

You can specify if the test run should stop after some time. To configure it, add
You can specify if the test run should stop after some time. To configure it, add

```yaml
duration: <Duration in ISO 8601 format>
Expand Down
10 changes: 6 additions & 4 deletions configs/all.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
deathloop:
target: ev_sensor
deathloop:
frequency: random
interval: PT1M
options:
target: ev_sensor
dropper:
target: ev_sensor
ip: 192.168.85.139
options:
target: ev_sensor
ip: 192.168.85.139
5 changes: 3 additions & 2 deletions configs/dropping.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dropper:
target: ev_sensor
ip: 192.168.85.139
options:
target: ev_sensor
ip: 192.168.85.139
5 changes: 3 additions & 2 deletions configs/restarting.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
deathloop:
target: ev_sensor
deathloop:
options:
target: ev_sensor
frequency: random
interval: PT1M
26 changes: 19 additions & 7 deletions paws_config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{collections::HashMap, path::PathBuf};
use serde::Deserialize;

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Duration(std::time::Duration);

impl Duration {
Expand All @@ -26,7 +25,7 @@ impl<'de> Deserialize<'de> for Duration {
}
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Clone)]
#[serde(rename_all = "snake_case")]
pub enum StartupOptions {
Hot,
Expand All @@ -35,13 +34,13 @@ pub enum StartupOptions {
Delayed(Duration),
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Clone)]
pub struct RandomRange<T> {
pub min: T,
pub max: T,
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Clone)]
#[serde(rename_all = "snake_case")]
pub enum FrequencyOptions {
Once,
Expand All @@ -51,17 +50,30 @@ pub enum FrequencyOptions {
Random(RandomRange<Duration>),
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Clone)]
pub struct GlobalMonitoringOptions {
pub dsn: String,
pub extra_tags: Option<HashMap<String, String>>
}

#[derive(Debug, Deserialize, Clone)]
pub struct PluginMonitoringOptions {
pub frequency: FrequencyOptions,
pub extra_tags: Option<HashMap<String, String>>
}

#[derive(Debug, Deserialize, Clone)]
pub struct PluginConfig {
pub name: String,
pub startup: StartupOptions,
pub frequency: FrequencyOptions,
pub healthcheck: Option<String>,
pub monitoring: Option<PluginMonitoringOptions>,
pub options: Option<HashMap<String, String>>
}

#[derive(Debug, Deserialize)]
pub struct KittypawsConfig {
pub monitoring: Option<GlobalMonitoringOptions>,
pub duration: Option<Duration>,
pub plugins: Vec<PluginConfig>,
}
Expand Down
9 changes: 9 additions & 0 deletions paws_monitoring/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "paws_monitoring"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
telegraf = "0.6.0"
29 changes: 29 additions & 0 deletions paws_monitoring/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
pub mod telegraf;
use std::collections::HashMap;

use telegraf::TelegrafClient;

#[derive(Debug)]
pub enum StatusValue {
Int(i64),
Float(f64),
String(String),
}

pub enum MonitoringBackend {
Telegraf,
}

pub trait MetricSender: Send {
fn send_metric(
&mut self,
tags: HashMap<String, String>,
fields: HashMap<String, StatusValue>,
) -> Result<(), String>;
}

pub fn init_monitoring_backend(option: MonitoringBackend, dsn: &str) -> Box<dyn MetricSender> {
Box::new(match option {
MonitoringBackend::Telegraf => TelegrafClient::new(dsn).unwrap(),
})
}
Loading
Loading