Skip to content

Commit

Permalink
fix: expose FILTERED gauge, update version
Browse files Browse the repository at this point in the history
  • Loading branch information
pyxis committed Dec 13, 2023
1 parent bc50d0e commit 3df7b45
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "adb-devices-prometheus-exporter"
version = "0.1.0"
version = "0.2.1"
edition = "2021"

[dependencies]
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand All @@ -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
Expand Down
39 changes: 39 additions & 0 deletions install-plist-macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
cat > ~/Library/LaunchAgents/com.github.windsekirun.adb-devices-prometheus-exporter.plist <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/opt/homebrew/bin:/opt/homebrew/sbin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>com.github.windsekirun.adb-devices-prometheus-exporter</string>
<key>LimitLoadToSessionType</key>
<array>
<string>Aqua</string>
<string>Background</string>
<string>LoginWindow</string>
<string>StandardIO</string>
<string>System</string>
</array>
<key>ProcessType</key>
<string>Interactive</string>
<key>ProgramArguments</key>
<array>
<string>/opt/homebrew/opt/adb-devices-prometheus-exporter/bin/adb-devices-prometheus-exporter</string>
<string>-f</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
EOF

launchctl load ~/Library/LaunchAgents/com.github.windsekirun.adb-devices-prometheus-exporter.plist
launchctl start com.github.windsekirun.adb-devices-prometheus-exporter
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 3 additions & 1 deletion src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down

0 comments on commit 3df7b45

Please sign in to comment.