@@ -7,6 +7,7 @@ use chrono::Utc;
7
7
use futures:: { stream, FutureExt , StreamExt , TryFutureExt } ;
8
8
use http:: uri:: Scheme ;
9
9
use hyper:: { Body , Request } ;
10
+ use serde_with:: serde_as;
10
11
use snafu:: ResultExt ;
11
12
use tokio_stream:: wrappers:: IntervalStream ;
12
13
use vector_config:: configurable_component;
@@ -30,15 +31,18 @@ pub use parser::ParseError;
30
31
use vector_core:: config:: LogNamespace ;
31
32
32
33
/// Configuration for the `apache_metrics` source.
34
+ #[ serde_as]
33
35
#[ configurable_component( source( "apache_metrics" ) ) ]
34
36
#[ derive( Clone , Debug ) ]
35
37
pub struct ApacheMetricsConfig {
36
38
/// The list of `mod_status` endpoints to scrape metrics from.
39
+ #[ configurable( metadata( docs:: examples = "http://localhost:8080/server-status/?auto" ) ) ]
37
40
endpoints : Vec < String > ,
38
41
39
- /// The interval between scrapes, in seconds .
42
+ /// The interval between scrapes.
40
43
#[ serde( default = "default_scrape_interval_secs" ) ]
41
- scrape_interval_secs : u64 ,
44
+ #[ serde_as( as = "serde_with::DurationSeconds<u64>" ) ]
45
+ scrape_interval_secs : Duration ,
42
46
43
47
/// The namespace of the metric.
44
48
///
@@ -47,8 +51,8 @@ pub struct ApacheMetricsConfig {
47
51
namespace : String ,
48
52
}
49
53
50
- pub const fn default_scrape_interval_secs ( ) -> u64 {
51
- 15
54
+ pub const fn default_scrape_interval_secs ( ) -> Duration {
55
+ Duration :: from_secs ( 15 )
52
56
}
53
57
54
58
pub fn default_namespace ( ) -> String {
@@ -141,14 +145,14 @@ impl UriExt for http::Uri {
141
145
142
146
fn apache_metrics (
143
147
urls : Vec < http:: Uri > ,
144
- interval : u64 ,
148
+ interval : Duration ,
145
149
namespace : Option < String > ,
146
150
shutdown : ShutdownSignal ,
147
151
mut out : SourceSender ,
148
152
proxy : ProxyConfig ,
149
153
) -> super :: Source {
150
154
Box :: pin ( async move {
151
- let mut stream = IntervalStream :: new ( tokio:: time:: interval ( Duration :: from_secs ( interval) ) )
155
+ let mut stream = IntervalStream :: new ( tokio:: time:: interval ( interval) )
152
156
. take_until ( shutdown)
153
157
. map ( move |_| stream:: iter ( urls. clone ( ) ) )
154
158
. flatten ( )
@@ -360,7 +364,7 @@ Scoreboard: ____S_____I______R____I_______KK___D__C__G_L____________W___________
360
364
361
365
let config = ApacheMetricsConfig {
362
366
endpoints : vec ! [ format!( "http://foo:bar@{}/metrics" , in_addr) ] ,
363
- scrape_interval_secs : 1 ,
367
+ scrape_interval_secs : Duration :: from_secs ( 1 ) ,
364
368
namespace : "custom" . to_string ( ) ,
365
369
} ;
366
370
@@ -420,7 +424,7 @@ Scoreboard: ____S_____I______R____I_______KK___D__C__G_L____________W___________
420
424
421
425
let source = ApacheMetricsConfig {
422
426
endpoints : vec ! [ format!( "http://{}" , in_addr) ] ,
423
- scrape_interval_secs : 1 ,
427
+ scrape_interval_secs : Duration :: from_secs ( 1 ) ,
424
428
namespace : "apache" . to_string ( ) ,
425
429
}
426
430
. build ( SourceContext :: new_test ( tx, None ) )
@@ -454,7 +458,7 @@ Scoreboard: ____S_____I______R____I_______KK___D__C__G_L____________W___________
454
458
455
459
let source = ApacheMetricsConfig {
456
460
endpoints : vec ! [ format!( "http://{}" , in_addr) ] ,
457
- scrape_interval_secs : 1 ,
461
+ scrape_interval_secs : Duration :: from_secs ( 1 ) ,
458
462
namespace : "custom" . to_string ( ) ,
459
463
}
460
464
. build ( SourceContext :: new_test ( tx, None ) )
0 commit comments