diff options
| author | Matthieu <matthieu@developershouse.xyz> | 2021-10-16 09:33:56 +0400 |
|---|---|---|
| committer | Matthieu <matthieu@developershouse.xyz> | 2021-10-16 09:33:56 +0400 |
| commit | b94b0552f81e667bec31352901bbc8c76f1b4216 (patch) | |
| tree | ccc73abd12875502a954eaf10d080e02b5eb42ac /common/rust/src/monitoring.rs | |
| parent | b8c904a2ccef5b7389356b858a3fd4ffbbfb1ae6 (diff) | |
| parent | d2aa675b39361eccb1f5e74b08bc6428f564daa3 (diff) | |
merge branch management
Diffstat (limited to 'common/rust/src/monitoring.rs')
| -rw-r--r-- | common/rust/src/monitoring.rs | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/common/rust/src/monitoring.rs b/common/rust/src/monitoring.rs index ded1d95..4bff043 100644 --- a/common/rust/src/monitoring.rs +++ b/common/rust/src/monitoring.rs @@ -1,19 +1,19 @@ use hyper::{ - Response, Body, Request, Server, - header::{CONTENT_TYPE}, + header::CONTENT_TYPE, service::{make_service_fn, service_fn}, + Body, Request, Response, Server, }; -use std::net::ToSocketAddrs; +use log::{error, info}; use prometheus::{Encoder, TextEncoder}; -use log::{info,error}; use serde::Deserialize; +use std::net::ToSocketAddrs; #[derive(Clone, Debug, Deserialize)] /// Options for the monitoring service pub struct MonitoringConfiguration { - enabled: bool, - address: Option<String>, - port: Option<i32>, + pub enabled: bool, + pub address: Option<String>, + pub port: Option<i32>, } /// Handler for the hyper http server @@ -37,17 +37,18 @@ pub fn start_monitoring(configuration: &MonitoringConfiguration) { let config = configuration.clone(); tokio::task::spawn(async move { if config.enabled { - let address = format!("{}:{}", - config.address.expect("a listening address must be specified for the metrics server"), - config.port.expect("a listening port must be specified for the metrics server") + let address = format!( + "{}:{}", + config + .address + .expect("a listening address must be specified for the metrics server"), + config + .port + .expect("a listening port must be specified for the metrics server") ); info!("Starting monitoring server on {}", address); - - let listen_address = address - .to_socket_addrs() - .unwrap() - .next() - .unwrap(); + + let listen_address = address.to_socket_addrs().unwrap().next().unwrap(); let server = Server::bind(&listen_address).serve(make_service_fn(|_| async { Ok::<_, hyper::Error>(service_fn(serve_metrics)) })); @@ -57,4 +58,4 @@ pub fn start_monitoring(configuration: &MonitoringConfiguration) { } } }); -}
\ No newline at end of file +} |
