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
//! CKB metrics configurations.
//!
//! This crate is used to configure the [CKB metrics service].
//!
//! [CKB metrics service]: ../ckb_metrics_service/index.html

use std::collections::HashMap;

use serde::{Deserialize, Serialize};

/// The whole CKB metrics configuration.
///
/// This struct is used to configure [CKB metrics service].
///
/// # An example which is used in `ckb.toml`:
/// ```toml
/// [metrics.exporter.prometheus]
/// target = { type = "prometheus", listen_address = "127.0.0.1:8100" }
/// ```
///
/// [CKB metrics service]: ../ckb_metrics_service/index.html
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Config {
    /// Stores all exporters configurations.
    #[serde(default)]
    pub exporter: HashMap<String, Exporter>,
}

/// The configuration of an exporter.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Exporter {
    /// How to output the metrics data.
    pub target: Target,
}

/// The target to output the metrics data.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[serde(tag = "type")]
pub enum Target {
    /// Outputs the metrics data through Prometheus.
    Prometheus {
        /// The HTTP listen address.
        listen_address: String,
    },
}