@@ -9,7 +9,7 @@ use hyper_util::rt::TokioIo;
99use prometheus:: { Encoder , TextEncoder } ;
1010
1111use std:: convert:: Infallible ;
12- use std:: net:: SocketAddr ;
12+ use std:: net:: { IpAddr , SocketAddr } ;
1313use std:: num:: ParseIntError ;
1414use std:: path:: PathBuf ;
1515
@@ -28,7 +28,7 @@ async fn metrics(_: Request<impl hyper::body::Body>) -> Result<Response<Full<Byt
2828}
2929
3030async fn run_http_server ( config : & CommandArgs ) -> Result < ( ) , anyhow:: Error > {
31- let addr: SocketAddr = ( [ 0 , 0 , 0 , 0 ] , config. port ) . into ( ) ;
31+ let addr: SocketAddr = ( config . addr , config. port ) . into ( ) ;
3232 let listener = TcpListener :: bind ( addr) . await ?;
3333 info ! ( "Listening on http://{}" , addr) ;
3434 loop {
@@ -72,6 +72,10 @@ struct CommandArgs {
7272 #[ arg( short, long, default_value_t = 9090 , env = "FDB_EXPORTER_PORT" ) ]
7373 port : u16 ,
7474
75+ /// Listen address of the web server, can be IPv4 or IPv6
76+ #[ arg( short, long, default_value = "0.0.0.0" , env = "FDB_EXPORTER_ADDR" ) ]
77+ addr : IpAddr ,
78+
7579 /// Location of fdb.cluster file
7680 #[ arg( short, long, env = "FDB_CLUSTER_FILE" ) ]
7781 cluster : Option < PathBuf > ,
@@ -117,14 +121,15 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
117121
118122#[ cfg( test) ]
119123mod tests {
120- use std:: time:: Duration ;
124+ use std:: { net :: Ipv4Addr , time:: Duration } ;
121125
122126 use crate :: CommandArgs ;
123127
124128 impl Default for CommandArgs {
125129 fn default ( ) -> Self {
126130 CommandArgs {
127131 port : 9090 ,
132+ addr : std:: net:: IpAddr :: V4 ( Ipv4Addr :: new ( 0 , 0 , 0 , 0 ) ) ,
128133 cluster : None ,
129134 delay_sec : Duration :: from_secs ( 1 ) ,
130135 }
0 commit comments