From 93942ef64c97d970589c86d922eb4dd0cf98161a Mon Sep 17 00:00:00 2001 From: zedprimed Date: Tue, 23 Jul 2024 18:34:03 -0500 Subject: [PATCH] Add soil moisture handling and update docs (#33) * Add soil moisture handling Add soil moisture handling * Update docs Update docs based on my own confusion through the process of getting this started: Which API metrics are currently mapped to a prometheus metric Default port * Update PrometheusHandler.cs Add humidity handling --- docs/install/setup-ambientweather-console.md | 2 +- docs/metrics.md | 105 +++---- .../AmbientWeatherPrometheusMetrics.cs | 109 ++++---- .../PrometheusMetrics/PrometheusHandler.cs | 262 ++++++++++++++---- 4 files changed, 319 insertions(+), 159 deletions(-) diff --git a/docs/install/setup-ambientweather-console.md b/docs/install/setup-ambientweather-console.md index 591199c..d9f3819 100644 --- a/docs/install/setup-ambientweather-console.md +++ b/docs/install/setup-ambientweather-console.md @@ -34,7 +34,7 @@ Additionally, the AmbientWeather Console has Wifi firmware that should be update 1. On your AmbientWeather Console find where you can configure a custom server 1. IP Address will be the IP Address of your locally running `ambientweather-local-server` - 1. Port will be the port of your locally running `ambientweather-local-server` + 1. Port will be the port of your locally running `ambientweather-local-server` ex. 8080 by default 1. Path should be: `/api/ambientweather/metrics?` 1. The question mark at the end is required 1. Save your settings diff --git a/docs/metrics.md b/docs/metrics.md index a2453a0..77d00a2 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -23,58 +23,59 @@ Metrics from your local Console can be identified by filtering on `source=local` The metrics provided by your local Console may vary by model. [AmbientWeather provides](https://github.com/ambient-weather/api-docs/wiki/Device-Data-Specs) the below list of possible data: -```text -winddir - instantaneous wind direction, 0-360º -windspeedmph - instantaneous wind speed, mph -windgustmph - max wind speed in the last 10 minutes, mph -maxdailygust - Maximum wind speed in last day, mph -windgustdir - Wind direction at which the wind gust occurred, 0-360º -windspdmph_avg2m - Average wind speed, 2 minute average, mph -winddir_avg2m - Average wind direction, 2 minute average, mph -windspdmph_avg10m - Average wind speed, 10 minute average, mph -winddir_avg10m - Average wind direction, 10 minute average, 0-360º -humidity - Outdoor Humidity, 0-100% -humidity1...humidity10 - humidity 1...10, 0-100% -humidityin - Indoor Humidity, 0-100% -tempf - Outdoor Temperature, ºF -temp1f...temp10f - Temperature 1...10, ºF -soiltemp1f...soiltemp10f - Temperature 1...10, ºF -soilhum1...soilhum10 - Temperature 1...10, % -tempinf - Indoor Temperature, ºF -battout - Outdoor Battery - OK/Low indication, Int, 1=OK, 0=Low (Meteobridge Users 1=Low, 0=OK) -battin - Indoor Battery - OK/Low indication, Int, 1=OK, 0=Low (Meteobridge Users 1=Low, 0=OK) -batt1...batt10 - OK/Low indication, Int, 1=OK, 0=Low (Meteobridge Users 1=Low, 0=OK) -batt_25 - PM2.5 Air Quality Sensor Battery indication, OK/Low indication, Int, 1=OK, 0=Low (Meteobridge Users 1=Low, 0=OK) -batt_lightning - Lightning Detector Battery - 1=Low 0=OK -batleak1...batleak4 - Leak Detector Battery - 1=Low 0=OK -battsm1...battsm4 - Soil Moisture Battery - 1=OK, 0=Low -batt_co2 - CO2 battery - 1=OK, 0=Low -batt_cellgateway - Cellular Gateway - 1=OK, 0=Low -hourlyrainin - Hourly Rain Rate, in/hr -dailyrainin - Daily Rain, in -24hourrainin - 24 Hour Rain, in -weeklyrainin - Weekly Rain, in -monthlyrainin - Monthly Rain, in -yearlyrainin - Yearly Rain, in -eventrainin - Event Rain, in -totalrainin - Total Rain, in (since last factory reset) -baromrelin - Relative Pressure, inHg -baromabsin - Absolute Pressure, inHg -uv - Ultra-Violet Radiation Index, integer on all devices EXCEPT WS-8478. -solarradiation - Solar Radiation, W/m^2 -co2 - CO2 Meter, ppm -relay1...relay10 - Relay 1...10, 0 or 1 -pm25 - PM2.5 Air Quality, Float, µg/m^3 -pm25_24h - PM2.5 Air Quality 24 hour average, Float, µg/m^3 -pm25_in - PM2.5 Air Quality, Indoor, Float, µg/m^3 -pm25_in_24h - PM2.5 Air Quality 24 hour average, Indoor, Float, µg/m^3 -lightning_day - Lightning strikes per day, int -lightning_hour - Lightning strikes per hour, int -lightning_time - Last strike time, Datetime -lightning_distance - Distance of last lightning strike, Float, miles -tz - IANA Time Zone, String -dateutc - Datetime, int (milliseconds from 01-01-1970, rounded down to nearest minute on server) -``` +Not all measurements in the official API are handled by this server yet. The mapping indicates where the AmbientWeather API is mapped to a Prometheus metric. All Prometheus metrics are prepended with ambientweather_api_. +| API Metric | Prometheus Metric | +|:----------|:------------------| +| winddir - instantaneous wind direction, 0-360º | winddirection_deg | +| windspeedmph - instantaneous wind speed, mph | windspeed_mph | +| windgustmph - max wind speed in the last 10 minutes, mph | windspeed_mph | +| maxdailygust - Maximum wind speed in last day, mph | windspeed_mph | +| windgustdir - Wind direction at which the wind gust occurred, 0-360º | winddirection_deg | +| windspdmph_avg2m - Average wind speed, 2 minute average, mph | windspeed_mph | +| winddir_avg2m - Average wind direction, 2 minute average, mph | windspeed_mph | +| windspdmph_avg10m - Average wind speed, 10 minute average, mph | windspeed_mph | +| winddir_avg10m - Average wind direction, 10 minute average, 0-360º | winddirection_deg | +| humidity - Outdoor Humidity, 0-100% | humidity_percent | +| humidity1...humidity10 - humidity 1...10, 0-100% | | +humidityin - Indoor Humidity, 0-100%| humidity_percent | +| tempf - Outdoor Temperature, ºF | temperature_f | +| temp1f...temp10f - Temperature 1...10, ºF | temperature_f | +| soiltemp1f...soiltemp10f - Temperature 1...10, ºF | temperature_f | +| soilhum1...soilhum10 - Temperature 1...10, %| soilhum | +| tempinf - Indoor Temperature, ºF | | +| battout - Outdoor Battery - OK/Low indication, Int, 1=OK, 0=Low (Meteobridge Users 1=Low, 0=OK) | lowbattery_bool | +| battin - Indoor Battery - OK/Low indication, Int, 1=OK, 0=Low (Meteobridge Users 1=Low, 0=OK) | lowbattery_bool | +| batt1...batt10 - OK/Low indication, Int, 1=OK, 0=Low (Meteobridge Users 1=Low, 0=OK) | | +| batt_25 - PM2.5 Air Quality Sensor Battery indication, OK/Low indication, Int, 1=OK, 0=Low (Meteobridge Users 1=Low, 0=OK) | | +| batt_lightning - Lightning Detector Battery - 1=Low 0=OK | | +| batleak1...batleak4 - Leak Detector Battery - 1=Low 0=OK | | +| battsm1...battsm4 - Soil Moisture Battery - 1=OK, 0=Low| | +| batt_co2 - CO2 battery - 1=OK, 0=Low| lowbattery_bool | +| batt_cellgateway - Cellular Gateway - 1=OK, 0=Low | | +| hourlyrainin - Hourly Rain Rate, in/hr | rain_in | +| dailyrainin - Daily Rain, in| rain_in | +| 24hourrainin - 24 Hour Rain, in | +| weeklyrainin - Weekly Rain, in| rain_in | +| monthlyrainin - Monthly Rain, in | rain_in | +| yearlyrainin - Yearly Rain, in | rain_in | +| eventrainin - Event Rain, in | rain_in | +| totalrainin - Total Rain, in (since last factory reset) | | +| baromrelin - Relative Pressure, inHg | baromabsin | +| baromabsin - Absolute Pressure, inHg | baromrelin | +| uv - Ultra-Violet Radiation Index, integer on all devices EXCEPT WS-8478. | uv_index | +| solarradiation - Solar Radiation, W/m^2 | solarradiation_wm2 | +| co2 - CO2 Meter, ppm | | +| relay1...relay10 - Relay 1...10, 0 or 1 | | +| pm25 - PM2.5 Air Quality, Float, µg/m^3| | +| pm25_24h - PM2.5 Air Quality 24 hour average, Float, µg/m^3 | | +| pm25_in - PM2.5 Air Quality, Indoor, Float, µg/m^3 | | +| pm25_in_24h - PM2.5 Air Quality 24 hour average, Indoor, Float, µg/m^3 | | +| lightning_day - Lightning strikes per day, int | | +| lightning_hour - Lightning strikes per hour, int| | +| lightning_time - Last strike time, Datetime| | +| lightning_distance - Distance of last lightning strike, Float, miles| | +| tz - IANA Time Zone, String | | +| dateutc - Datetime, int (milliseconds from 01-01-1970, rounded down to nearest minute on server) | | ## AmbientWeather Network Metrics diff --git a/src/Core/MetricsHandlers/PrometheusMetrics/AmbientWeatherPrometheusMetrics.cs b/src/Core/MetricsHandlers/PrometheusMetrics/AmbientWeatherPrometheusMetrics.cs index 63b064a..1260968 100644 --- a/src/Core/MetricsHandlers/PrometheusMetrics/AmbientWeatherPrometheusMetrics.cs +++ b/src/Core/MetricsHandlers/PrometheusMetrics/AmbientWeatherPrometheusMetrics.cs @@ -1,79 +1,84 @@ using Common; using Common.Contracts; -using Prometheus; - -namespace Core.MetricsHandlers.PrometheusMetrics; - -public static class AmbientWeatherPrometheusMetrics +using Prometheus; + +namespace Core.MetricsHandlers.PrometheusMetrics; + +public static class AmbientWeatherPrometheusMetrics { - public static readonly Gauge LowBattery = Prometheus.Metrics.CreateGauge($"{Statics.MetricPrefix}_lowbattery_bool", "Gauge of Low Battery State", new GaugeConfiguration() - { - LabelNames = new[] { "type", "macAddress", "stationType", "source" } + public static readonly Gauge LowBattery = Prometheus.Metrics.CreateGauge($"{Statics.MetricPrefix}_lowbattery_bool", "Gauge of Low Battery State", new GaugeConfiguration() + { + LabelNames = new[] { "type", "macAddress", "stationType", "source" } }); - public static readonly Gauge Humidity = Prometheus.Metrics.CreateGauge($"{Statics.MetricPrefix}_humidity_percent", "Gauge of Humidity Percentage", new GaugeConfiguration() - { - LabelNames = new[] { "type", "macAddress", "stationType", "source" } + public static readonly Gauge Humidity = Prometheus.Metrics.CreateGauge($"{Statics.MetricPrefix}_humidity_percent", "Gauge of Humidity Percentage", new GaugeConfiguration() + { + LabelNames = new[] { "type", "macAddress", "stationType", "source" } }); - public static readonly Gauge Rain = Prometheus.Metrics.CreateGauge($"{Statics.MetricPrefix}_rain_in", "Gauge of Rain in Inches", new GaugeConfiguration() - { - LabelNames = new[] { "type", "macAddress", "stationType", "source" } + public static readonly Gauge Rain = Prometheus.Metrics.CreateGauge($"{Statics.MetricPrefix}_rain_in", "Gauge of Rain in Inches", new GaugeConfiguration() + { + LabelNames = new[] { "type", "macAddress", "stationType", "source" } }); - public static readonly Gauge SolarRadiation = Prometheus.Metrics.CreateGauge($"{Statics.MetricPrefix}_solarradiation_wm2", "Gauge of Solar Radiation in w/m^2", new GaugeConfiguration() - { - LabelNames = new[] { "type", "macAddress", "stationType", "source" } + public static readonly Gauge SolarRadiation = Prometheus.Metrics.CreateGauge($"{Statics.MetricPrefix}_solarradiation_wm2", "Gauge of Solar Radiation in w/m^2", new GaugeConfiguration() + { + LabelNames = new[] { "type", "macAddress", "stationType", "source" } }); - public static readonly Gauge Temperature = Prometheus.Metrics.CreateGauge($"{Statics.MetricPrefix}_temperature_f", "Gauge of Temperature in Fahrenheit", new GaugeConfiguration() - { - LabelNames = new[] { "type", "macAddress", "stationType", "source" } + public static readonly Gauge Temperature = Prometheus.Metrics.CreateGauge($"{Statics.MetricPrefix}_temperature_f", "Gauge of Temperature in Fahrenheit", new GaugeConfiguration() + { + LabelNames = new[] { "type", "macAddress", "stationType", "source" } }); - public static readonly Gauge UVIndex = Prometheus.Metrics.CreateGauge($"{Statics.MetricPrefix}_uv_index", "Gauge of UV Index", new GaugeConfiguration() - { - LabelNames = new[] { "type", "macAddress", "stationType", "source" } + public static readonly Gauge UVIndex = Prometheus.Metrics.CreateGauge($"{Statics.MetricPrefix}_uv_index", "Gauge of UV Index", new GaugeConfiguration() + { + LabelNames = new[] { "type", "macAddress", "stationType", "source" } }); - public static readonly Gauge WindDirection = Prometheus.Metrics.CreateGauge($"{Statics.MetricPrefix}_winddirection_deg", "Gauge of WindDirection 0-360deg.", new GaugeConfiguration() - { - LabelNames = new[] { "type", "macAddress", "stationType", "source" } + public static readonly Gauge WindDirection = Prometheus.Metrics.CreateGauge($"{Statics.MetricPrefix}_winddirection_deg", "Gauge of WindDirection 0-360deg.", new GaugeConfiguration() + { + LabelNames = new[] { "type", "macAddress", "stationType", "source" } }); - public static readonly Gauge WindSpeed = Prometheus.Metrics.CreateGauge($"{Statics.MetricPrefix}_windspeed_mph", "Gauge of WindSpeed in MPH", new GaugeConfiguration() - { - LabelNames = new[] { "type", "macAddress", "stationType", "source" } + public static readonly Gauge WindSpeed = Prometheus.Metrics.CreateGauge($"{Statics.MetricPrefix}_windspeed_mph", "Gauge of WindSpeed in MPH", new GaugeConfiguration() + { + LabelNames = new[] { "type", "macAddress", "stationType", "source" } }); - public static readonly Gauge FeelsLike = Prometheus.Metrics.CreateGauge($"{Statics.MetricPrefix}_feelslike_f", "Gauge of Feels Like Temperature in Fahrenheit", new GaugeConfiguration() - { - LabelNames = new[] { "type", "macAddress", "stationType", "source" } + public static readonly Gauge FeelsLike = Prometheus.Metrics.CreateGauge($"{Statics.MetricPrefix}_feelslike_f", "Gauge of Feels Like Temperature in Fahrenheit", new GaugeConfiguration() + { + LabelNames = new[] { "type", "macAddress", "stationType", "source" } }); - public static readonly Gauge DewPoint = Prometheus.Metrics.CreateGauge($"{Statics.MetricPrefix}_dewpoint_f", "Gauge of Dew Point Temperature in Fahrenheit", new GaugeConfiguration() - { - LabelNames = new[] { "type", "macAddress", "stationType", "source" } + public static readonly Gauge DewPoint = Prometheus.Metrics.CreateGauge($"{Statics.MetricPrefix}_dewpoint_f", "Gauge of Dew Point Temperature in Fahrenheit", new GaugeConfiguration() + { + LabelNames = new[] { "type", "macAddress", "stationType", "source" } + }); + + public static readonly Gauge BaromRelIn = Prometheus.Metrics.CreateGauge($"{Statics.MetricPrefix}_baromrelin", "Gauge of Relative Barometric Pressure in in-Hg", new GaugeConfiguration() + { + LabelNames = new[] { "type", "macAddress", "stationType", "source" } + }); + + public static readonly Gauge BaromAbsIn = Prometheus.Metrics.CreateGauge($"{Statics.MetricPrefix}_baromabsin", "Gauge of Absolute Barometric Pressure in in-Hg", new GaugeConfiguration() + { + LabelNames = new[] { "type", "macAddress", "stationType", "source" } + }); + + public static readonly Gauge SoilHum = Prometheus.Metrics.CreateGauge($"{Statics.MetricPrefix}_soilhum", "Gauge of Soil Moisture in %", new GaugeConfiguration() + { + LabelNames = new[] { "type", "macAddress", "stationType", "source" } + }); + + public static readonly Gauge DateUtc = Prometheus.Metrics.CreateGauge($"{Statics.MetricPrefix}_dateutc", "Gauge of Date and Time UTC", new GaugeConfiguration() + { + LabelNames = new[] { "type", "macAddress", "stationType", "source" } }); - - public static readonly Gauge BaromRelIn = Prometheus.Metrics.CreateGauge($"{Statics.MetricPrefix}_baromrelin", "Gauge of Relative Barometric Pressure in in-Hg", new GaugeConfiguration() - { - LabelNames = new[] { "type", "macAddress", "stationType", "source" } - }); - - public static readonly Gauge BaromAbsIn = Prometheus.Metrics.CreateGauge($"{Statics.MetricPrefix}_baromabsin", "Gauge of Absolute Barometric Pressure in in-Hg", new GaugeConfiguration() - { - LabelNames = new[] { "type", "macAddress", "stationType", "source" } - }); - - public static readonly Gauge DateUtc = Prometheus.Metrics.CreateGauge($"{Statics.MetricPrefix}_dateutc", "Gauge of Date and Time UTC", new GaugeConfiguration() - { - LabelNames = new[] { "type", "macAddress", "stationType", "source" } - }); public static TChild WithLabels(this Collector collector, string type, IAmbientWeatherMetrics metrics) where TChild : Prometheus.ChildBase { return collector.WithLabels(type, metrics.Mac ?? metrics.PassKey ?? "none", metrics.StationType ?? "none", Enum.GetName(metrics.Source)?.ToLower() ?? "Unknown"); - } -} + } +} diff --git a/src/Core/MetricsHandlers/PrometheusMetrics/PrometheusHandler.cs b/src/Core/MetricsHandlers/PrometheusMetrics/PrometheusHandler.cs index 79197f2..3b2ec23 100644 --- a/src/Core/MetricsHandlers/PrometheusMetrics/PrometheusHandler.cs +++ b/src/Core/MetricsHandlers/PrometheusMetrics/PrometheusHandler.cs @@ -1,11 +1,11 @@ -using Common.Contracts; +using Common.Contracts; using Common.Observe; -namespace Core.MetricsHandlers.PrometheusMetrics; - -public class PrometheusHandler : IMetricsHandler -{ - public Task ProcessAsync(IAmbientWeatherMetrics metrics) +namespace Core.MetricsHandlers.PrometheusMetrics; + +public class PrometheusHandler : IMetricsHandler +{ + public Task ProcessAsync(IAmbientWeatherMetrics metrics) { using var trace = Tracing.Trace($"{nameof(PrometheusHandler)}.{nameof(ProcessAsync)}"); @@ -16,13 +16,14 @@ public Task ProcessAsync(IAmbientWeatherMetrics metrics) ProcessRain(metrics); ProcessSolarRadiation(metrics); ProcessTemperature(metrics); - ProcessUVIndex(metrics); + ProcessUVIndex(metrics); ProcessWindDirection(metrics); - ProcessWindSpeed(metrics); - ProcessPressure(metrics); - ProcessDateUTC(metrics); - - return Task.CompletedTask; + ProcessWindSpeed(metrics); + ProcessPressure(metrics); + ProcessDateUTC(metrics); + ProcessSoilMoist(metrics); + + return Task.CompletedTask; } public void ProcessHumditiy(IAmbientWeatherMetrics metrics) @@ -42,6 +43,87 @@ public void ProcessHumditiy(IAmbientWeatherMetrics metrics) .WithLabels("indoor", metrics) .Set(metrics.HumidityIn.Value); } + + + if (metrics.Humidity1.HasValue) + { + AmbientWeatherPrometheusMetrics + .Humidity + .WithLabels("hum01", metrics) + .Set(metrics.Humidity1.Value); + } + + if (metrics.Humidity2.HasValue) + { + AmbientWeatherPrometheusMetrics + .Humidity + .WithLabels("hum02", metrics) + .Set(metrics.Humidity2.Value); + } + + if (metrics.Humidity3.HasValue) + { + AmbientWeatherPrometheusMetrics + .Humidity + .WithLabels("hum03", metrics) + .Set(metrics.Humidity3.Value); + } + + if (metrics.Humidity4.HasValue) + { + AmbientWeatherPrometheusMetrics + .Humidity + .WithLabels("hum04", metrics) + .Set(metrics.Humidity4.Value); + } + + if (metrics.Humidity5.HasValue) + { + AmbientWeatherPrometheusMetrics + .Humidity + .WithLabels("hum05", metrics) + .Set(metrics.Humidity5.Value); + } + + if (metrics.Humidity6.HasValue) + { + AmbientWeatherPrometheusMetrics + .Humidity + .WithLabels("hum06", metrics) + .Set(metrics.Humidity6.Value); + } + + if (metrics.Humidity7.HasValue) + { + AmbientWeatherPrometheusMetrics + .Humidity + .WithLabels("hum07", metrics) + .Set(metrics.Humidity7.Value); + } + + if (metrics.Humidity8.HasValue) + { + AmbientWeatherPrometheusMetrics + .Humidity + .WithLabels("hum08", metrics) + .Set(metrics.Humidity8.Value); + } + + if (metrics.Humidity9.HasValue) + { + AmbientWeatherPrometheusMetrics + .Humidity + .WithLabels("hum09", metrics) + .Set(metrics.Humidity9.Value); + } + + if (metrics.Humidity10.HasValue) + { + AmbientWeatherPrometheusMetrics + .Humidity + .WithLabels("hum10", metrics) + .Set(metrics.Humidity10.Value); + } } public void ProcessLowBattery(IAmbientWeatherMetrics metrics) @@ -131,7 +213,7 @@ public void ProcessSolarRadiation(IAmbientWeatherMetrics metrics) .WithLabels("solarradiation", metrics) .Set(metrics.SolarRadiation.Value); } - } + } public void ProcessTemperature(IAmbientWeatherMetrics metrics) { @@ -331,39 +413,39 @@ public void ProcessUVIndex(IAmbientWeatherMetrics metrics) } } - public void ProcessWindDirection(IAmbientWeatherMetrics metrics) - { - if (metrics.WindDir.HasValue) - { - AmbientWeatherPrometheusMetrics - .WindDirection - .WithLabels("wind", metrics) - .Set(metrics.WindDir.Value); - } - - if (metrics.WindGustDir.HasValue) - { - AmbientWeatherPrometheusMetrics - .WindDirection - .WithLabels("gust", metrics) - .Set(metrics.WindGustDir.Value); - } - - if (metrics.WindDir_Avg2m.HasValue) - { - AmbientWeatherPrometheusMetrics - .WindDirection - .WithLabels("2mAvg", metrics) - .Set(metrics.WindDir_Avg2m.Value); - } - - if (metrics.WindDir_Avg10m.HasValue) - { - AmbientWeatherPrometheusMetrics - .WindDirection - .WithLabels("10mAvg", metrics) - .Set(metrics.WindDir_Avg10m.Value); - } + public void ProcessWindDirection(IAmbientWeatherMetrics metrics) + { + if (metrics.WindDir.HasValue) + { + AmbientWeatherPrometheusMetrics + .WindDirection + .WithLabels("wind", metrics) + .Set(metrics.WindDir.Value); + } + + if (metrics.WindGustDir.HasValue) + { + AmbientWeatherPrometheusMetrics + .WindDirection + .WithLabels("gust", metrics) + .Set(metrics.WindGustDir.Value); + } + + if (metrics.WindDir_Avg2m.HasValue) + { + AmbientWeatherPrometheusMetrics + .WindDirection + .WithLabels("2mAvg", metrics) + .Set(metrics.WindDir_Avg2m.Value); + } + + if (metrics.WindDir_Avg10m.HasValue) + { + AmbientWeatherPrometheusMetrics + .WindDirection + .WithLabels("10mAvg", metrics) + .Set(metrics.WindDir_Avg10m.Value); + } } public void ProcessWindSpeed(IAmbientWeatherMetrics metrics) @@ -606,7 +688,7 @@ public void ProcessDewPoint(IAmbientWeatherMetrics metrics) .Set(metrics.DewPoint10.Value); } } - + public void ProcessPressure(IAmbientWeatherMetrics metrics) { if (metrics.BaromRelIn.HasValue) @@ -616,7 +698,7 @@ public void ProcessPressure(IAmbientWeatherMetrics metrics) .WithLabels("baromrelin", metrics) .Set(metrics.BaromRelIn.Value); } - + if (metrics.BaromAbsIn.HasValue) { AmbientWeatherPrometheusMetrics @@ -624,19 +706,91 @@ public void ProcessPressure(IAmbientWeatherMetrics metrics) .WithLabels("baromabsin", metrics) .Set(metrics.BaromAbsIn.Value); } - } - + } +public void ProcessSoilMoist(IAmbientWeatherMetrics metrics) + { + if (metrics.SoilHum1.HasValue) + { + AmbientWeatherPrometheusMetrics + .SoilHum + .WithLabels("soilhum1", metrics) + .Set(metrics.SoilHum1.Value); + } + if (metrics.SoilHum2.HasValue) + { + AmbientWeatherPrometheusMetrics + .SoilHum + .WithLabels("soilhum2", metrics) + .Set(metrics.SoilHum2.Value); + } + if (metrics.SoilHum3.HasValue) + { + AmbientWeatherPrometheusMetrics + .SoilHum + .WithLabels("soilhum3", metrics) + .Set(metrics.SoilHum3.Value); + } + if (metrics.SoilHum1.HasValue) + { + AmbientWeatherPrometheusMetrics + .SoilHum + .WithLabels("soilhum4", metrics) + .Set(metrics.SoilHum4.Value); + } + if (metrics.SoilHum5.HasValue) + { + AmbientWeatherPrometheusMetrics + .SoilHum + .WithLabels("soilhum5", metrics) + .Set(metrics.SoilHum5.Value); + } + if (metrics.SoilHum6.HasValue) + { + AmbientWeatherPrometheusMetrics + .SoilHum + .WithLabels("soilhum6", metrics) + .Set(metrics.SoilHum6.Value); + } + if (metrics.SoilHum7.HasValue) + { + AmbientWeatherPrometheusMetrics + .SoilHum + .WithLabels("soilhum7", metrics) + .Set(metrics.SoilHum7.Value); + } + if (metrics.SoilHum8.HasValue) + { + AmbientWeatherPrometheusMetrics + .SoilHum + .WithLabels("soilhum8", metrics) + .Set(metrics.SoilHum8.Value); + } if (metrics.SoilHum9.HasValue) + { + AmbientWeatherPrometheusMetrics + .SoilHum + .WithLabels("soilhum9", metrics) + .Set(metrics.SoilHum9.Value); + } + if (metrics.SoilHum10.HasValue) + { + AmbientWeatherPrometheusMetrics + .SoilHum + .WithLabels("soilhum10", metrics) + .Set(metrics.SoilHum10.Value); + } + } + public void ProcessDateUTC(IAmbientWeatherMetrics metrics) { if (metrics.DateUtc.HasValue) { - // Write UTC timestamp as UNIX time in milliseconds, as that's how Grafana wants it. - DateTimeOffset DateUtcOff = new DateTimeOffset(DateTime.SpecifyKind(metrics.DateUtc.Value, DateTimeKind.Utc)); + // Write UTC timestamp as UNIX time in milliseconds, as that's how Grafana wants it. + DateTimeOffset DateUtcOff = new DateTimeOffset(DateTime.SpecifyKind(metrics.DateUtc.Value, DateTimeKind.Utc)); AmbientWeatherPrometheusMetrics .DateUtc .WithLabels("dateutc", metrics) .Set(DateUtcOff.ToUnixTimeMilliseconds()); } - } + } -} +}