Add influxdb
This commit is contained in:
@@ -5,7 +5,18 @@ pub struct Config {
|
||||
pub fan_on_temp_c: f64,
|
||||
pub fan_off_temp_c: f64,
|
||||
pub poll_interval_s: f64,
|
||||
pub error_temp_c: f64,
|
||||
pub thermal_alarm_temp_c: f64,
|
||||
pub influx: Option<InfluxConfig>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct InfluxConfig {
|
||||
pub url: String,
|
||||
pub org: String,
|
||||
pub bucket: String,
|
||||
pub token: String,
|
||||
pub host_tag: String,
|
||||
pub metrics_interval_s: f64,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
@@ -16,7 +27,30 @@ impl Default for Config {
|
||||
fan_on_temp_c: 40.0,
|
||||
fan_off_temp_c: 35.0,
|
||||
poll_interval_s: 2.0,
|
||||
error_temp_c: 80.0,
|
||||
thermal_alarm_temp_c: 80.0,
|
||||
influx: InfluxConfig::from_env(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl InfluxConfig {
|
||||
pub fn from_env() -> Option<Self> {
|
||||
let token = std::env::var("TOWERD_INFLUX_TOKEN").ok()?;
|
||||
let org = std::env::var("TOWERD_INFLUX_ORG").ok()?;
|
||||
let bucket = std::env::var("TOWERD_INFLUX_BUCKET").ok()?;
|
||||
|
||||
Some(Self {
|
||||
url: std::env::var("TOWERD_INFLUX_URL")
|
||||
.unwrap_or_else(|_| "http://influx.kitsunehosting.net:8086".into()),
|
||||
org,
|
||||
bucket,
|
||||
token,
|
||||
host_tag: std::env::var("TOWERD_INFLUX_HOST")
|
||||
.unwrap_or_else(|_| "kw1fox-1".into()),
|
||||
metrics_interval_s: std::env::var("TOWERD_INFLUX_INTERVAL_S")
|
||||
.ok()
|
||||
.and_then(|s| s.parse().ok())
|
||||
.unwrap_or(30.0),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user