2121use hyper:: http:: StatusCode ;
2222use hyper:: service:: Service ;
2323use hyper:: { Body , Method , Request , Response , Server } ;
24- use log:: { error , info} ;
24+ use log:: info;
2525use prometheus_client:: encoding:: text:: encode;
2626use prometheus_client:: registry:: Registry ;
2727use std:: future:: Future ;
@@ -30,31 +30,22 @@ use std::sync::{Arc, Mutex};
3030use std:: task:: { Context , Poll } ;
3131
3232const METRICS_CONTENT_TYPE : & str = "application/openmetrics-text;charset=utf-8;version=1.0.0" ;
33-
3433pub ( crate ) async fn metrics_server (
3534 registry : Registry ,
3635 metrics_path : String ,
37- ) -> Result < ( ) , std :: io :: Error > {
36+ ) -> Result < ( ) , hyper :: Error > {
3837 // Serve on localhost.
3938 let addr = ( [ 0 , 0 , 0 , 0 ] , 8888 ) . into ( ) ;
4039
41- // Use the tokio runtime to run the hyper server.
42- let rt = tokio:: runtime:: Runtime :: new ( ) ?;
43- rt. block_on ( async {
44- let server =
45- Server :: bind ( & addr) . serve ( MakeMetricService :: new ( registry, metrics_path. clone ( ) ) ) ;
46- info ! (
47- "Metrics server on http://{}{}" ,
48- server. local_addr( ) ,
49- metrics_path
50- ) ;
51- if let Err ( e) = server. await {
52- error ! ( "server error: {}" , e) ;
53- }
54- Ok ( ( ) )
55- } )
40+ let server = Server :: bind ( & addr) . serve ( MakeMetricService :: new ( registry, metrics_path. clone ( ) ) ) ;
41+ info ! (
42+ "Metrics server on http://{}{}" ,
43+ server. local_addr( ) ,
44+ metrics_path
45+ ) ;
46+ server. await ?;
47+ Ok ( ( ) )
5648}
57-
5849pub ( crate ) struct MetricService {
5950 reg : Arc < Mutex < Registry > > ,
6051 metrics_path : String ,
0 commit comments