Skip to content

Commit

Permalink
Add soil moisture handling and update docs (#33)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
zedprimed authored Jul 23, 2024
1 parent fe99ce0 commit 93942ef
Show file tree
Hide file tree
Showing 4 changed files with 319 additions and 159 deletions.
2 changes: 1 addition & 1 deletion docs/install/setup-ambientweather-console.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
105 changes: 53 additions & 52 deletions docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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<TChild>(this Collector<TChild> 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");
}
}
}
}
Loading

0 comments on commit 93942ef

Please sign in to comment.