Skip to content

Commit 317933c

Browse files
committed
Dep update + fix lints
1 parent 9f5c53c commit 317933c

File tree

4 files changed

+59
-60
lines changed

4 files changed

+59
-60
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
66

77
## [Unreleased]
88

9+
## 0.2.14 - 2022-06-14
10+
11+
- Update deps
12+
- Fix lints
13+
914
## 0.2.13 - 2022-06-03
1015

1116
- Fix crash when missing or none values are found

Cargo.lock

Lines changed: 35 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sio2prom"
3-
version = "0.2.13"
3+
version = "0.2.14"
44
edition = "2021"
55
authors = ["Sebastian YEPES F <[email protected]>"]
66
keywords = ["prometheus", "metrics", "scaleio", "VxFlex", "PowerFlex"]
@@ -26,14 +26,14 @@ publish = true
2626
[dependencies]
2727
log = "0.4.*"
2828
env_logger = "0.9.*"
29-
tokio = { version = "1.18.*", features = ["macros", "time", "rt-multi-thread"] }
29+
tokio = { version = "1.19.*", features = ["macros", "time", "rt-multi-thread"] }
3030
futures = { version = "0.3.*", default-features = false }
3131
reqwest = { version = "0.11.*", features = ["json"] }
3232
serde = { version = "1.0.*", features = ["derive"] }
3333
serde_json = { version = "1.0.*", features = ["raw_value"] }
3434
anyhow = "1.0.*"
3535
chrono = "0.4.*"
36-
clap = { version = "3.1.*", default-features = false, features = [
36+
clap = { version = "3.2.*", default-features = false, features = [
3737
"std",
3838
"color",
3939
"cargo",

src/main.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

8585
async 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

Comments
 (0)