summaryrefslogtreecommitdiff
path: root/src/reporting.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-10-06 10:22:31 +0200
committermetamuffin <metamuffin@disroot.org>2023-10-06 10:22:31 +0200
commit6e4095bd811a53cb75092516ef303b746e9aafba (patch)
tree44875ca252da14cc8018413ed2a25f99ed1fa06d /src/reporting.rs
parent452541087c6562fca94f24b9275b17d771622fbd (diff)
downloadgnix-6e4095bd811a53cb75092516ef303b746e9aafba.tar
gnix-6e4095bd811a53cb75092516ef303b746e9aafba.tar.bz2
gnix-6e4095bd811a53cb75092516ef303b746e9aafba.tar.zst
some basic reporting for mond
Diffstat (limited to 'src/reporting.rs')
-rw-r--r--src/reporting.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/reporting.rs b/src/reporting.rs
new file mode 100644
index 0000000..ee30ac5
--- /dev/null
+++ b/src/reporting.rs
@@ -0,0 +1,39 @@
+use crate::config::Config;
+use mond_client::{make_ident, Aspect, Push, Rate, Reporter};
+use std::{collections::HashMap, marker::PhantomData};
+
+pub struct Reporting {
+ pub request_in: Aspect<Rate<i64>>,
+ pub request_out: Aspect<Rate<i64>>,
+ pub hosts: HashMap<String, HostReporting>,
+ // pub connections: Aspect<State<i64>>,
+}
+pub struct HostReporting {
+ pub requests_in: Aspect<Rate<i64>>,
+}
+
+impl Reporting {
+ pub fn new(config: &Config) -> Self {
+ let mut rep = Reporter::new();
+ Self {
+ request_in: rep.create(make_ident!("requests-in"), Push(Rate(PhantomData::<i64>))),
+ request_out: rep.create(make_ident!("requests-out"), Push(Rate(PhantomData::<i64>))),
+ // connections: rep.create(make_ident!("connections"), Push()),
+ hosts: config
+ .hosts
+ .iter()
+ .map(|(k, _v)| {
+ (
+ k.to_owned(),
+ HostReporting {
+ requests_in: rep.create(
+ make_ident!("host", k, "request-in"),
+ Push(Rate(PhantomData::<i64>)),
+ ),
+ },
+ )
+ })
+ .collect(),
+ }
+ }
+}