metrics_influxdb/
lib.rs

1use std::fmt::Display;
2
3use crate::config::InfluxConfig;
4use metrics::{Counter, Gauge, Histogram, Key, KeyName, Recorder, SharedString, Unit};
5use reqwest::{Client, RequestBuilder};
6
7mod config;
8mod metric;
9mod types;
10
11pub struct InfluxClient {
12    client: Client,
13    request: RequestBuilder,
14}
15
16impl InfluxClient {
17    pub fn new(config: InfluxConfig) -> Self {
18        let client = Client::new();
19
20        let request = match config {
21            InfluxConfig::V1(config) => {
22                let parameters = vec![
23                    Some(("db", config.db.clone())),
24                    config.username.as_ref().map(|u| ("u", u.clone())),
25                    config.password.as_ref().map(|p| ("p", p.clone())),
26                    config
27                        .consistency
28                        .as_ref()
29                        .map(|c| ("consistency", c.to_string())),
30                    config
31                        .precision
32                        .as_ref()
33                        .map(|p| ("precision", p.to_string())),
34                    config
35                        .retention_policy
36                        .as_ref()
37                        .map(|rp| ("rp", rp.clone())),
38                ]
39                .into_iter()
40                .flatten()
41                .collect::<Vec<(&str, String)>>();
42
43                client
44                    .post(format!("{}/write", config.endpoint))
45                    .query(&parameters)
46            }
47            InfluxConfig::V2(config) => {
48                todo!()
49            }
50        };
51
52        InfluxClient { client, request }
53    }
54}
55
56impl Recorder for InfluxClient {
57    fn describe_counter(&self, key: KeyName, unit: Option<Unit>, description: SharedString) {
58        todo!()
59    }
60
61    fn describe_gauge(&self, key: KeyName, unit: Option<Unit>, description: SharedString) {
62        todo!()
63    }
64
65    fn describe_histogram(&self, key: KeyName, unit: Option<Unit>, description: SharedString) {
66        todo!()
67    }
68
69    fn register_counter(&self, key: &Key) -> Counter {
70        todo!()
71    }
72
73    fn register_gauge(&self, key: &Key) -> Gauge {
74        todo!()
75    }
76
77    fn register_histogram(&self, key: &Key) -> Histogram {
78        todo!()
79    }
80}