ckb_metrics_config/
lib.rs

1//! CKB metrics configurations.
2//!
3//! This crate is used to configure the [CKB metrics service].
4//!
5//! [CKB metrics service]: ../ckb_metrics_service/index.html
6
7use std::collections::HashMap;
8
9use serde::{Deserialize, Serialize};
10
11/// The whole CKB metrics configuration.
12///
13/// This struct is used to configure [CKB metrics service].
14///
15/// # An example which is used in `ckb.toml`:
16/// ```toml
17/// [metrics.exporter.prometheus]
18/// target = { type = "prometheus", listen_address = "127.0.0.1:8100" }
19/// ```
20///
21/// [CKB metrics service]: ../ckb_metrics_service/index.html
22#[derive(Default, Clone, Debug, Serialize, Deserialize)]
23#[serde(deny_unknown_fields)]
24pub struct Config {
25    /// Stores all exporters configurations.
26    #[serde(default)]
27    pub exporter: HashMap<String, Exporter>,
28}
29
30/// The configuration of an exporter.
31#[derive(Clone, Debug, Serialize, Deserialize)]
32pub struct Exporter {
33    /// How to output the metrics data.
34    pub target: Target,
35}
36
37/// The target to output the metrics data.
38#[derive(Clone, Debug, Serialize, Deserialize)]
39#[serde(rename_all = "snake_case")]
40#[serde(tag = "type")]
41pub enum Target {
42    /// Outputs the metrics data through Prometheus.
43    Prometheus {
44        /// The HTTP listen address.
45        listen_address: String,
46    },
47}