chore: cargo-fmt
This commit is contained in:
parent
bf9549d801
commit
dcdee5ffaa
4 changed files with 66 additions and 34 deletions
|
@ -1 +0,0 @@
|
|||
max_width = 120
|
|
@ -28,14 +28,17 @@ pub struct Configuration {
|
|||
|
||||
impl Configuration {
|
||||
pub async fn load() -> Result<Configuration> {
|
||||
let mut s = Config::builder();
|
||||
if std::fs::metadata("config").is_ok(){
|
||||
s = s.add_source(config::File::with_name("config"));
|
||||
} else { println!("config file not found. continuing with env vars... ") };
|
||||
|
||||
s = s.add_source(config::Environment::with_prefix("VICI_EXPORTER").separator("_"));
|
||||
// s.build().unwrap();
|
||||
let conf: Configuration = s.build().unwrap().try_deserialize().unwrap();
|
||||
Ok(conf)
|
||||
let settings = Config::builder()
|
||||
.set_default("vici.socket", "/var/run/charon.vici")?
|
||||
.set_default("vici.interval", 10)?
|
||||
.set_default("server.address", "0.0.0.0")?
|
||||
.set_default("server.port", 8000)?
|
||||
.add_source(config::File::with_name("config"))
|
||||
.add_source(config::Environment::with_prefix("VICI_EXPORTER").separator("_"))
|
||||
.build();
|
||||
match settings {
|
||||
Ok(body) => Ok(body.try_deserialize().unwrap()),
|
||||
Err(err) => Err(err.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
33
src/main.rs
33
src/main.rs
|
@ -1,10 +1,4 @@
|
|||
use metrics::{
|
||||
describe_gauge,
|
||||
gauge,
|
||||
describe_counter,
|
||||
counter,
|
||||
IntoLabels,
|
||||
Unit};
|
||||
use metrics::{counter, describe_counter, describe_gauge, gauge, IntoLabels, Unit};
|
||||
use metrics_exporter_prometheus::PrometheusBuilder;
|
||||
use tokio::time::{interval, Duration, MissedTickBehavior};
|
||||
|
||||
|
@ -44,11 +38,26 @@ async fn main() -> anyhow::Result<()> {
|
|||
let mut child_labels = sa_child_values.into_labels();
|
||||
child_labels.push((&("sa_name", sa_name.clone())).into());
|
||||
child_labels.push((&("sa_child_name", sa_child_name)).into());
|
||||
counter!("sa_child_bytes_in", sa_child_values.bytes_in, child_labels.clone());
|
||||
counter!("sa_child_bytes_out", sa_child_values.bytes_out, child_labels.clone());
|
||||
counter!("sa_child_packets_in", sa_child_values.packets_in, child_labels.clone());
|
||||
counter!("sa_child_packets_out", sa_child_values.packets_out, child_labels.clone());
|
||||
|
||||
counter!(
|
||||
"sa_child_bytes_in",
|
||||
sa_child_values.bytes_in,
|
||||
child_labels.clone()
|
||||
);
|
||||
counter!(
|
||||
"sa_child_bytes_out",
|
||||
sa_child_values.bytes_out,
|
||||
child_labels.clone()
|
||||
);
|
||||
counter!(
|
||||
"sa_child_packets_in",
|
||||
sa_child_values.packets_in,
|
||||
child_labels.clone()
|
||||
);
|
||||
counter!(
|
||||
"sa_child_packets_out",
|
||||
sa_child_values.packets_out,
|
||||
child_labels.clone()
|
||||
);
|
||||
}
|
||||
}
|
||||
interval.tick().await;
|
||||
|
|
41
src/vici.rs
41
src/vici.rs
|
@ -1,12 +1,12 @@
|
|||
#![allow(dead_code)]
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::{de::value::BoolDeserializer, Deserialize};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use futures_util::stream::StreamExt;
|
||||
|
||||
use anyhow::Result;
|
||||
use metrics::{IntoLabels,Label};
|
||||
use metrics::{IntoLabels, Label};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct VICIState {
|
||||
|
@ -25,22 +25,45 @@ impl VICIState {
|
|||
Ok(VICIState {
|
||||
version: client.request("version", ()).await?,
|
||||
statistics: client.request("statistics", ()).await?,
|
||||
policies: collected_stream::<NamedPolicy, Policies>(client, "list-policies", "list-policy").await?,
|
||||
connections: collected_stream::<NamedConnection, Connections>(client, "list-connections", "list-conn")
|
||||
policies: collected_stream::<NamedPolicy, Policies>(
|
||||
client,
|
||||
"list-policies",
|
||||
"list-policy",
|
||||
)
|
||||
.await?,
|
||||
security_associations: collected_stream::<NamedSecurityAssociation, SecurityAssociations>(
|
||||
connections: collected_stream::<NamedConnection, Connections>(
|
||||
client,
|
||||
"list-connections",
|
||||
"list-conn",
|
||||
)
|
||||
.await?,
|
||||
security_associations:
|
||||
collected_stream::<NamedSecurityAssociation, SecurityAssociations>(
|
||||
client, "list-sas", "list-sa",
|
||||
)
|
||||
.await?,
|
||||
certificates: collected_stream::<NamedCertificate, Certificates>(client, "list-certs", "list-cert").await?,
|
||||
authorities: collected_stream::<NamedAuthority, Authorities>(client, "list-authorities", "list-authority")
|
||||
certificates: collected_stream::<NamedCertificate, Certificates>(
|
||||
client,
|
||||
"list-certs",
|
||||
"list-cert",
|
||||
)
|
||||
.await?,
|
||||
authorities: collected_stream::<NamedAuthority, Authorities>(
|
||||
client,
|
||||
"list-authorities",
|
||||
"list-authority",
|
||||
)
|
||||
.await?,
|
||||
pools: collected_stream::<NamedPool, Pools>(client, "list-pools", "list-pool").await?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async fn collected_stream<N, C>(client: &mut rsvici::Client, command: &str, event: &str) -> Result<C>
|
||||
async fn collected_stream<N, C>(
|
||||
client: &mut rsvici::Client,
|
||||
command: &str,
|
||||
event: &str,
|
||||
) -> Result<C>
|
||||
where
|
||||
N: for<'de> serde::Deserialize<'de>,
|
||||
C: std::iter::Extend<N> + Default,
|
||||
|
@ -243,7 +266,6 @@ pub struct SecurityAssociation {
|
|||
pub child_security_associations: HashMap<String, SecurityAssociationChild>,
|
||||
}
|
||||
|
||||
|
||||
impl IntoLabels for &SecurityAssociationChild {
|
||||
fn into_labels(self) -> Vec<Label> {
|
||||
vec![
|
||||
|
@ -253,7 +275,6 @@ impl IntoLabels for &SecurityAssociationChild {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct SecurityAssociationChild {
|
||||
pub name: String,
|
||||
|
|
Loading…
Add table
Reference in a new issue