diff --git a/Cargo.lock b/Cargo.lock index 1675b46..a7764fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "adb-devices-prometheus-exporter" -version = "0.1.0" +version = "0.2.1" dependencies = [ "axum", "clap", diff --git a/Cargo.toml b/Cargo.toml index dcd0378..bc53ca6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "adb-devices-prometheus-exporter" -version = "0.1.0" +version = "0.2.1" edition = "2021" [dependencies] diff --git a/README.md b/README.md index fd10775..4d6325c 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,14 @@ connected_android_device_state_fastbootd 0 # HELP connected_android_device_state_bootloader Number of Android devices connected in 'bootloader' status # TYPE connected_android_device_state_bootloader gauge connected_android_device_state_bootloader 0 + +# HELP connected_android_device_state_filtered Number of Android devices connected in 'FILTERED' status +# TYPE connected_android_device_state_filtered gauge +connected_android_device_state_filtered 0 ``` +* `connected_android_device_state_filtered` is available with -f options in v0.2.1 or newer + ## Usage ``` @@ -65,6 +71,9 @@ brew install adb-devices-prometheus-exporter // manage by background service (launchctl on macos) brew services start adb-devices-prometheus-exporter + +// or, use launchctl instead +sh install-plist-macos.sh ``` access http://0.0.0.0:9001/metrics diff --git a/install-plist-macos.sh b/install-plist-macos.sh new file mode 100644 index 0000000..880730e --- /dev/null +++ b/install-plist-macos.sh @@ -0,0 +1,39 @@ +cat > ~/Library/LaunchAgents/com.github.windsekirun.adb-devices-prometheus-exporter.plist < + + + + EnvironmentVariables + + PATH + /opt/homebrew/bin:/opt/homebrew/sbin:/usr/bin:/bin:/usr/sbin:/sbin + + KeepAlive + + Label + com.github.windsekirun.adb-devices-prometheus-exporter + LimitLoadToSessionType + + Aqua + Background + LoginWindow + StandardIO + System + + ProcessType + Interactive + ProgramArguments + + /opt/homebrew/opt/adb-devices-prometheus-exporter/bin/adb-devices-prometheus-exporter + -f + + RunAtLoad + + + + +EOF + +launchctl load ~/Library/LaunchAgents/com.github.windsekirun.adb-devices-prometheus-exporter.plist +launchctl start com.github.windsekirun.adb-devices-prometheus-exporter \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 09f5793..a07ec76 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,5 +49,6 @@ async fn metrics() -> String { result.push_str(&add_device_metrics_state(&device_infos, "offline")); result.push_str(&add_device_metrics_state(&device_infos, "fastbootd")); result.push_str(&add_device_metrics_state(&device_infos, "bootloader")); + result.push_str(&add_device_metrics_state(&device_infos, "FILTERED")); return result; } \ No newline at end of file diff --git a/src/metrics.rs b/src/metrics.rs index c23e9ce..d3a5f5c 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -47,8 +47,10 @@ pub fn add_device_metrics_state(device_infos: &[DeviceInfo], state: &str) -> Str .filter(|device| device.state == state) .count(); + let lowercase_state = state.to_ascii_lowercase(); + let gauge = PrometheusMetricsBuilder::default() - .key(format!("connected_android_device_state_{state}")) + .key(format!("connected_android_device_state_{lowercase_state}")) .value(value) .metric_type("gauge") .help_str(format!(