-
Notifications
You must be signed in to change notification settings - Fork 236
/
Copy pathlib.rs
91 lines (82 loc) · 2.05 KB
/
lib.rs
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
85
86
87
88
89
90
91
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
/* Examples:
* ```toml
* [metrics]
* threads = 3
* histogram_window = 60
* histogram_granularity = 1
* upkeep_interval = 500
* [metrics.exporter.prometheus]
* target = { type = "http", listen_address = "127.0.0.1:8100" }
* format = { type = "prometheus" }
* [metrics.exporter.log_yaml]
* target = { type = "log", level = "warn", interval = 600 }
* format = { type = "yaml" }
* [metrics.exporter.log_json]
* target = { type = "log", level = "error", interval = 900 }
* format = { type = "json" }
* ```
*/
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Config {
#[serde(default)]
pub threads: usize,
#[serde(default)]
pub histogram_window: u64, // seconds
#[serde(default)]
pub histogram_granularity: u64, // seconds
#[serde(default)]
pub upkeep_interval: u64, // milliseconds
#[serde(default)]
pub exporter: HashMap<String, Exporter>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Exporter {
pub target: Target,
pub format: Format,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[serde(tag = "type")]
pub enum Target {
Log {
level: LogLevel,
interval: u64, // seconds
},
Http {
listen_address: String,
},
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[serde(tag = "type")]
pub enum Format {
Json {
#[serde(default)]
pretty: bool,
},
Yaml,
Prometheus,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum LogLevel {
Error,
Warn,
Info,
Debug,
Trace,
}
impl From<LogLevel> for log::Level {
fn from(lv: LogLevel) -> Self {
match lv {
LogLevel::Error => Self::Error,
LogLevel::Warn => Self::Warn,
LogLevel::Info => Self::Info,
LogLevel::Debug => Self::Debug,
LogLevel::Trace => Self::Trace,
}
}
}