@@ -14,6 +14,7 @@ use oximeter::{
14
14
} ;
15
15
use oximeter_db:: { query, Client , DbWrite } ;
16
16
use slog:: { debug, info, o, Drain , Level , Logger } ;
17
+ use std:: net:: IpAddr ;
17
18
use std:: net:: SocketAddr ;
18
19
use uuid:: Uuid ;
19
20
@@ -53,6 +54,10 @@ fn level_from_str(s: &str) -> Result<Level, anyhow::Error> {
53
54
/// Tools for developing with the Oximeter timeseries database.
54
55
#[ derive( Debug , Parser ) ]
55
56
struct OxDb {
57
+ /// IP address at which to connect to the database
58
+ #[ clap( short, long, default_value = "::1" ) ]
59
+ address : IpAddr ,
60
+
56
61
/// Port on which to connect to the database
57
62
#[ clap( short, long, default_value = "8123" , action) ]
58
63
port : u16 ,
@@ -135,8 +140,12 @@ enum Subcommand {
135
140
} ,
136
141
}
137
142
138
- async fn make_client ( port : u16 , log : & Logger ) -> Result < Client , anyhow:: Error > {
139
- let address = SocketAddr :: new ( "::1" . parse ( ) . unwrap ( ) , port) ;
143
+ async fn make_client (
144
+ address : IpAddr ,
145
+ port : u16 ,
146
+ log : & Logger ,
147
+ ) -> Result < Client , anyhow:: Error > {
148
+ let address = SocketAddr :: new ( address, port) ;
140
149
let client = Client :: new ( address, & log) ;
141
150
client
142
151
. init_db ( )
@@ -199,12 +208,13 @@ async fn insert_samples(
199
208
}
200
209
201
210
async fn populate (
211
+ address : IpAddr ,
202
212
port : u16 ,
203
213
log : Logger ,
204
214
args : PopulateArgs ,
205
215
) -> Result < ( ) , anyhow:: Error > {
206
216
info ! ( log, "populating Oximeter database" ) ;
207
- let client = make_client ( port, & log) . await ?;
217
+ let client = make_client ( address , port, & log) . await ?;
208
218
let n_timeseries = args. n_projects * args. n_instances * args. n_cpus ;
209
219
debug ! (
210
220
log,
@@ -251,20 +261,25 @@ async fn populate(
251
261
Ok ( ( ) )
252
262
}
253
263
254
- async fn wipe_db ( port : u16 , log : Logger ) -> Result < ( ) , anyhow:: Error > {
255
- let client = make_client ( port, & log) . await ?;
264
+ async fn wipe_db (
265
+ address : IpAddr ,
266
+ port : u16 ,
267
+ log : Logger ,
268
+ ) -> Result < ( ) , anyhow:: Error > {
269
+ let client = make_client ( address, port, & log) . await ?;
256
270
client. wipe_db ( ) . await . context ( "Failed to wipe database" )
257
271
}
258
272
259
273
async fn query (
274
+ address : IpAddr ,
260
275
port : u16 ,
261
276
log : Logger ,
262
277
timeseries_name : String ,
263
278
filters : Vec < String > ,
264
279
start : Option < query:: Timestamp > ,
265
280
end : Option < query:: Timestamp > ,
266
281
) -> Result < ( ) , anyhow:: Error > {
267
- let client = make_client ( port, & log) . await ?;
282
+ let client = make_client ( address , port, & log) . await ?;
268
283
let filters = filters. iter ( ) . map ( |s| s. as_str ( ) ) . collect :: < Vec < _ > > ( ) ;
269
284
let timeseries = client
270
285
. select_timeseries_with (
@@ -291,9 +306,13 @@ async fn main() {
291
306
match args. cmd {
292
307
Subcommand :: Describe => describe_data ( ) ,
293
308
Subcommand :: Populate { populate_args } => {
294
- populate ( args. port , log, populate_args) . await . unwrap ( ) ;
309
+ populate ( args. address , args. port , log, populate_args)
310
+ . await
311
+ . unwrap ( ) ;
312
+ }
313
+ Subcommand :: Wipe => {
314
+ wipe_db ( args. address , args. port , log) . await . unwrap ( )
295
315
}
296
- Subcommand :: Wipe => wipe_db ( args. port , log) . await . unwrap ( ) ,
297
316
Subcommand :: Query {
298
317
timeseries_name,
299
318
filters,
@@ -312,9 +331,17 @@ async fn main() {
312
331
( _, Some ( end) ) => Some ( query:: Timestamp :: Exclusive ( end) ) ,
313
332
( None , None ) => None ,
314
333
} ;
315
- query ( args. port , log, timeseries_name, filters, start, end)
316
- . await
317
- . unwrap ( ) ;
334
+ query (
335
+ args. address ,
336
+ args. port ,
337
+ log,
338
+ timeseries_name,
339
+ filters,
340
+ start,
341
+ end,
342
+ )
343
+ . await
344
+ . unwrap ( ) ;
318
345
}
319
346
}
320
347
}
0 commit comments