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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use std::collections::HashMap;

pub type LabelName = String;
pub type LabelValue = String;
pub type Label = HashMap<LabelName, LabelValue>;

#[derive(Debug)]
pub enum MetricType {
    COUNTER,
    GAUGE,
    HISTOGRAM,
    NONE,
    SUMMARY,
}

impl Default for MetricType {
    fn default() -> Self { MetricType::NONE }
}

#[derive(Default, Debug)]
pub struct Metric( pub Vec<Label> );

impl Metric {
    pub fn add(metric_name: &str, metric_text: &str) -> Label {
        let mut metric_hash = HashMap::new();
        metric_hash.insert("value".to_string(), metric_text.to_string());
        metric_hash
    }
}

#[derive(Default, Debug)]
pub struct MetricGroup {
    pub help: String,
    pub r#type: MetricType,
    pub metric: Metric,
}

impl MetricGroup {
    pub fn new_with_help(help_string: &str) -> Self {
        MetricGroup {
            help: help_string.to_string(),
            r#type: Default::default(),
            metric: Default::default()
        }
    }

    pub fn new_with_type(type_string: &str) -> Self {
        MetricGroup {
            help: Default::default(),
            r#type: match type_string {
                "counter" => MetricType::COUNTER,
                "gauge" => MetricType::GAUGE,
                "histogram" => MetricType::HISTOGRAM,
                "summary" => MetricType::SUMMARY,
                _ => MetricType::NONE,
            },
            metric: Default::default()
        }
    }

    pub fn new_with_metric(metric_name: &str, metric_text: &str) -> Self {
        MetricGroup {
            help: Default::default(),
            r#type: Default::default(),
            metric: Default::default()
            //metric: metric_text.to_string()
        }
    }
}

pub type Metrics = HashMap<String, MetricGroup>;
//#[derive(Default, Debug)]
//pub struct Metrics( HashMap<String, MetricGroup> );
//impl Metrics {
//    pub fn new() -> Self {
//        Default::default()
//    }
//}

pub fn add(metric_name: &str, metric_text: &str) -> Label {
    let mut metric_hash = HashMap::new();
    metric_hash.insert("value".to_string(), metric_text.to_string());
    metric_hash
}