From fdd69a29bcd34e393775a065224d017e1ae6cd6d Mon Sep 17 00:00:00 2001 From: Markus Dobel Date: Thu, 8 Jun 2023 16:47:55 +0200 Subject: [PATCH] feat: add metrics for Wifi and MQTT status --- .../shelly/exporter/client/api/Settings.kt | 17 +++++---- .../shelly/exporter/client/api/Shelly.kt | 2 +- .../shelly/exporter/client/api/Status.kt | 37 +++++++++++++++++-- .../shelly/exporter/metrics/ShellyMetrics.kt | 33 ++++++++++++++++- 4 files changed, 75 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/click/dobel/shelly/exporter/client/api/Settings.kt b/src/main/kotlin/click/dobel/shelly/exporter/client/api/Settings.kt index e686681..a683a6f 100644 --- a/src/main/kotlin/click/dobel/shelly/exporter/client/api/Settings.kt +++ b/src/main/kotlin/click/dobel/shelly/exporter/client/api/Settings.kt @@ -10,20 +10,21 @@ data class Settings( @JsonProperty("lng") val lng: Double, @JsonProperty("led_status_disable") - val ledStatusDisable: Boolean, + val isStatusLedDisabled: Boolean, @JsonProperty("fw") val firmwareVersion: String, @JsonProperty("device") val device: Device, - @JsonProperty("cloud") - val cloud: Cloud, + + @JsonProperty("ap_roaming") + val apRoaming: ApRoaming, // Shelly Plug only @JsonProperty("max_power") val maxPower: Double?, @JsonProperty("led_power_disable") - val ledPowerDisable: Boolean?, + val isPowerLedDisabled: Boolean?, ) { data class Device( @@ -39,10 +40,10 @@ data class Settings( val meterCount: Int, ) - data class Cloud( + data class ApRoaming( @JsonProperty("enabled") - val enabled: Boolean, - @JsonProperty("connected") - val connected: Boolean + val isEnabled: Boolean, + @JsonProperty("threshold") + val threshold: Int, ) } diff --git a/src/main/kotlin/click/dobel/shelly/exporter/client/api/Shelly.kt b/src/main/kotlin/click/dobel/shelly/exporter/client/api/Shelly.kt index b0f1e36..ab43f38 100644 --- a/src/main/kotlin/click/dobel/shelly/exporter/client/api/Shelly.kt +++ b/src/main/kotlin/click/dobel/shelly/exporter/client/api/Shelly.kt @@ -12,5 +12,5 @@ data class Shelly( @JsonProperty("fw") val firmwareVersion: String, @JsonProperty("longid") - val longId: Boolean, + val hasLongId: Boolean, ) diff --git a/src/main/kotlin/click/dobel/shelly/exporter/client/api/Status.kt b/src/main/kotlin/click/dobel/shelly/exporter/client/api/Status.kt index be9bb04..c61adc2 100644 --- a/src/main/kotlin/click/dobel/shelly/exporter/client/api/Status.kt +++ b/src/main/kotlin/click/dobel/shelly/exporter/client/api/Status.kt @@ -9,7 +9,6 @@ data class Status( @JsonProperty("meters") val meters: List, - @JsonProperty("ram_total") val ramTotal: Long, @JsonProperty("ram_free") @@ -27,12 +26,21 @@ data class Status( @JsonProperty("update") val update: Update, + @JsonProperty("wifi_sta") + val wifiSta: WifiSta, + + @JsonProperty("mqtt") + val mqtt: Mqtt, + + @JsonProperty("cloud") + val cloud: Cloud, + // Following properties available on Plug S only // val temperature: Double?, @JsonProperty("overtemperature") val overTemperature: Boolean?, @JsonProperty("tmp") - val temperature: Temperature? + val temperature: Temperature?, ) { data class Relay( @@ -79,7 +87,7 @@ data class Status( @JsonProperty("tF") val fahrenheit: Double, @JsonProperty("is_valid") - val isValid: Boolean + val isValid: Boolean, ) data class Update( @@ -88,4 +96,27 @@ data class Status( @JsonProperty("has_update") val hasUpdate: Boolean, ) + + data class WifiSta( + @JsonProperty("connected") + val isConnected: Boolean, + @JsonProperty("ssid") + val ssid: String, + @JsonProperty("ip") + val ip: String, + @JsonProperty("rssi") + val rssi: Int, + ) + + data class Mqtt( + @JsonProperty("connected") + val isConnected: Boolean, + ) + + data class Cloud( + @JsonProperty("enabled") + val isEnabled: Boolean, + @JsonProperty("connected") + val isConnected: Boolean, + ) } diff --git a/src/main/kotlin/click/dobel/shelly/exporter/metrics/ShellyMetrics.kt b/src/main/kotlin/click/dobel/shelly/exporter/metrics/ShellyMetrics.kt index 129da02..4ac15a2 100644 --- a/src/main/kotlin/click/dobel/shelly/exporter/metrics/ShellyMetrics.kt +++ b/src/main/kotlin/click/dobel/shelly/exporter/metrics/ShellyMetrics.kt @@ -65,12 +65,41 @@ class ShellyMetrics( "cloud.enabled", "Whether Shelly cloud is enabled.", tags - ) { settings(address)?.cloud?.enabled } + ) { status(address)?.cloud?.isEnabled } boolGauge( "cloud.connected", "Whether Shelly cloud is connected.", tags - ) { settings(address)?.cloud?.connected } + ) { status(address)?.cloud?.isConnected } + + boolGauge( + "wifi.connected", + "Whether Shelly is connected to WIFI.", + tags + ) { status(address)?.wifiSta?.isConnected } + gauge( + "wifi.rssi", + "Current Wifi Received Signal Strength Indication (RSSI).", + "dbmw", + tags + ) { status(address)?.wifiSta?.rssi } + boolGauge( + "wifi.roaming.enabled", + "Whether AP roaming is enabled.", + tags + ) { settings(address)?.apRoaming?.isEnabled } + gauge( + "wifi.roaming.threshold", + "RSSI signal strength value below which the device will periodically scan for better access point.", + "dbmw", + tags + ) { settings(address)?.apRoaming?.threshold } + + boolGauge( + "mqtt.connected", + "Whether Shelly is connected to MQTT server.", + tags + ) { status(address)?.mqtt?.isConnected } gauge( "location.latitude",