feat(api): prometheus metrics
This commit is contained in:
@@ -8,6 +8,8 @@ anyhow = { workspace = true }
|
||||
config = "0.13.3"
|
||||
gethostname = "0.4.1"
|
||||
lazy_static = { workspace = true }
|
||||
metrics = "0.20.1"
|
||||
metrics-exporter-prometheus = { version = "0.11.0", default-features = false, features = ["tokio", "http-listener", "tracing"] }
|
||||
serde = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
|
@@ -33,11 +33,18 @@ pub struct ApiConfig {
|
||||
pub remote_url: String,
|
||||
}
|
||||
|
||||
fn _metrics_default() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct PKConfig {
|
||||
pub discord: DiscordConfig,
|
||||
pub api: ApiConfig,
|
||||
|
||||
#[serde(default = "_metrics_default")]
|
||||
pub run_metrics_server: bool,
|
||||
|
||||
pub(crate) gelf_log_url: Option<String>,
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
use gethostname::gethostname;
|
||||
use metrics_exporter_prometheus::PrometheusBuilder;
|
||||
use tracing_subscriber::{prelude::__tracing_subscriber_SubscriberExt, EnvFilter, Registry};
|
||||
|
||||
mod _config;
|
||||
@@ -25,3 +26,12 @@ pub fn init_logging(component: &str) -> anyhow::Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn init_metrics() -> anyhow::Result<()> {
|
||||
if config.run_metrics_server {
|
||||
// automatically spawns a http listener at :9000
|
||||
let builder = PrometheusBuilder::new();
|
||||
builder.install()?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user