@@ -41,10 +41,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
4141 . arg ( Arg :: new ( "ip" ) . short ( 'h' ) . long ( "ip" ) . env ( "IP" ) . required ( true ) . takes_value ( true ) )
4242 . arg ( Arg :: new ( "auth_usr" ) . short ( 'u' ) . long ( "auth_usr" ) . env ( "AUTH_USR" ) . required ( true ) . takes_value ( true ) )
4343 . arg ( Arg :: new ( "auth_pwd" ) . short ( 'p' ) . long ( "auth_pwd" ) . env ( "AUTH_PWD" ) . requires ( "auth_usr" ) . required ( true ) . takes_value ( true ) )
44- . arg ( Arg :: new ( "v" ) . short ( 'v' ) . multiple_occurrences ( true ) . takes_value ( false ) . required ( false ) . help ( "Log verbosity (-v, -vv, -vvv...)" ) )
44+ . arg ( Arg :: new ( "v" ) . short ( 'v' ) . action ( clap :: ArgAction :: Count ) . takes_value ( false ) . required ( false ) . help ( "Log verbosity (-v, -vv, -vvv...)" ) )
4545 . get_matches ( ) ;
4646
47- match app. occurrences_of ( "v" ) {
47+ match app. get_one :: < u8 > ( "v" ) . unwrap ( ) {
4848 0 => std:: env:: set_var ( "RUST_LOG" , "error" ) ,
4949 1 => std:: env:: set_var ( "RUST_LOG" , "warn" ) ,
5050 2 => std:: env:: set_var ( "RUST_LOG" , "info" ) ,
@@ -55,14 +55,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
5555
5656 env_logger:: Builder :: from_default_env ( ) . format ( |buf, record| writeln ! ( buf, "{} {} {}:{} [{}] - {}" , chrono:: Local :: now( ) . format( "%Y-%m-%dT%H:%M:%S" ) , record. module_path( ) . unwrap_or( "unknown" ) , record. file( ) . unwrap_or( "unknown" ) , record. line( ) . unwrap_or( 0 ) , record. level( ) , record. args( ) ) ) . init ( ) ;
5757
58- if !Path :: new ( & app. value_of ( "cfg_path" ) . unwrap ( ) ) . exists ( ) {
59- error ! ( "Config path not found: {}" , app. value_of ( "cfg_path" ) . unwrap( ) ) ;
58+ if !Path :: new ( & app. get_one :: < String > ( "cfg_path" ) . unwrap ( ) ) . exists ( ) {
59+ error ! ( "Config path not found: {}" , app. get_one :: < String > ( "cfg_path" ) . unwrap( ) ) ;
6060 return Ok ( ( ) ) ;
6161 }
6262
63- let port = & app. value_of ( "port" ) . and_then ( |s| s. parse :: < u16 > ( ) . ok ( ) ) ;
63+ let port = & app. get_one :: < String > ( "port" ) . and_then ( |s| s. parse :: < u16 > ( ) . ok ( ) ) ;
6464 if port. is_none ( ) {
65- error ! ( "The specified port is not valid ({})" , & app. value_of ( "port" ) . unwrap( ) ) ;
65+ error ! ( "The specified port is not valid ({})" , & app. get_one :: < String > ( "port" ) . unwrap( ) ) ;
6666 return Ok ( ( ) ) ;
6767 }
6868
@@ -83,10 +83,10 @@ fn register_metrics() {
8383}
8484
8585async fn data_collector ( app : ArgMatches ) {
86- let interval = app. value_of ( "interval" ) . unwrap ( ) . parse :: < u64 > ( ) . unwrap_or ( 60 ) ;
86+ let interval = app. get_one :: < String > ( "interval" ) . unwrap ( ) . parse :: < u64 > ( ) . unwrap_or ( 60 ) ;
8787 let mut collect_interval = tokio:: time:: interval ( Duration :: from_secs ( interval) ) ;
8888
89- let mut sio = sio:: client:: ClientInfo :: new ( app. value_of ( "cfg_path" ) , app. value_of ( "ip" ) , app. value_of ( "auth_usr" ) , app. value_of ( "auth_pwd" ) ) ;
89+ let mut sio = sio:: client:: ClientInfo :: new ( app. get_one :: < String > ( "cfg_path" ) . map ( |s| s . as_str ( ) ) , app. get_one :: < String > ( "ip" ) . map ( |s| s . as_str ( ) ) , app. get_one :: < String > ( "auth_usr" ) . map ( |s| s . as_str ( ) ) , app. get_one :: < String > ( "auth_pwd" ) . map ( |s| s . as_str ( ) ) ) ;
9090 _ = sio. version ( ) . await ;
9191
9292 loop {
@@ -188,15 +188,17 @@ fn update_metrics(metrics: &[sio::metrics::Metric]) {
188188 }
189189
190190 if m. mtype . to_lowercase ( ) == "counter" {
191- let c = match counters. get ( & m. name ) {
191+ let c = counters. get ( & m. name ) ;
192+ let c = match c {
192193 None => {
193194 error ! ( "The metric {} ({}) was not found as registered" , m. name, m. mtype) ;
194195 continue ;
195196 } ,
196197 Some ( c) => c,
197198 } ;
198199
199- let metric = match c. get_metric_with ( & labels) {
200+ let metric = c. get_metric_with ( & labels) ;
201+ let metric = match metric {
200202 Err ( e) => {
201203 error ! ( "The metric {} {:?} ({}) was not found in MetricFamily - {}" , m. name, labels, m. mtype, e) ;
202204 continue ;
@@ -206,15 +208,17 @@ fn update_metrics(metrics: &[sio::metrics::Metric]) {
206208
207209 metric. inc_by ( m. value as u64 ) ;
208210 } else if m. mtype . to_lowercase ( ) == "gauge" {
209- let g = match gauges. get ( & m. name ) {
211+ let g = gauges. get ( & m. name ) ;
212+ let g = match g {
210213 None => {
211214 error ! ( "The metric {} ({}) was not found as registered" , m. name, m. mtype) ;
212215 continue ;
213216 } ,
214217 Some ( g) => g,
215218 } ;
216219
217- let metric = match g. get_metric_with ( & labels) {
220+ let metric = g. get_metric_with ( & labels) ;
221+ let metric = match metric {
218222 Err ( e) => {
219223 error ! ( "The metric {} {:?} ({}) was not found in MetricFamily - {}" , m. name, labels, m. mtype, e) ;
220224 continue ;
0 commit comments