summaryrefslogtreecommitdiff
path: root/src/reporting.rs
blob: ee30ac55e355a4820378535336373a63e88ea51d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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(),
        }
    }
}