Compare commits
20 Commits
96dfcf7e53
...
v0.5.2
Author | SHA1 | Date | |
---|---|---|---|
eaf2cf211d | |||
e8fbacfe6d | |||
19823ea08f | |||
7fc1fc9b56 | |||
849dbfb6ff | |||
dc2470da71 | |||
c23177b62d | |||
86653cf589 | |||
fa0a9f4ddc | |||
689790fe86 | |||
3af1cc40a5 | |||
4ff684abe3 | |||
87f0cbac01 | |||
4c93303f27 | |||
e8654e76bc | |||
54f725c822 | |||
c002331fd4 | |||
2ed4eca56c | |||
2e3cfb44f4 | |||
be8a4f3bca |
16
TODO.md
16
TODO.md
@ -1,11 +1,21 @@
|
|||||||
# TODO
|
# TODO
|
||||||
- [ ] Fix shutdown
|
|
||||||
- [ ] Configuration for app
|
|
||||||
- [ ] Helm Chart
|
- [ ] Helm Chart
|
||||||
- [ ] Update README
|
- [ ] Update README
|
||||||
- [ ] Add new fields from WS-2192
|
- [ ] Add Grafana dashboard
|
||||||
|
- [ ] Add proxy to upstream support
|
||||||
|
- [ ] Add new spans
|
||||||
|
- [ ] Fix wunderground 401
|
||||||
|
- [ ] Perform proxy calls in goroutines
|
||||||
|
|
||||||
## Done
|
## Done
|
||||||
|
- [x] Configuration for app
|
||||||
|
- [x] Configurable metric prefix
|
||||||
|
- [x] Add device name field with ID/Key mappings
|
||||||
|
- [x] Add device type field with ID/Key mappings
|
||||||
|
- [x] Move EVERYTHING to pointers to support nil
|
||||||
|
- [x] Consolidate battery status into one metric with device label
|
||||||
|
- [x] Fix shutdown
|
||||||
|
- [x] Add new fields from WS-2192
|
||||||
- [x] Gitea CI
|
- [x] Gitea CI
|
||||||
- [x] Version flag
|
- [x] Version flag
|
||||||
- [x] Makefile
|
- [x] Makefile
|
||||||
|
16
go.mod
16
go.mod
@ -3,12 +3,14 @@ module gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter
|
|||||||
go 1.23.4
|
go 1.23.4
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gitea.libretechconsulting.com/rmcguire/go-app v0.2.0
|
gitea.libretechconsulting.com/rmcguire/go-app v0.3.1
|
||||||
|
github.com/go-resty/resty/v2 v2.16.3
|
||||||
github.com/gorilla/schema v1.4.1
|
github.com/gorilla/schema v1.4.1
|
||||||
github.com/rs/zerolog v1.33.0
|
github.com/rs/zerolog v1.33.0
|
||||||
go.opentelemetry.io/otel v1.33.0
|
go.opentelemetry.io/otel v1.33.0
|
||||||
go.opentelemetry.io/otel/metric v1.33.0
|
go.opentelemetry.io/otel/metric v1.33.0
|
||||||
golang.org/x/sys v0.29.0
|
golang.org/x/sys v0.29.0
|
||||||
|
k8s.io/utils v0.0.0-20241210054802-24370beab758
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@ -22,7 +24,7 @@ require (
|
|||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1 // indirect
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1 // indirect
|
||||||
github.com/klauspost/compress v1.17.11 // indirect
|
github.com/klauspost/compress v1.17.11 // indirect
|
||||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||||
github.com/prometheus/client_golang v1.20.5 // indirect
|
github.com/prometheus/client_golang v1.20.5 // indirect
|
||||||
@ -40,12 +42,12 @@ require (
|
|||||||
go.opentelemetry.io/otel/sdk v1.33.0 // indirect
|
go.opentelemetry.io/otel/sdk v1.33.0 // indirect
|
||||||
go.opentelemetry.io/otel/sdk/metric v1.33.0 // indirect
|
go.opentelemetry.io/otel/sdk/metric v1.33.0 // indirect
|
||||||
go.opentelemetry.io/otel/trace v1.33.0 // indirect
|
go.opentelemetry.io/otel/trace v1.33.0 // indirect
|
||||||
go.opentelemetry.io/proto/otlp v1.4.0 // indirect
|
go.opentelemetry.io/proto/otlp v1.5.0 // indirect
|
||||||
golang.org/x/net v0.33.0 // indirect
|
golang.org/x/net v0.34.0 // indirect
|
||||||
golang.org/x/text v0.21.0 // indirect
|
golang.org/x/text v0.21.0 // indirect
|
||||||
google.golang.org/genproto/googleapis/api v0.0.0-20250102185135-69823020774d // indirect
|
google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422 // indirect
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250102185135-69823020774d // indirect
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422 // indirect
|
||||||
google.golang.org/grpc v1.69.2 // indirect
|
google.golang.org/grpc v1.69.2 // indirect
|
||||||
google.golang.org/protobuf v1.36.1 // indirect
|
google.golang.org/protobuf v1.36.2 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
35
go.sum
35
go.sum
@ -1,7 +1,5 @@
|
|||||||
gitea.libretechconsulting.com/rmcguire/go-app v0.1.3 h1:EwmEJLpN+rQjJ5stGEkZsqEDa5F/YnDAEeqJB9XlFn4=
|
gitea.libretechconsulting.com/rmcguire/go-app v0.3.1 h1:jydcJ+Vv8sk+Le7nTI2+b6E7FfV+ShBJo7YdxmdaCYc=
|
||||||
gitea.libretechconsulting.com/rmcguire/go-app v0.1.3/go.mod h1:wHOWh4O4AMDATQ3WEUYjq5a5bnICPBpu5G6BsNxqN38=
|
gitea.libretechconsulting.com/rmcguire/go-app v0.3.1/go.mod h1:wHOWh4O4AMDATQ3WEUYjq5a5bnICPBpu5G6BsNxqN38=
|
||||||
gitea.libretechconsulting.com/rmcguire/go-app v0.2.0 h1:pOm/PysC0IWPuEbmEjNSHHa8Qc5OhuoksYExcuJMFE4=
|
|
||||||
gitea.libretechconsulting.com/rmcguire/go-app v0.2.0/go.mod h1:wHOWh4O4AMDATQ3WEUYjq5a5bnICPBpu5G6BsNxqN38=
|
|
||||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||||
github.com/caarlos0/env/v11 v11.3.1 h1:cArPWC15hWmEt+gWk7YBi7lEXTXCvpaSdCiZE2X5mCA=
|
github.com/caarlos0/env/v11 v11.3.1 h1:cArPWC15hWmEt+gWk7YBi7lEXTXCvpaSdCiZE2X5mCA=
|
||||||
@ -20,6 +18,8 @@ github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
|||||||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||||
|
github.com/go-resty/resty/v2 v2.16.3 h1:zacNT7lt4b8M/io2Ahj6yPypL7bqx9n1iprfQuodV+E=
|
||||||
|
github.com/go-resty/resty/v2 v2.16.3/go.mod h1:hkJtXbA2iKHzJheXYvQ8snQES5ZLGKMwQ07xAwp/fiA=
|
||||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||||
@ -39,8 +39,9 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
|||||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
||||||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
|
||||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||||
|
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
|
||||||
|
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
|
||||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||||
@ -91,12 +92,12 @@ go.opentelemetry.io/otel/sdk/metric v1.33.0 h1:Gs5VK9/WUJhNXZgn8MR6ITatvAmKeIuCt
|
|||||||
go.opentelemetry.io/otel/sdk/metric v1.33.0/go.mod h1:dL5ykHZmm1B1nVRk9dDjChwDmt81MjVp3gLkQRwKf/Q=
|
go.opentelemetry.io/otel/sdk/metric v1.33.0/go.mod h1:dL5ykHZmm1B1nVRk9dDjChwDmt81MjVp3gLkQRwKf/Q=
|
||||||
go.opentelemetry.io/otel/trace v1.33.0 h1:cCJuF7LRjUFso9LPnEAHJDB2pqzp+hbO8eu1qqW2d/s=
|
go.opentelemetry.io/otel/trace v1.33.0 h1:cCJuF7LRjUFso9LPnEAHJDB2pqzp+hbO8eu1qqW2d/s=
|
||||||
go.opentelemetry.io/otel/trace v1.33.0/go.mod h1:uIcdVUZMpTAmz0tI1z04GoVSezK37CbGV4fr1f2nBck=
|
go.opentelemetry.io/otel/trace v1.33.0/go.mod h1:uIcdVUZMpTAmz0tI1z04GoVSezK37CbGV4fr1f2nBck=
|
||||||
go.opentelemetry.io/proto/otlp v1.4.0 h1:TA9WRvW6zMwP+Ssb6fLoUIuirti1gGbP28GcKG1jgeg=
|
go.opentelemetry.io/proto/otlp v1.5.0 h1:xJvq7gMzB31/d406fB8U5CBdyQGw4P399D1aQWU/3i4=
|
||||||
go.opentelemetry.io/proto/otlp v1.4.0/go.mod h1:PPBWZIP98o2ElSqI35IHfu7hIhSwvc5N38Jw8pXuGFY=
|
go.opentelemetry.io/proto/otlp v1.5.0/go.mod h1:keN8WnHxOy8PG0rQZjJJ5A2ebUoafqWp0eVQ4yIXvJ4=
|
||||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||||
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
|
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
|
||||||
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
|
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
|
||||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
@ -104,16 +105,20 @@ golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
|
|||||||
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
||||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||||
google.golang.org/genproto/googleapis/api v0.0.0-20250102185135-69823020774d h1:H8tOf8XM88HvKqLTxe755haY6r1fqqzLbEnfrmLXlSA=
|
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
|
||||||
google.golang.org/genproto/googleapis/api v0.0.0-20250102185135-69823020774d/go.mod h1:2v7Z7gP2ZUOGsaFyxATQSRoBnKygqVq2Cwnvom7QiqY=
|
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250102185135-69823020774d h1:xJJRGY7TJcvIlpSrN3K6LAWgNFUILlO+OMAqtg9aqnw=
|
google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422 h1:GVIKPyP/kLIyVOgOnTwFOrvQaQUzOzGMCxgFUOEmm24=
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250102185135-69823020774d/go.mod h1:3ENsm/5D1mzDyhpzeRi1NR784I0BcofWBoSc5QqqMK4=
|
google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422/go.mod h1:b6h1vNKhxaSoEI+5jc3PJUCustfli/mRab7295pY7rw=
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422 h1:3UsHvIr4Wc2aW4brOaSCmcxh9ksica6fHEr8P1XhkYw=
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422/go.mod h1:3ENsm/5D1mzDyhpzeRi1NR784I0BcofWBoSc5QqqMK4=
|
||||||
google.golang.org/grpc v1.69.2 h1:U3S9QEtbXC0bYNvRtcoklF3xGtLViumSYxWykJS+7AU=
|
google.golang.org/grpc v1.69.2 h1:U3S9QEtbXC0bYNvRtcoklF3xGtLViumSYxWykJS+7AU=
|
||||||
google.golang.org/grpc v1.69.2/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4=
|
google.golang.org/grpc v1.69.2/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4=
|
||||||
google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk=
|
google.golang.org/protobuf v1.36.2 h1:R8FeyR1/eLmkutZOM5CWghmo5itiG9z0ktFlTVLuTmU=
|
||||||
google.golang.org/protobuf v1.36.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
google.golang.org/protobuf v1.36.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
k8s.io/utils v0.0.0-20241210054802-24370beab758 h1:sdbE21q2nlQtFh65saZY+rRM6x6aJJI8IUa1AmH/qa0=
|
||||||
|
k8s.io/utils v0.0.0-20241210054802-24370beab758/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
|
||||||
|
20
main.go
20
main.go
@ -10,17 +10,29 @@ import (
|
|||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
|
|
||||||
"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/ambient"
|
"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/ambient"
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/ambient/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const defaultMetricPrefix = "weather"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ctx, cncl := signal.NotifyContext(context.Background(), os.Kill, unix.SIGTERM)
|
ctx, cncl := signal.NotifyContext(context.Background(), os.Kill, unix.SIGTERM)
|
||||||
defer cncl()
|
defer cncl()
|
||||||
|
|
||||||
ctx = app.MustSetupConfigAndLogging(ctx)
|
// Config type for app, which implements go-app/config.AppConfig
|
||||||
|
awConfig := &config.AmbientLocalExporterConfig{
|
||||||
|
MetricPrefix: defaultMetricPrefix,
|
||||||
|
WeatherStations: make([]config.WeatherStation, 0),
|
||||||
|
}
|
||||||
|
|
||||||
aw := ambient.New(ctx)
|
// Read config and environment, set up logging, load up
|
||||||
aw.MustInit()
|
// an appCtx, and prepare ambient weather local exporter
|
||||||
|
ctx, awConfig = app.MustLoadConfigInto(ctx, awConfig)
|
||||||
|
|
||||||
|
// Prepare the exporter
|
||||||
|
aw := ambient.New(ctx, awConfig).Init()
|
||||||
|
|
||||||
|
// Define and prepare the app
|
||||||
awApp := app.App{
|
awApp := app.App{
|
||||||
AppContext: ctx,
|
AppContext: ctx,
|
||||||
HTTP: &app.AppHTTP{
|
HTTP: &app.AppHTTP{
|
||||||
@ -43,7 +55,7 @@ func main() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run and wait
|
||||||
awApp.MustRun()
|
awApp.MustRun()
|
||||||
|
|
||||||
<-awApp.Done()
|
<-awApp.Done()
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
"go.opentelemetry.io/otel/attribute"
|
"go.opentelemetry.io/otel/attribute"
|
||||||
"go.opentelemetry.io/otel/codes"
|
"go.opentelemetry.io/otel/codes"
|
||||||
|
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/ambient/config"
|
||||||
"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/provider"
|
"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/provider"
|
||||||
"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/provider/awn"
|
"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/provider/awn"
|
||||||
"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/provider/wunderground"
|
"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/provider/wunderground"
|
||||||
@ -24,6 +25,7 @@ type AmbientWeather struct {
|
|||||||
// when either "AmbientWeather" or "Wunderground" are selected
|
// when either "AmbientWeather" or "Wunderground" are selected
|
||||||
// in the "Custom" section of the AWNet app, or the web UI
|
// in the "Custom" section of the AWNet app, or the web UI
|
||||||
// of an Ambient WeatherHub
|
// of an Ambient WeatherHub
|
||||||
|
config *config.AmbientLocalExporterConfig
|
||||||
awnProvider provider.AmbientProvider
|
awnProvider provider.AmbientProvider
|
||||||
wuProvider provider.AmbientProvider
|
wuProvider provider.AmbientProvider
|
||||||
appCtx context.Context
|
appCtx context.Context
|
||||||
@ -31,16 +33,21 @@ type AmbientWeather struct {
|
|||||||
l *zerolog.Logger
|
l *zerolog.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(appCtx context.Context) *AmbientWeather {
|
func New(appCtx context.Context, awConfig *config.AmbientLocalExporterConfig) *AmbientWeather {
|
||||||
return &AmbientWeather{
|
return &AmbientWeather{
|
||||||
|
config: awConfig,
|
||||||
appCtx: appCtx,
|
appCtx: appCtx,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (aw *AmbientWeather) MustInit() {
|
// Initialize with defaults, set logger from context
|
||||||
|
func (aw *AmbientWeather) Init() *AmbientWeather {
|
||||||
aw.awnProvider = &awn.AWNProvider{}
|
aw.awnProvider = &awn.AWNProvider{}
|
||||||
aw.wuProvider = &wunderground.WUProvider{}
|
aw.wuProvider = &wunderground.WUProvider{}
|
||||||
aw.l = zerolog.Ctx(aw.appCtx)
|
aw.l = zerolog.Ctx(aw.appCtx)
|
||||||
|
|
||||||
|
aw.l.Trace().Any("awConfig", aw.config).Send()
|
||||||
|
return aw
|
||||||
}
|
}
|
||||||
|
|
||||||
func (aw *AmbientWeather) GetAWNHandlerFunc(appCtx context.Context) func(http.ResponseWriter, *http.Request) {
|
func (aw *AmbientWeather) GetAWNHandlerFunc(appCtx context.Context) func(http.ResponseWriter, *http.Request) {
|
||||||
@ -55,7 +62,7 @@ func (aw *AmbientWeather) GetWundergroundHandlerFunc(appCtx context.Context) fun
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes an HTTP requests and convers it to a
|
// Takes an HTTP requests and converts it to a
|
||||||
// stable type. Enrich is called on the type to complete
|
// stable type. Enrich is called on the type to complete
|
||||||
// any missing fields as the two providers supported by Ambient
|
// any missing fields as the two providers supported by Ambient
|
||||||
// devices (awn/wunderground) produce different fields
|
// devices (awn/wunderground) produce different fields
|
||||||
@ -85,16 +92,22 @@ func (aw *AmbientWeather) handleProviderRequest(
|
|||||||
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
w.Write([]byte(err.Error()))
|
w.Write([]byte(err.Error()))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate any fields that may be missing
|
// Calculate any fields that may be missing
|
||||||
// such as dew point and wind chill
|
// such as dew point and wind chill
|
||||||
update.Enrich()
|
update.Enrich()
|
||||||
|
|
||||||
// Update metrics
|
// Prepare metrics if this is the first update
|
||||||
if aw.metrics == nil {
|
if aw.metrics == nil {
|
||||||
aw.metrics = weather.MustInitMetrics(aw.appCtx)
|
aw.InitMetrics()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enrich station if configured
|
||||||
|
aw.enrichStation(update)
|
||||||
|
|
||||||
|
// Update metrics
|
||||||
aw.metrics.Update(update)
|
aw.metrics.Update(update)
|
||||||
|
|
||||||
l.Debug().
|
l.Debug().
|
||||||
@ -102,4 +115,47 @@ func (aw *AmbientWeather) handleProviderRequest(
|
|||||||
Any("update", update).
|
Any("update", update).
|
||||||
Msg("successfully handled update")
|
Msg("successfully handled update")
|
||||||
w.Write([]byte("ok"))
|
w.Write([]byte("ok"))
|
||||||
|
|
||||||
|
// Proxy update to one or both services if configured to do so
|
||||||
|
// Uses a weather update to allow awn to publish to wunderground and
|
||||||
|
// visa versa.
|
||||||
|
if station := update.StationConfig; station != nil {
|
||||||
|
if station.ProxyToAWN {
|
||||||
|
err := aw.awnProvider.ProxyReq(ctx, update)
|
||||||
|
if err != nil {
|
||||||
|
zerolog.Ctx(aw.appCtx).Err(err).Msg("failed to proxy to ambient weather")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
zerolog.Ctx(aw.appCtx).Debug().
|
||||||
|
Str("station", station.Name).
|
||||||
|
Msg("proxied weather update to awn")
|
||||||
|
}
|
||||||
|
if station.ProxyToWunderground {
|
||||||
|
err := aw.wuProvider.ProxyReq(ctx, update)
|
||||||
|
if err != nil {
|
||||||
|
zerolog.Ctx(aw.appCtx).Err(err).Msg("failed to proxy to ambient weather")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
zerolog.Ctx(aw.appCtx).Debug().
|
||||||
|
Str("station", station.Name).
|
||||||
|
Msg("proxied weather update to wunderground")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (aw *AmbientWeather) InitMetrics() {
|
||||||
|
if aw.config.MetricPrefix != "" {
|
||||||
|
weather.MetricPrefix = aw.config.MetricPrefix
|
||||||
|
}
|
||||||
|
aw.metrics = weather.MustInitMetrics(aw.appCtx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (aw *AmbientWeather) enrichStation(update *weather.WeatherUpdate) {
|
||||||
|
if update != nil && update.StationID != nil && *update.StationID != "" {
|
||||||
|
for _, station := range aw.config.WeatherStations {
|
||||||
|
if *update.StationID == station.AWNPassKey || *update.StationID == station.WundergroundID {
|
||||||
|
update.StationConfig = &station
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
36
pkg/ambient/config/config.go
Normal file
36
pkg/ambient/config/config.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
// This configuration includes all config from go-app/config.AppConfig
|
||||||
|
type AmbientLocalExporterConfig struct {
|
||||||
|
MetricPrefix string `yaml:"metricPrefix" default:"weather" env:"AMBIENT_METRIC_PREFIX"`
|
||||||
|
WeatherStations []WeatherStation `yaml:"weatherStations"` // No env, too complex, not worth the time
|
||||||
|
*config.AppConfig // Extends app config
|
||||||
|
}
|
||||||
|
|
||||||
|
type WeatherStation struct {
|
||||||
|
Name string `yaml:"name"` // Human Friendly Name (e.g. Back Yard Weather)
|
||||||
|
Equipment string `yaml:"equipment"` // Equipment Type (e.g. WS-5000)
|
||||||
|
|
||||||
|
// Required if proxying to awn/wu is enabled
|
||||||
|
WundergroundID string `yaml:"wundergroundID"`
|
||||||
|
WundergroundPassword string `yaml:"wundergroundPassword"`
|
||||||
|
AWNPassKey string `yaml:"awnPassKey"`
|
||||||
|
|
||||||
|
// Proxy updates to AWN or Wunderground
|
||||||
|
ProxyToAWN bool `yaml:"proxyToAWN"`
|
||||||
|
ProxyToWunderground bool `yaml:"proxyToWunderground"`
|
||||||
|
|
||||||
|
// Unreliable / unwanted metrics by name of WeatherUpdate Field
|
||||||
|
// will be excluded if present in discardMetrics
|
||||||
|
//
|
||||||
|
// If anything is present in keepMetrics, it is solely applied,
|
||||||
|
// ignoring discardMetrics.
|
||||||
|
//
|
||||||
|
// Check weather.WeatherUpdateField for options
|
||||||
|
KeepMetrics []string `yaml:"keepMetrics"`
|
||||||
|
DropMetrics []string `yaml:"dropMetrics"`
|
||||||
|
}
|
@ -13,7 +13,18 @@ import (
|
|||||||
|
|
||||||
type AWNProvider struct{}
|
type AWNProvider struct{}
|
||||||
|
|
||||||
const providerName = "awn"
|
const (
|
||||||
|
providerName = "awn"
|
||||||
|
awnURL = "http://ambientweather.net/data/report"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Battery Sensors
|
||||||
|
const (
|
||||||
|
BattOutdoorSensor = "OutdoorSensor"
|
||||||
|
BattIndoorSensor = "IndoorSensor"
|
||||||
|
BattRainSensor = "RainSensor"
|
||||||
|
BattCO2Sensor = "CO2Sensor"
|
||||||
|
)
|
||||||
|
|
||||||
func (awn *AWNProvider) Name() string {
|
func (awn *AWNProvider) Name() string {
|
||||||
return providerName
|
return providerName
|
||||||
@ -33,37 +44,56 @@ func (awn *AWNProvider) ReqToWeather(_ context.Context, r *http.Request) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
func MapAwnUpdate(awnUpdate *AmbientWeatherUpdate) *weather.WeatherUpdate {
|
func MapAwnUpdate(awnUpdate *AmbientWeatherUpdate) *weather.WeatherUpdate {
|
||||||
updateTime, err := time.Parse(time.DateTime, awnUpdate.DateUTC)
|
updateTime := time.Now()
|
||||||
if err != nil {
|
if awnUpdate.DateUTC != nil {
|
||||||
updateTime = time.Now()
|
ut, err := time.Parse(time.DateTime, *awnUpdate.DateUTC)
|
||||||
|
if err == nil {
|
||||||
|
updateTime = ut
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &weather.WeatherUpdate{
|
return &weather.WeatherUpdate{
|
||||||
StationType: awnUpdate.StationType,
|
DateUTC: &updateTime,
|
||||||
DateUTC: &updateTime,
|
StationID: awnUpdate.PassKey,
|
||||||
TempOutdoorF: awnUpdate.TempF,
|
StationType: awnUpdate.StationType,
|
||||||
HumidityOudoor: awnUpdate.Humidity,
|
TempOutdoorF: awnUpdate.TempF,
|
||||||
WindSpeedMPH: awnUpdate.WindGustMPH,
|
HumidityOudoor: awnUpdate.Humidity,
|
||||||
WindGustMPH: awnUpdate.WindGustMPH,
|
WindSpeedMPH: awnUpdate.WindSpeedMPH,
|
||||||
MaxDailyGust: awnUpdate.MaxDailyGust,
|
WindGustMPH: awnUpdate.WindGustMPH,
|
||||||
WindDir: awnUpdate.WindDir,
|
MaxDailyGust: awnUpdate.MaxDailyGust,
|
||||||
WindDirAvg10m: awnUpdate.WindDirAVG10m,
|
WindDir: awnUpdate.WindDir,
|
||||||
UV: awnUpdate.UV,
|
WindDirAvg10m: awnUpdate.WindDirAVG10m,
|
||||||
SolarRadiation: awnUpdate.SolarRadiation,
|
UV: awnUpdate.UV,
|
||||||
HourlyRainIn: awnUpdate.HourlyRainIn,
|
SolarRadiation: awnUpdate.SolarRadiation,
|
||||||
EventRainIn: awnUpdate.EventRainIn,
|
HourlyRainIn: awnUpdate.HourlyRainIn,
|
||||||
DailyRainIn: awnUpdate.DailyRainIn,
|
EventRainIn: awnUpdate.EventRainIn,
|
||||||
WeeklyRainIn: awnUpdate.WeeklyRainIn,
|
DailyRainIn: awnUpdate.DailyRainIn,
|
||||||
MonthlyRainIn: awnUpdate.MonthlyRainIn,
|
WeeklyRainIn: awnUpdate.WeeklyRainIn,
|
||||||
YearlyRainIn: awnUpdate.YearlyRainIn,
|
MonthlyRainIn: awnUpdate.MonthlyRainIn,
|
||||||
TotalRainIn: awnUpdate.TotalRainIn,
|
YearlyRainIn: awnUpdate.YearlyRainIn,
|
||||||
BattOutdoorSensor: awnUpdate.BattOut,
|
TotalRainIn: awnUpdate.TotalRainIn,
|
||||||
BattIndoorSensor: awnUpdate.BattIn,
|
Batteries: []weather.BatteryStatus{
|
||||||
BattRainSensor: awnUpdate.BattRain,
|
{
|
||||||
TempIndoorF: awnUpdate.TempInF,
|
Component: BattOutdoorSensor,
|
||||||
HumidityIndoor: awnUpdate.HumidityIn,
|
Status: awnUpdate.BattOut,
|
||||||
BaromRelativeIn: awnUpdate.BaromRelIn,
|
},
|
||||||
BaromAbsoluteIn: awnUpdate.BaromAbsIn,
|
{
|
||||||
|
Component: BattIndoorSensor,
|
||||||
|
Status: awnUpdate.BattIn,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Component: BattRainSensor,
|
||||||
|
Status: awnUpdate.BattRain,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Component: BattCO2Sensor,
|
||||||
|
Status: awnUpdate.BattCO2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
TempIndoorF: awnUpdate.TempInF,
|
||||||
|
HumidityIndoor: awnUpdate.HumidityIn,
|
||||||
|
BaromRelativeIn: awnUpdate.BaromRelIn,
|
||||||
|
BaromAbsoluteIn: awnUpdate.BaromAbsIn,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
98
pkg/provider/awn/proxy.go
Normal file
98
pkg/provider/awn/proxy.go
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
package awn
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"net/url"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
|
||||||
|
"github.com/go-resty/resty/v2"
|
||||||
|
"go.opentelemetry.io/otel/attribute"
|
||||||
|
"go.opentelemetry.io/otel/codes"
|
||||||
|
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/weather"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Attempts to proxy the weather station update to awn
|
||||||
|
// SAMPLE:
|
||||||
|
// {"PASSKEY":["ABF7E052BC7325A32300ACC89112AA91"],"baromabsin":["28.895"],
|
||||||
|
// "baromrelin":["29.876"],"battin":["1"],"battout":["1"],"battrain":["1"],
|
||||||
|
// "dailyrainin":["0.000"],"dateutc":["2025-01-11 22:07:57"],"eventrainin":["0.000"],
|
||||||
|
// "hourlyrainin":["0.000"],"humidity":["76"],"humidityin":["31"],"maxdailygust":["7.83"],
|
||||||
|
// "monthlyrainin":["0.000"],"solarradiation":["14.21"],"stationtype":["WeatherHub_V1.0.1"],
|
||||||
|
// "tempf":["29.48"],"tempinf":["66.20"],"totalrainin":["0.000"],"uv":["0"],
|
||||||
|
// "weeklyrainin":["0.000"],"winddir":["66"],"winddir_avg10m":["268"],"windgustmph":["2.68"],
|
||||||
|
// "windspeedmph":["0.00"],"yearlyrainin":["0.000"]}
|
||||||
|
func (awn *AWNProvider) ProxyReq(ctx context.Context, update *weather.WeatherUpdate) error {
|
||||||
|
tracer := otel.GetTracer(ctx, "awnProvider", "proxyReq")
|
||||||
|
ctx, span := tracer.Start(ctx, "proxyToAWN")
|
||||||
|
defer span.End()
|
||||||
|
|
||||||
|
if update.StationConfig.AWNPassKey == "" {
|
||||||
|
err := errors.New("no PASSKEY set in update")
|
||||||
|
span.RecordError(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
params := updateToAWNParams(update)
|
||||||
|
|
||||||
|
resp, err := resty.New().R().
|
||||||
|
SetContext(ctx).
|
||||||
|
SetQueryParamsFromValues(*params).
|
||||||
|
Get(awnURL)
|
||||||
|
if err != nil {
|
||||||
|
span.RecordError(err)
|
||||||
|
span.SetStatus(codes.Error, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
span.SetAttributes(
|
||||||
|
attribute.Int("statusCode", resp.StatusCode()),
|
||||||
|
attribute.String("body", string(resp.Body())),
|
||||||
|
)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateToAWNParams(update *weather.WeatherUpdate) *url.Values {
|
||||||
|
params := &url.Values{}
|
||||||
|
params.Set("dateutc", time.Now().Format(time.DateTime))
|
||||||
|
weather.SetURLVal(params, "PASSKEY", &update.StationConfig.AWNPassKey)
|
||||||
|
weather.SetURLVal(params, "baromabsin", update.BaromAbsoluteIn)
|
||||||
|
weather.SetURLVal(params, "baromrelin", update.BaromRelativeIn)
|
||||||
|
weather.SetURLVal(params, "dailyrainin", update.DailyRainIn)
|
||||||
|
weather.SetURLVal(params, "weeklyrainin", update.WeeklyRainIn)
|
||||||
|
weather.SetURLVal(params, "eventrainin", update.EventRainIn)
|
||||||
|
weather.SetURLVal(params, "hourlyrainin", update.HourlyRainIn)
|
||||||
|
weather.SetURLVal(params, "monthlyrainin", update.MonthlyRainIn)
|
||||||
|
weather.SetURLVal(params, "yearlyrainin", update.YearlyRainIn)
|
||||||
|
weather.SetURLVal(params, "totalrainin", update.TotalRainIn)
|
||||||
|
weather.SetURLVal(params, "humidity", update.HumidityOudoor)
|
||||||
|
weather.SetURLVal(params, "humidityin", update.HumidityIndoor)
|
||||||
|
weather.SetURLVal(params, "solarradiation", update.SolarRadiation)
|
||||||
|
weather.SetURLVal(params, "uv", update.UV)
|
||||||
|
weather.SetURLVal(params, "stationtype", update.StationType)
|
||||||
|
weather.SetURLVal(params, "tempf", update.TempOutdoorF)
|
||||||
|
weather.SetURLVal(params, "tempinf", update.TempIndoorF)
|
||||||
|
weather.SetURLVal(params, "winddir", update.WindDir)
|
||||||
|
weather.SetURLVal(params, "winddir_avg10m", update.WindDirAvg10m)
|
||||||
|
weather.SetURLVal(params, "windgustmph", update.WindGustMPH)
|
||||||
|
weather.SetURLVal(params, "windspeedmph", update.WindSpeedMPH)
|
||||||
|
weather.SetURLVal(params, "maxdailygust", update.MaxDailyGust)
|
||||||
|
|
||||||
|
// Batteries
|
||||||
|
for _, status := range update.Batteries {
|
||||||
|
switch status.Component {
|
||||||
|
case BattOutdoorSensor:
|
||||||
|
weather.SetURLVal(params, "battin", status.Status)
|
||||||
|
case BattIndoorSensor:
|
||||||
|
weather.SetURLVal(params, "battout", status.Status)
|
||||||
|
case BattRainSensor:
|
||||||
|
weather.SetURLVal(params, "battrain", status.Status)
|
||||||
|
case BattCO2Sensor:
|
||||||
|
weather.SetURLVal(params, "batt_co2", status.Status)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return params
|
||||||
|
}
|
@ -1,30 +1,31 @@
|
|||||||
package awn
|
package awn
|
||||||
|
|
||||||
type AmbientWeatherUpdate struct {
|
type AmbientWeatherUpdate struct {
|
||||||
PassKey string `json:"PASSKEY,omitempty" schema:"PASSKEY"`
|
PassKey *string `json:"PASSKEY,omitempty" schema:"PASSKEY"`
|
||||||
StationType string `json:"stationtype,omitempty" schema:"stationtype"`
|
StationType *string `json:"stationtype,omitempty" schema:"stationtype"`
|
||||||
DateUTC string `json:"dateutc,omitempty" schema:"dateutc"`
|
DateUTC *string `json:"dateutc,omitempty" schema:"dateutc"`
|
||||||
TempF float64 `json:"tempf,omitempty" schema:"tempf"`
|
TempF *float64 `json:"tempf,omitempty" schema:"tempf"`
|
||||||
Humidity int `json:"humidity,omitempty" schema:"humidity"`
|
Humidity *int `json:"humidity,omitempty" schema:"humidity"`
|
||||||
WindSpeedMPH float64 `json:"windspeedmph,omitempty" schema:"windspeedmph"`
|
WindSpeedMPH *float64 `json:"windspeedmph,omitempty" schema:"windspeedmph"`
|
||||||
WindGustMPH float64 `json:"windgustmph,omitempty" schema:"windgustmph"`
|
WindGustMPH *float64 `json:"windgustmph,omitempty" schema:"windgustmph"`
|
||||||
MaxDailyGust float64 `json:"maxdailygust,omitempty" schema:"maxdailygust"`
|
MaxDailyGust *float64 `json:"maxdailygust,omitempty" schema:"maxdailygust"`
|
||||||
WindDir int `json:"winddir,omitempty" schema:"winddir"`
|
WindDir *int `json:"winddir,omitempty" schema:"winddir"`
|
||||||
WindDirAVG10m int `json:"winddir_avg10m,omitempty" schema:"winddir_avg10m"`
|
WindDirAVG10m *int `json:"winddir_avg10m,omitempty" schema:"winddir_avg10m"`
|
||||||
UV int `json:"uv,omitempty" schema:"uv"`
|
UV *int `json:"uv,omitempty" schema:"uv"`
|
||||||
SolarRadiation float64 `json:"solarradiation,omitempty" schema:"solarradiation"`
|
SolarRadiation *float64 `json:"solarradiation,omitempty" schema:"solarradiation"`
|
||||||
HourlyRainIn float64 `json:"hourlyrainin,omitempty" schema:"hourlyrainin"`
|
HourlyRainIn *float64 `json:"hourlyrainin,omitempty" schema:"hourlyrainin"`
|
||||||
EventRainIn float64 `json:"eventrainin,omitempty" schema:"eventrainin"`
|
EventRainIn *float64 `json:"eventrainin,omitempty" schema:"eventrainin"`
|
||||||
DailyRainIn float64 `json:"dailyrainin,omitempty" schema:"dailyrainin"`
|
DailyRainIn *float64 `json:"dailyrainin,omitempty" schema:"dailyrainin"`
|
||||||
WeeklyRainIn float64 `json:"weeklyrainin,omitempty" schema:"weeklyrainin"`
|
WeeklyRainIn *float64 `json:"weeklyrainin,omitempty" schema:"weeklyrainin"`
|
||||||
MonthlyRainIn float64 `json:"monthlyrainin,omitempty" schema:"monthlyrainin"`
|
MonthlyRainIn *float64 `json:"monthlyrainin,omitempty" schema:"monthlyrainin"`
|
||||||
YearlyRainIn float64 `json:"yearlyrainin,omitempty" schema:"yearlyrainin"`
|
YearlyRainIn *float64 `json:"yearlyrainin,omitempty" schema:"yearlyrainin"`
|
||||||
TotalRainIn float64 `json:"totalrainin,omitempty" schema:"totalrainin"`
|
TotalRainIn *float64 `json:"totalrainin,omitempty" schema:"totalrainin"`
|
||||||
BattOut int `json:"battout,omitempty" schema:"battout"`
|
BattOut *int `json:"battout,omitempty" schema:"battout"`
|
||||||
BattRain int `json:"battrain,omitempty" schema:"battrain"`
|
BattRain *int `json:"battrain,omitempty" schema:"battrain"`
|
||||||
TempInF float64 `json:"tempinf,omitempty" schema:"tempinf"`
|
TempInF *float64 `json:"tempinf,omitempty" schema:"tempinf"`
|
||||||
HumidityIn int `json:"humidityin,omitempty" schema:"humidityin"`
|
HumidityIn *int `json:"humidityin,omitempty" schema:"humidityin"`
|
||||||
BaromRelIn float64 `json:"baromrelin,omitempty" schema:"baromrelin"`
|
BaromRelIn *float64 `json:"baromrelin,omitempty" schema:"baromrelin"`
|
||||||
BaromAbsIn float64 `json:"baromabsin,omitempty" schema:"baromabsin"`
|
BaromAbsIn *float64 `json:"baromabsin,omitempty" schema:"baromabsin"`
|
||||||
BattIn int `json:"battin,omitempty" schema:"battin"`
|
BattIn *int `json:"battin,omitempty" schema:"battin"`
|
||||||
|
BattCO2 *int `json:"batt_co2,omitempty" schema:"batt_co2"`
|
||||||
}
|
}
|
||||||
|
@ -11,5 +11,6 @@ import (
|
|||||||
// Ambient Weather Network HTTP requests to a stable struct
|
// Ambient Weather Network HTTP requests to a stable struct
|
||||||
type AmbientProvider interface {
|
type AmbientProvider interface {
|
||||||
ReqToWeather(context.Context, *http.Request) (*weather.WeatherUpdate, error)
|
ReqToWeather(context.Context, *http.Request) (*weather.WeatherUpdate, error)
|
||||||
|
ProxyReq(context.Context, *weather.WeatherUpdate) error
|
||||||
Name() string
|
Name() string
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,10 @@ import (
|
|||||||
|
|
||||||
type WUProvider struct{}
|
type WUProvider struct{}
|
||||||
|
|
||||||
const providerName = "weatherunderground"
|
const (
|
||||||
|
providerName = "weatherunderground"
|
||||||
|
wuURL = "https://rtupdate.wunderground.com/weatherstation/updateweatherstation.php"
|
||||||
|
)
|
||||||
|
|
||||||
func (wu *WUProvider) Name() string {
|
func (wu *WUProvider) Name() string {
|
||||||
return providerName
|
return providerName
|
||||||
@ -33,16 +36,21 @@ func (wu *WUProvider) ReqToWeather(_ context.Context, r *http.Request) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
func MapWUUpdate(wuUpdate *WundergroundUpdate) *weather.WeatherUpdate {
|
func MapWUUpdate(wuUpdate *WundergroundUpdate) *weather.WeatherUpdate {
|
||||||
updateTime, err := time.Parse(time.DateTime, wuUpdate.DateUTC)
|
updateTime := time.Now()
|
||||||
if err != nil {
|
|
||||||
updateTime = time.Now()
|
if wuUpdate.DateUTC != nil {
|
||||||
|
ut, err := time.Parse(time.DateTime, *wuUpdate.DateUTC)
|
||||||
|
if err == nil {
|
||||||
|
updateTime = ut
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &weather.WeatherUpdate{
|
return &weather.WeatherUpdate{
|
||||||
StationType: wuUpdate.SoftwareType,
|
|
||||||
DateUTC: &updateTime,
|
DateUTC: &updateTime,
|
||||||
TempOutdoorF: wuUpdate.Tempf,
|
StationID: wuUpdate.ID,
|
||||||
HumidityOudoor: wuUpdate.Humidity,
|
StationType: wuUpdate.SoftwareType,
|
||||||
|
TempOutdoorF: wuUpdate.Tempf,
|
||||||
|
HumidityOudoor: wuUpdate.Humidity,
|
||||||
WindSpeedMPH: wuUpdate.WindGustMPH,
|
WindSpeedMPH: wuUpdate.WindGustMPH,
|
||||||
WindGustMPH: wuUpdate.WindGustMPH,
|
WindGustMPH: wuUpdate.WindGustMPH,
|
||||||
WindDir: wuUpdate.WindDir,
|
WindDir: wuUpdate.WindDir,
|
||||||
|
83
pkg/provider/wunderground/proxy.go
Normal file
83
pkg/provider/wunderground/proxy.go
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
package wunderground
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"net/url"
|
||||||
|
|
||||||
|
"github.com/go-resty/resty/v2"
|
||||||
|
"go.opentelemetry.io/otel/attribute"
|
||||||
|
"go.opentelemetry.io/otel/codes"
|
||||||
|
"k8s.io/utils/ptr"
|
||||||
|
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
|
||||||
|
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/weather"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (wu *WUProvider) ProxyReq(ctx context.Context, update *weather.WeatherUpdate) error {
|
||||||
|
tracer := otel.GetTracer(ctx, "wuProvider", "proxyReq")
|
||||||
|
ctx, span := tracer.Start(ctx, "proxyToWunderground")
|
||||||
|
defer span.End()
|
||||||
|
|
||||||
|
if update.StationConfig.WundergroundID == "" {
|
||||||
|
err := errors.New("no wunderground id set in update")
|
||||||
|
span.RecordError(err)
|
||||||
|
return err
|
||||||
|
} else if update.StationConfig.WundergroundPassword == "" {
|
||||||
|
err := errors.New("no wunderground id set in update")
|
||||||
|
span.RecordError(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
params := updateToWuParams(update)
|
||||||
|
|
||||||
|
resp, err := resty.New().R().
|
||||||
|
SetContext(ctx).
|
||||||
|
SetQueryParamsFromValues(*params).
|
||||||
|
Get(wuURL)
|
||||||
|
if err != nil {
|
||||||
|
span.SetStatus(codes.Error, err.Error())
|
||||||
|
span.SetAttributes(
|
||||||
|
attribute.String("query", resp.Request.QueryParam.Encode()),
|
||||||
|
)
|
||||||
|
span.RecordError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
span.SetAttributes(
|
||||||
|
attribute.Int("statusCode", resp.StatusCode()),
|
||||||
|
attribute.String("body", string(resp.Body())),
|
||||||
|
)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateToWuParams(u *weather.WeatherUpdate) *url.Values {
|
||||||
|
params := &url.Values{}
|
||||||
|
weather.SetURLVal(params, "ID", &u.StationConfig.WundergroundID)
|
||||||
|
weather.SetURLVal(params, "PASSWORD", &u.StationConfig.WundergroundPassword)
|
||||||
|
params.Set("action", "updateraw")
|
||||||
|
params.Set("dateutc", "now")
|
||||||
|
weather.SetURLVal(params, "UV", u.UV)
|
||||||
|
weather.SetURLVal(params, "baromin", u.BaromRelativeIn)
|
||||||
|
weather.SetURLVal(params, "dailyrainin", u.DailyRainIn)
|
||||||
|
weather.SetURLVal(params, "dewptf", u.DewPointF)
|
||||||
|
weather.SetURLVal(params, "humidity", u.HumidityOudoor)
|
||||||
|
weather.SetURLVal(params, "indoorhumidity", u.HumidityIndoor)
|
||||||
|
weather.SetURLVal(params, "indoortempf", u.TempIndoorF)
|
||||||
|
weather.SetURLVal(params, "lowbatt", ptr.To(0))
|
||||||
|
weather.SetURLVal(params, "monthlyrainin", u.MonthlyRainIn)
|
||||||
|
weather.SetURLVal(params, "rainin", u.HourlyRainIn)
|
||||||
|
weather.SetURLVal(params, "realtime", ptr.To(1))
|
||||||
|
weather.SetURLVal(params, "rtfreq", ptr.To(60))
|
||||||
|
weather.SetURLVal(params, "softwaretype", u.StationType)
|
||||||
|
weather.SetURLVal(params, "solarradiation", u.SolarRadiation)
|
||||||
|
weather.SetURLVal(params, "tempf", u.TempOutdoorF)
|
||||||
|
weather.SetURLVal(params, "weeklyrainin", u.WeeklyRainIn)
|
||||||
|
weather.SetURLVal(params, "windchillf", u.WindChillF)
|
||||||
|
weather.SetURLVal(params, "winddir", u.WindDir)
|
||||||
|
weather.SetURLVal(params, "windgustmph", u.WindGustMPH)
|
||||||
|
weather.SetURLVal(params, "windspeedmph", u.WindSpeedMPH)
|
||||||
|
weather.SetURLVal(params, "yearlyrainin", u.YearlyRainIn)
|
||||||
|
return params
|
||||||
|
}
|
@ -1,29 +1,29 @@
|
|||||||
package wunderground
|
package wunderground
|
||||||
|
|
||||||
type WundergroundUpdate struct {
|
type WundergroundUpdate struct {
|
||||||
ID string `json:"ID,omitempty" schema:"ID"`
|
ID *string `json:"ID,omitempty" schema:"ID"`
|
||||||
Password string `json:"PASSWORD,omitempty" schema:"PASSWORD"`
|
Password *string `json:"PASSWORD,omitempty" schema:"PASSWORD"`
|
||||||
UV int `json:"UV,omitempty" schema:"UV"`
|
UV *int `json:"UV,omitempty" schema:"UV"`
|
||||||
Action string `json:"action,omitempty" schema:"action"`
|
Action *string `json:"action,omitempty" schema:"action"`
|
||||||
BaromIn float64 `json:"baromin,omitempty" schema:"baromin"`
|
BaromIn *float64 `json:"baromin,omitempty" schema:"baromin"`
|
||||||
DailyRainIn float64 `json:"dailyrainin,omitempty" schema:"dailyrainin"`
|
DailyRainIn *float64 `json:"dailyrainin,omitempty" schema:"dailyrainin"`
|
||||||
DateUTC string `json:"dateutc,omitempty" schema:"dateutc"`
|
DateUTC *string `json:"dateutc,omitempty" schema:"dateutc"`
|
||||||
DewPtF float64 `json:"dewptf,omitempty" schema:"dewptf"`
|
DewPtF *float64 `json:"dewptf,omitempty" schema:"dewptf"`
|
||||||
Humidity int `json:"humidity,omitempty" schema:"humidity"`
|
Humidity *int `json:"humidity,omitempty" schema:"humidity"`
|
||||||
IndoorHumidity int `json:"indoorhumidity,omitempty" schema:"indoorhumidity"`
|
IndoorHumidity *int `json:"indoorhumidity,omitempty" schema:"indoorhumidity"`
|
||||||
IndoorTempF float64 `json:"indoortempf,omitempty" schema:"indoortempf"`
|
IndoorTempF *float64 `json:"indoortempf,omitempty" schema:"indoortempf"`
|
||||||
LowBatt bool `json:"lowbatt,omitempty" schema:"lowbatt"`
|
LowBatt *bool `json:"lowbatt,omitempty" schema:"lowbatt"`
|
||||||
MonthlyRainIn float64 `json:"monthlyrainin,omitempty" schema:"monthlyrainin"`
|
MonthlyRainIn *float64 `json:"monthlyrainin,omitempty" schema:"monthlyrainin"`
|
||||||
RainIn float64 `json:"rainin,omitempty" schema:"rainin"`
|
RainIn *float64 `json:"rainin,omitempty" schema:"rainin"`
|
||||||
Realtime bool `json:"realtime,omitempty" schema:"realtime"`
|
Realtime *bool `json:"realtime,omitempty" schema:"realtime"`
|
||||||
Rtfreq int `json:"rtfreq,omitempty" schema:"rtfreq"`
|
Rtfreq *int `json:"rtfreq,omitempty" schema:"rtfreq"`
|
||||||
SoftwareType string `json:"softwaretype,omitempty" schema:"softwaretype"`
|
SoftwareType *string `json:"softwaretype,omitempty" schema:"softwaretype"`
|
||||||
SolarRadiation float64 `json:"solarradiation,omitempty" schema:"solarradiation"`
|
SolarRadiation *float64 `json:"solarradiation,omitempty" schema:"solarradiation"`
|
||||||
Tempf float64 `json:"tempf,omitempty" schema:"tempf"`
|
Tempf *float64 `json:"tempf,omitempty" schema:"tempf"`
|
||||||
WeeklyRainIn float64 `json:"weeklyrainin,omitempty" schema:"weeklyrainin"`
|
WeeklyRainIn *float64 `json:"weeklyrainin,omitempty" schema:"weeklyrainin"`
|
||||||
WindChillF float64 `json:"windchillf,omitempty" schema:"windchillf"`
|
WindChillF *float64 `json:"windchillf,omitempty" schema:"windchillf"`
|
||||||
WindDir int `json:"winddir,omitempty" schema:"winddir"`
|
WindDir *int `json:"winddir,omitempty" schema:"winddir"`
|
||||||
WindGustMPH float64 `json:"windgustmph,omitempty" schema:"windgustmph"`
|
WindGustMPH *float64 `json:"windgustmph,omitempty" schema:"windgustmph"`
|
||||||
WindSpeedMPH float64 `json:"windspeedmph,omitempty" schema:"windspeedmph"`
|
WindSpeedMPH *float64 `json:"windspeedmph,omitempty" schema:"windspeedmph"`
|
||||||
YearlyRainIn float64 `json:"yearlyrainin,omitempty" schema:"yearlyrainin"`
|
YearlyRainIn *float64 `json:"yearlyrainin,omitempty" schema:"yearlyrainin"`
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,33 @@
|
|||||||
package weather
|
package weather
|
||||||
|
|
||||||
import "math"
|
import (
|
||||||
|
"math"
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/ambient/config"
|
||||||
|
)
|
||||||
|
|
||||||
// Attempts to complete missing fields that may not
|
// Attempts to complete missing fields that may not
|
||||||
// be set by a specific provider, such as DewPoint and WindChill
|
// be set by a specific provider, such as DewPoint and WindChill
|
||||||
func (u *WeatherUpdate) Enrich() {
|
func (u *WeatherUpdate) Enrich(weatherStations ...*config.WeatherStation) {
|
||||||
if u.WindChillF == 0 {
|
if u == nil {
|
||||||
u.WindChillF = CalculateWindChill(u.TempOutdoorF, u.WindSpeedMPH)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if u.DewPointF == 0 {
|
if u.WindChillF == nil && u.TempOutdoorF != nil && u.WindSpeedMPH != nil {
|
||||||
u.DewPointF = CalculateDewPoint(u.TempOutdoorF, float64(u.HumidityOudoor))
|
wc := CalculateWindChill(*u.TempOutdoorF, *u.WindSpeedMPH)
|
||||||
|
u.WindChillF = &wc
|
||||||
}
|
}
|
||||||
|
|
||||||
if u.BaromAbsoluteIn == 0 {
|
if u.DewPointF == nil && (u.TempOutdoorF != nil && u.HumidityOudoor != nil) {
|
||||||
|
if *u.TempOutdoorF != 0 || *u.HumidityOudoor != 0 {
|
||||||
|
dp := CalculateDewPoint(*u.TempOutdoorF, float64(*u.HumidityOudoor))
|
||||||
|
u.DewPointF = &dp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if u.BaromAbsoluteIn == nil && u.BaromRelativeIn != nil {
|
||||||
u.BaromAbsoluteIn = u.BaromRelativeIn
|
u.BaromAbsoluteIn = u.BaromRelativeIn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -45,3 +59,31 @@ func CalculateWindChill(tempF float64, windSpeedMPH float64) float64 {
|
|||||||
35.75*math.Pow(windSpeedMPH, 0.16) +
|
35.75*math.Pow(windSpeedMPH, 0.16) +
|
||||||
0.4275*tempF*math.Pow(windSpeedMPH, 0.16)
|
0.4275*tempF*math.Pow(windSpeedMPH, 0.16)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper function to set values from fields
|
||||||
|
// typically from a WeatherUpdate
|
||||||
|
func SetURLVal(vals *url.Values, key string, value any) {
|
||||||
|
if value == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch v := value.(type) {
|
||||||
|
case *float64:
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
str := strconv.FormatFloat(*v, 'f', 4, 64)
|
||||||
|
vals.Set(key, str)
|
||||||
|
case *int:
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
str := strconv.FormatInt(int64(*v), 10)
|
||||||
|
vals.Set(key, str)
|
||||||
|
case *string:
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
vals.Set(key, *v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/config"
|
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/config"
|
||||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
|
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
|
||||||
|
"github.com/rs/zerolog"
|
||||||
"go.opentelemetry.io/otel/attribute"
|
"go.opentelemetry.io/otel/attribute"
|
||||||
"go.opentelemetry.io/otel/metric"
|
"go.opentelemetry.io/otel/metric"
|
||||||
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
|
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
|
||||||
@ -12,137 +13,153 @@ import (
|
|||||||
|
|
||||||
type WeatherMetrics struct {
|
type WeatherMetrics struct {
|
||||||
// Weather Metrics
|
// Weather Metrics
|
||||||
TempOutdoorF metric.Float64Gauge
|
TempOutdoorF metric.Float64Gauge
|
||||||
TempIndoorF metric.Float64Gauge
|
TempIndoorF metric.Float64Gauge
|
||||||
HumidityOudoor metric.Int64Gauge
|
HumidityOudoor metric.Int64Gauge
|
||||||
HumidityIndoor metric.Int64Gauge
|
HumidityIndoor metric.Int64Gauge
|
||||||
WindSpeedMPH metric.Float64Gauge
|
WindSpeedMPH metric.Float64Gauge
|
||||||
WindGustMPH metric.Float64Gauge
|
WindGustMPH metric.Float64Gauge
|
||||||
MaxDailyGust metric.Float64Gauge
|
MaxDailyGust metric.Float64Gauge
|
||||||
WindDir metric.Int64Gauge
|
WindDir metric.Int64Gauge
|
||||||
WindDirAvg10m metric.Int64Gauge
|
WindDirAvg10m metric.Int64Gauge
|
||||||
UV metric.Int64Gauge
|
UV metric.Int64Gauge
|
||||||
SolarRadiation metric.Float64Gauge
|
SolarRadiation metric.Float64Gauge
|
||||||
HourlyRainIn metric.Float64Gauge
|
HourlyRainIn metric.Float64Gauge
|
||||||
EventRainIn metric.Float64Gauge
|
EventRainIn metric.Float64Gauge
|
||||||
DailyRainIn metric.Float64Gauge
|
DailyRainIn metric.Float64Gauge
|
||||||
WeeklyRainIn metric.Float64Gauge
|
WeeklyRainIn metric.Float64Gauge
|
||||||
MonthlyRainIn metric.Float64Gauge
|
MonthlyRainIn metric.Float64Gauge
|
||||||
YearlyRainIn metric.Float64Gauge
|
YearlyRainIn metric.Float64Gauge
|
||||||
TotalRainIn metric.Float64Gauge
|
TotalRainIn metric.Float64Gauge
|
||||||
BattOutdoorSensor metric.Int64Gauge
|
BatteryStatus metric.Int64Gauge
|
||||||
BattIndoorSensor metric.Int64Gauge
|
BaromRelativeIn metric.Float64Gauge
|
||||||
BattRainSensor metric.Int64Gauge
|
BaromAbsoluteIn metric.Float64Gauge
|
||||||
BaromRelativeIn metric.Float64Gauge
|
DewPointF metric.Float64Gauge
|
||||||
BaromAbsoluteIn metric.Float64Gauge
|
WindChillF metric.Float64Gauge
|
||||||
DewPointF metric.Float64Gauge
|
|
||||||
WindChillF metric.Float64Gauge
|
|
||||||
|
|
||||||
// Internal Telemetry
|
// Internal Telemetry
|
||||||
UpdatesReceived metric.Int64Counter
|
UpdatesReceived metric.Int64Counter
|
||||||
appCtx context.Context
|
appCtx context.Context
|
||||||
cfg *config.AppConfig
|
cfg *config.AppConfig
|
||||||
meter metric.Meter
|
meter metric.Meter
|
||||||
|
recorder *MetricRecorder
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var MetricPrefix = "weather"
|
||||||
|
|
||||||
func MustInitMetrics(appCtx context.Context) *WeatherMetrics {
|
func MustInitMetrics(appCtx context.Context) *WeatherMetrics {
|
||||||
wm := &WeatherMetrics{
|
wm := &WeatherMetrics{
|
||||||
appCtx: appCtx,
|
appCtx: appCtx,
|
||||||
cfg: config.MustFromCtx(appCtx),
|
cfg: config.MustFromCtx(appCtx),
|
||||||
|
recorder: &MetricRecorder{ctx: appCtx, l: zerolog.Ctx(appCtx)},
|
||||||
}
|
}
|
||||||
|
|
||||||
wm.meter = otel.GetMeter(appCtx, "weather", "metrics")
|
wm.meter = otel.GetMeter(appCtx, "weather", "metrics")
|
||||||
|
|
||||||
// Weather Metrics
|
// Weather Metrics
|
||||||
wm.TempOutdoorF, _ = wm.meter.Float64Gauge("weather_temp_outdoor_f",
|
wm.TempOutdoorF, _ = wm.meter.Float64Gauge(MetricPrefix+"_temp_outdoor_f",
|
||||||
metric.WithDescription("Outdoor Temperature in Faherenheit"))
|
metric.WithDescription("Outdoor Temperature in Faherenheit"))
|
||||||
wm.TempIndoorF, _ = wm.meter.Float64Gauge("weather_temp_indoor_f",
|
wm.TempIndoorF, _ = wm.meter.Float64Gauge(MetricPrefix+"_temp_indoor_f",
|
||||||
metric.WithDescription("Indoor Temperature in Faherenheit"))
|
metric.WithDescription("Indoor Temperature in Faherenheit"))
|
||||||
wm.HumidityOudoor, _ = wm.meter.Int64Gauge("weather_humidity_oudoor",
|
wm.HumidityOudoor, _ = wm.meter.Int64Gauge(MetricPrefix+"_humidity_outdoor",
|
||||||
metric.WithDescription("Outdoor Humidity %"))
|
metric.WithDescription("Outdoor Humidity %"))
|
||||||
wm.HumidityIndoor, _ = wm.meter.Int64Gauge("weather_humidity_indoor",
|
wm.HumidityIndoor, _ = wm.meter.Int64Gauge(MetricPrefix+"_humidity_indoor",
|
||||||
metric.WithDescription("Indoor Humidity %"))
|
metric.WithDescription("Indoor Humidity %"))
|
||||||
wm.WindSpeedMPH, _ = wm.meter.Float64Gauge("weather_wind_speed_mph",
|
wm.WindSpeedMPH, _ = wm.meter.Float64Gauge(MetricPrefix+"_wind_speed_mph",
|
||||||
metric.WithDescription("Wind Speed in MPH"))
|
metric.WithDescription("Wind Speed in MPH"))
|
||||||
wm.WindGustMPH, _ = wm.meter.Float64Gauge("weather_wind_gust_mph",
|
wm.WindGustMPH, _ = wm.meter.Float64Gauge(MetricPrefix+"_wind_gust_mph",
|
||||||
metric.WithDescription("Wind Gust in MPH"))
|
metric.WithDescription("Wind Gust in MPH"))
|
||||||
wm.MaxDailyGust, _ = wm.meter.Float64Gauge("weather_max_daily_gust",
|
wm.MaxDailyGust, _ = wm.meter.Float64Gauge(MetricPrefix+"_max_daily_gust",
|
||||||
metric.WithDescription("Max Daily Wind Gust"))
|
metric.WithDescription("Max Daily Wind Gust"))
|
||||||
wm.WindDir, _ = wm.meter.Int64Gauge("weather_wind_dir",
|
wm.WindDir, _ = wm.meter.Int64Gauge(MetricPrefix+"_wind_dir",
|
||||||
metric.WithDescription("Wind Direction in Degrees"))
|
metric.WithDescription("Wind Direction in Degrees"))
|
||||||
wm.WindDirAvg10m, _ = wm.meter.Int64Gauge("weather_wind_dir_avg_10m",
|
wm.WindDirAvg10m, _ = wm.meter.Int64Gauge(MetricPrefix+"_wind_dir_avg_10m",
|
||||||
metric.WithDescription("Wind Direction 10m Average"))
|
metric.WithDescription("Wind Direction 10m Average"))
|
||||||
wm.UV, _ = wm.meter.Int64Gauge("weather_uv",
|
wm.UV, _ = wm.meter.Int64Gauge(MetricPrefix+"_uv",
|
||||||
metric.WithDescription("UV Index"))
|
metric.WithDescription("UV Index"))
|
||||||
wm.SolarRadiation, _ = wm.meter.Float64Gauge("weather_solar_radiation",
|
wm.SolarRadiation, _ = wm.meter.Float64Gauge(MetricPrefix+"_solar_radiation",
|
||||||
metric.WithDescription("Solar Radiation in W/㎡"))
|
metric.WithDescription("Solar Radiation in W/㎡"))
|
||||||
wm.HourlyRainIn, _ = wm.meter.Float64Gauge("weather_hourly_rain_in",
|
wm.HourlyRainIn, _ = wm.meter.Float64Gauge(MetricPrefix+"_hourly_rain_in",
|
||||||
metric.WithDescription("Hourly Rain in Inches"))
|
metric.WithDescription("Hourly Rain in Inches"))
|
||||||
wm.EventRainIn, _ = wm.meter.Float64Gauge("weather_event_rain_in",
|
wm.EventRainIn, _ = wm.meter.Float64Gauge(MetricPrefix+"_event_rain_in",
|
||||||
metric.WithDescription("Event Rain in Inches"))
|
metric.WithDescription("Event Rain in Inches"))
|
||||||
wm.DailyRainIn, _ = wm.meter.Float64Gauge("weather_daily_rain_in",
|
wm.DailyRainIn, _ = wm.meter.Float64Gauge(MetricPrefix+"_daily_rain_in",
|
||||||
metric.WithDescription("Daily Rain in Inches"))
|
metric.WithDescription("Daily Rain in Inches"))
|
||||||
wm.WeeklyRainIn, _ = wm.meter.Float64Gauge("weather_weekly_rain_in",
|
wm.WeeklyRainIn, _ = wm.meter.Float64Gauge(MetricPrefix+"_weekly_rain_in",
|
||||||
metric.WithDescription("Weekly Rain in Inches"))
|
metric.WithDescription("Weekly Rain in Inches"))
|
||||||
wm.MonthlyRainIn, _ = wm.meter.Float64Gauge("weather_monthly_rain_in",
|
wm.MonthlyRainIn, _ = wm.meter.Float64Gauge(MetricPrefix+"_monthly_rain_in",
|
||||||
metric.WithDescription("Monthly Rain in Inches"))
|
metric.WithDescription("Monthly Rain in Inches"))
|
||||||
wm.YearlyRainIn, _ = wm.meter.Float64Gauge("weather_yearly_rain_in",
|
wm.YearlyRainIn, _ = wm.meter.Float64Gauge(MetricPrefix+"_yearly_rain_in",
|
||||||
metric.WithDescription("Yearly Rain in Inches"))
|
metric.WithDescription("Yearly Rain in Inches"))
|
||||||
wm.TotalRainIn, _ = wm.meter.Float64Gauge("weather_total_rain_in",
|
wm.TotalRainIn, _ = wm.meter.Float64Gauge(MetricPrefix+"_total_rain_in",
|
||||||
metric.WithDescription("Total Rain in Inches"))
|
metric.WithDescription("Total Rain in Inches"))
|
||||||
wm.BattOutdoorSensor, _ = wm.meter.Int64Gauge("weather_batt_outdoor_sensor",
|
wm.BatteryStatus, _ = wm.meter.Int64Gauge(MetricPrefix+"_battery_status",
|
||||||
metric.WithDescription("Outdoor Equipment Battery"))
|
metric.WithDescription("Per-component battery status"))
|
||||||
wm.BattIndoorSensor, _ = wm.meter.Int64Gauge("weather_batt_indoor_sensor",
|
wm.BaromRelativeIn, _ = wm.meter.Float64Gauge(MetricPrefix+"_barometric_pressure_relative_in",
|
||||||
metric.WithDescription("Indoor Equipmenet Battery"))
|
|
||||||
wm.BattRainSensor, _ = wm.meter.Int64Gauge("weather_batt_rain_sensor",
|
|
||||||
metric.WithDescription("Rain Sensor Battery"))
|
|
||||||
wm.BaromRelativeIn, _ = wm.meter.Float64Gauge("weather_barometric_pressure_relative_in",
|
|
||||||
metric.WithDescription("Relative Pressure in Inches of Mercury"))
|
metric.WithDescription("Relative Pressure in Inches of Mercury"))
|
||||||
wm.BaromAbsoluteIn, _ = wm.meter.Float64Gauge("weather_barometric_pressure_absolute_in",
|
wm.BaromAbsoluteIn, _ = wm.meter.Float64Gauge(MetricPrefix+"_barometric_pressure_absolute_in",
|
||||||
metric.WithDescription("Absolute Pressure in Inches of Mercury"))
|
metric.WithDescription("Absolute Pressure in Inches of Mercury"))
|
||||||
wm.DewPointF, _ = wm.meter.Float64Gauge("weather_dew_point_f",
|
wm.DewPointF, _ = wm.meter.Float64Gauge(MetricPrefix+"_dew_point_f",
|
||||||
metric.WithDescription("Dew Point in Faherenheit"))
|
metric.WithDescription("Dew Point in Faherenheit"))
|
||||||
wm.WindChillF, _ = wm.meter.Float64Gauge("weather_wind_chill_f",
|
wm.WindChillF, _ = wm.meter.Float64Gauge(MetricPrefix+"_wind_chill_f",
|
||||||
metric.WithDescription("Wind Chill in Faherenheit"))
|
metric.WithDescription("Wind Chill in Faherenheit"))
|
||||||
|
|
||||||
// Internal Telemetry
|
// Internal Telemetry
|
||||||
wm.UpdatesReceived, _ = wm.meter.Int64Counter("weather_updates_received",
|
wm.UpdatesReceived, _ = wm.meter.Int64Counter(MetricPrefix+"_updates_received",
|
||||||
metric.WithDescription("Metric Updates Processed by Exporter"))
|
metric.WithDescription("Metric Updates Processed by Exporter"))
|
||||||
|
|
||||||
return wm
|
return wm
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wm *WeatherMetrics) Update(u *WeatherUpdate) {
|
func (wm *WeatherMetrics) Update(u *WeatherUpdate) {
|
||||||
attributes := attribute.NewSet(
|
attributes := []attribute.KeyValue{
|
||||||
semconv.ServiceVersion(wm.cfg.Version),
|
semconv.ServiceVersion(wm.cfg.Version),
|
||||||
attribute.String("station_type", u.StationType),
|
}
|
||||||
)
|
if u.StationType != nil {
|
||||||
|
attributes = append(attributes,
|
||||||
|
attribute.String("station_type", *u.StationType))
|
||||||
|
}
|
||||||
|
if u.StationConfig != nil {
|
||||||
|
if u.StationConfig.Name != "" {
|
||||||
|
attributes = append(attributes,
|
||||||
|
attribute.String("station_name", u.StationConfig.Name))
|
||||||
|
}
|
||||||
|
if u.StationConfig.Equipment != "" {
|
||||||
|
attributes = append(attributes,
|
||||||
|
attribute.String("station_equipment", u.StationConfig.Equipment))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
wm.TempOutdoorF.Record(wm.appCtx, u.TempOutdoorF, metric.WithAttributeSet(attributes))
|
wm.recorder.Record(&RecordOpts{Float64Gauge: wm.TempOutdoorF, FloatVal: u.TempOutdoorF, Field: FieldTempOutdoorF, Attributes: attributes, Station: u.StationConfig})
|
||||||
wm.TempIndoorF.Record(wm.appCtx, u.TempIndoorF, metric.WithAttributeSet(attributes))
|
wm.recorder.Record(&RecordOpts{Float64Gauge: wm.TempIndoorF, FloatVal: u.TempIndoorF, Field: FieldTempIndoorF, Attributes: attributes, Station: u.StationConfig})
|
||||||
wm.HumidityOudoor.Record(wm.appCtx, int64(u.HumidityOudoor), metric.WithAttributeSet(attributes))
|
wm.recorder.Record(&RecordOpts{Int64Gauge: wm.HumidityOudoor, IntVal: u.HumidityOudoor, Field: FieldHumidityOudoor, Attributes: attributes, Station: u.StationConfig})
|
||||||
wm.HumidityIndoor.Record(wm.appCtx, int64(u.HumidityIndoor), metric.WithAttributeSet(attributes))
|
wm.recorder.Record(&RecordOpts{Int64Gauge: wm.HumidityIndoor, IntVal: u.HumidityIndoor, Field: FieldHumidityIndoor, Attributes: attributes, Station: u.StationConfig})
|
||||||
wm.WindSpeedMPH.Record(wm.appCtx, u.WindSpeedMPH, metric.WithAttributeSet(attributes))
|
wm.recorder.Record(&RecordOpts{Float64Gauge: wm.WindSpeedMPH, FloatVal: u.WindSpeedMPH, Field: FieldWindSpeedMPH, Attributes: attributes, Station: u.StationConfig})
|
||||||
wm.WindGustMPH.Record(wm.appCtx, u.WindGustMPH, metric.WithAttributeSet(attributes))
|
wm.recorder.Record(&RecordOpts{Float64Gauge: wm.WindGustMPH, FloatVal: u.WindGustMPH, Field: FieldWindGustMPH, Attributes: attributes, Station: u.StationConfig})
|
||||||
wm.MaxDailyGust.Record(wm.appCtx, u.MaxDailyGust, metric.WithAttributeSet(attributes))
|
wm.recorder.Record(&RecordOpts{Float64Gauge: wm.MaxDailyGust, FloatVal: u.MaxDailyGust, Field: FieldMaxDailyGust, Attributes: attributes, Station: u.StationConfig})
|
||||||
wm.WindDir.Record(wm.appCtx, int64(u.WindDir), metric.WithAttributeSet(attributes))
|
wm.recorder.Record(&RecordOpts{Int64Gauge: wm.WindDir, IntVal: u.WindDir, Field: FieldWindDir, Attributes: attributes, Station: u.StationConfig})
|
||||||
wm.WindDirAvg10m.Record(wm.appCtx, int64(u.WindDirAvg10m), metric.WithAttributeSet(attributes))
|
wm.recorder.Record(&RecordOpts{Int64Gauge: wm.WindDirAvg10m, IntVal: u.WindDirAvg10m, Field: FieldWindDirAvg10m, Attributes: attributes, Station: u.StationConfig})
|
||||||
wm.UV.Record(wm.appCtx, int64(u.UV), metric.WithAttributeSet(attributes))
|
wm.recorder.Record(&RecordOpts{Int64Gauge: wm.UV, IntVal: u.UV, Field: FieldUV, Attributes: attributes, Station: u.StationConfig})
|
||||||
wm.SolarRadiation.Record(wm.appCtx, u.SolarRadiation, metric.WithAttributeSet(attributes))
|
wm.recorder.Record(&RecordOpts{Float64Gauge: wm.SolarRadiation, FloatVal: u.SolarRadiation, Field: FieldSolarRadiation, Attributes: attributes, Station: u.StationConfig})
|
||||||
wm.HourlyRainIn.Record(wm.appCtx, u.HourlyRainIn, metric.WithAttributeSet(attributes))
|
wm.recorder.Record(&RecordOpts{Float64Gauge: wm.HourlyRainIn, FloatVal: u.HourlyRainIn, Field: FieldHourlyRainIn, Attributes: attributes, Station: u.StationConfig})
|
||||||
wm.EventRainIn.Record(wm.appCtx, u.EventRainIn, metric.WithAttributeSet(attributes))
|
wm.recorder.Record(&RecordOpts{Float64Gauge: wm.EventRainIn, FloatVal: u.EventRainIn, Field: FieldEventRainIn, Attributes: attributes, Station: u.StationConfig})
|
||||||
wm.DailyRainIn.Record(wm.appCtx, u.DailyRainIn, metric.WithAttributeSet(attributes))
|
wm.recorder.Record(&RecordOpts{Float64Gauge: wm.DailyRainIn, FloatVal: u.DailyRainIn, Field: FieldDailyRainIn, Attributes: attributes, Station: u.StationConfig})
|
||||||
wm.WeeklyRainIn.Record(wm.appCtx, u.WeeklyRainIn, metric.WithAttributeSet(attributes))
|
wm.recorder.Record(&RecordOpts{Float64Gauge: wm.WeeklyRainIn, FloatVal: u.WeeklyRainIn, Field: FieldWeeklyRainIn, Attributes: attributes, Station: u.StationConfig})
|
||||||
wm.MonthlyRainIn.Record(wm.appCtx, u.MonthlyRainIn, metric.WithAttributeSet(attributes))
|
wm.recorder.Record(&RecordOpts{Float64Gauge: wm.MonthlyRainIn, FloatVal: u.MonthlyRainIn, Field: FieldMonthlyRainIn, Attributes: attributes, Station: u.StationConfig})
|
||||||
wm.YearlyRainIn.Record(wm.appCtx, u.YearlyRainIn, metric.WithAttributeSet(attributes))
|
wm.recorder.Record(&RecordOpts{Float64Gauge: wm.YearlyRainIn, FloatVal: u.YearlyRainIn, Field: FieldYearlyRainIn, Attributes: attributes, Station: u.StationConfig})
|
||||||
wm.TotalRainIn.Record(wm.appCtx, u.TotalRainIn, metric.WithAttributeSet(attributes))
|
wm.recorder.Record(&RecordOpts{Float64Gauge: wm.TotalRainIn, FloatVal: u.TotalRainIn, Field: FieldTotalRainIn, Attributes: attributes, Station: u.StationConfig})
|
||||||
wm.BattOutdoorSensor.Record(wm.appCtx, int64(u.BattOutdoorSensor), metric.WithAttributeSet(attributes))
|
wm.recorder.Record(&RecordOpts{Float64Gauge: wm.BaromRelativeIn, FloatVal: u.BaromRelativeIn, Field: FieldBaromRelativeIn, Attributes: attributes, Station: u.StationConfig})
|
||||||
wm.BattIndoorSensor.Record(wm.appCtx, int64(u.BattIndoorSensor), metric.WithAttributeSet(attributes))
|
wm.recorder.Record(&RecordOpts{Float64Gauge: wm.BaromAbsoluteIn, FloatVal: u.BaromAbsoluteIn, Field: FieldBaromAbsoluteIn, Attributes: attributes, Station: u.StationConfig})
|
||||||
wm.BattRainSensor.Record(wm.appCtx, int64(u.BattRainSensor), metric.WithAttributeSet(attributes))
|
wm.recorder.Record(&RecordOpts{Float64Gauge: wm.DewPointF, FloatVal: u.DewPointF, Field: FieldDewPointF, Attributes: attributes, Station: u.StationConfig})
|
||||||
wm.BaromRelativeIn.Record(wm.appCtx, u.BaromRelativeIn, metric.WithAttributeSet(attributes))
|
wm.recorder.Record(&RecordOpts{Float64Gauge: wm.WindChillF, FloatVal: u.WindChillF, Field: FieldWindChillF, Attributes: attributes, Station: u.StationConfig})
|
||||||
wm.BaromAbsoluteIn.Record(wm.appCtx, u.BaromAbsoluteIn, metric.WithAttributeSet(attributes))
|
|
||||||
wm.DewPointF.Record(wm.appCtx, u.DewPointF, metric.WithAttributeSet(attributes))
|
// Batteries
|
||||||
wm.WindChillF.Record(wm.appCtx, u.WindChillF, metric.WithAttributeSet(attributes))
|
for _, battery := range u.Batteries {
|
||||||
|
batAttr := attributes
|
||||||
|
batAttr = append(batAttr, attribute.String("component", battery.Component))
|
||||||
|
|
||||||
|
wm.recorder.Record(&RecordOpts{Int64Gauge: wm.BatteryStatus, IntVal: battery.Status, Field: FieldBatteries, Attributes: batAttr, Station: u.StationConfig})
|
||||||
|
}
|
||||||
|
|
||||||
wm.UpdatesReceived.Add(wm.appCtx, 1)
|
wm.UpdatesReceived.Add(wm.appCtx, 1)
|
||||||
}
|
}
|
||||||
|
106
pkg/weather/metrics_record.go
Normal file
106
pkg/weather/metrics_record.go
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
package weather
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog"
|
||||||
|
"go.opentelemetry.io/otel/attribute"
|
||||||
|
"go.opentelemetry.io/otel/metric"
|
||||||
|
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/ambient/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MetricRecorder struct {
|
||||||
|
ctx context.Context
|
||||||
|
l *zerolog.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
type RecordOpts struct {
|
||||||
|
Float64Gauge metric.Float64Gauge
|
||||||
|
Int64Gauge metric.Int64Gauge
|
||||||
|
IntVal *int
|
||||||
|
FloatVal *float64
|
||||||
|
Attributes []attribute.KeyValue
|
||||||
|
Field string
|
||||||
|
Station *config.WeatherStation
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *MetricRecorder) Record(opts *RecordOpts) {
|
||||||
|
if opts.Station != nil && !opts.keep() {
|
||||||
|
r.l.Trace().
|
||||||
|
Str("field", string(opts.Field)).
|
||||||
|
Str("station", opts.Station.Name).
|
||||||
|
Msg("Metric dropped by station config")
|
||||||
|
return
|
||||||
|
} else if opts.Int64Gauge == nil && opts.Float64Gauge == nil {
|
||||||
|
r.l.Err(errors.New("neither int nor float gauge provided")).Send()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if opts.Int64Gauge != nil {
|
||||||
|
if opts.IntVal == nil {
|
||||||
|
log := r.l.Trace().Str("field", string(opts.Field))
|
||||||
|
if opts.Station != nil {
|
||||||
|
log = log.Str("station", opts.Station.Name)
|
||||||
|
}
|
||||||
|
log.Msg("Dropping nil int metric")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r.recordInt(opts.Int64Gauge, *opts.IntVal, opts.Attributes...)
|
||||||
|
} else if opts.Float64Gauge != nil {
|
||||||
|
if opts.FloatVal == nil {
|
||||||
|
log := r.l.Trace().Str("field", string(opts.Field))
|
||||||
|
if opts.Station != nil {
|
||||||
|
log = log.Str("station", opts.Station.Name)
|
||||||
|
}
|
||||||
|
log.Msg("Dropping nil float metric")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r.recordFloat(opts.Float64Gauge, *opts.FloatVal, opts.Attributes...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *RecordOpts) keep() bool {
|
||||||
|
// If keep fields are given, only check keep fields
|
||||||
|
if len(o.Station.KeepMetrics) > 0 {
|
||||||
|
for _, f := range o.Station.KeepMetrics {
|
||||||
|
if f == o.Field {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, f := range o.Station.DropMetrics {
|
||||||
|
if f == o.Field {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *MetricRecorder) recordInt(
|
||||||
|
m metric.Int64Gauge, value int, attributes ...attribute.KeyValue,
|
||||||
|
) {
|
||||||
|
// Prepare metric attributes
|
||||||
|
options := make([]metric.RecordOption, 0, len(attributes))
|
||||||
|
if len(attributes) > 0 {
|
||||||
|
options = append(options, metric.WithAttributes(attributes...))
|
||||||
|
}
|
||||||
|
|
||||||
|
val := int64(value)
|
||||||
|
m.Record(r.ctx, val, options...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *MetricRecorder) recordFloat(
|
||||||
|
m metric.Float64Gauge, value float64, attributes ...attribute.KeyValue,
|
||||||
|
) {
|
||||||
|
// Prepare metric attributes
|
||||||
|
options := make([]metric.RecordOption, 0, len(attributes))
|
||||||
|
if len(attributes) > 0 {
|
||||||
|
options = append(options, metric.WithAttributes(attributes...))
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Record(r.ctx, value, options...)
|
||||||
|
}
|
@ -2,38 +2,85 @@ package weather
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/ambient/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Stable intermediate struct containing superset of fields
|
// Stable intermediate struct containing superset of fields
|
||||||
// between AWN and Wunderground style updates from Ambient devices
|
// between AWN and Wunderground style updates from Ambient devices
|
||||||
type WeatherUpdate struct {
|
type WeatherUpdate struct {
|
||||||
DateUTC *time.Time
|
DateUTC *time.Time
|
||||||
StationType string
|
StationConfig *config.WeatherStation
|
||||||
TempOutdoorF float64
|
StationID *string
|
||||||
TempIndoorF float64
|
StationType *string
|
||||||
HumidityOudoor int
|
TempOutdoorF *float64
|
||||||
HumidityIndoor int
|
TempIndoorF *float64
|
||||||
WindSpeedMPH float64
|
HumidityOudoor *int
|
||||||
WindGustMPH float64
|
HumidityIndoor *int
|
||||||
MaxDailyGust float64
|
WindSpeedMPH *float64
|
||||||
WindDir int
|
WindGustMPH *float64
|
||||||
WindDirAvg10m int
|
MaxDailyGust *float64
|
||||||
UV int
|
WindDir *int
|
||||||
SolarRadiation float64
|
WindDirAvg10m *int
|
||||||
HourlyRainIn float64
|
UV *int
|
||||||
EventRainIn float64
|
SolarRadiation *float64
|
||||||
DailyRainIn float64
|
HourlyRainIn *float64
|
||||||
WeeklyRainIn float64
|
EventRainIn *float64
|
||||||
MonthlyRainIn float64
|
DailyRainIn *float64
|
||||||
YearlyRainIn float64
|
WeeklyRainIn *float64
|
||||||
TotalRainIn float64
|
MonthlyRainIn *float64
|
||||||
BattOutdoorSensor int
|
YearlyRainIn *float64
|
||||||
BattIndoorSensor int
|
TotalRainIn *float64
|
||||||
BattRainSensor int
|
Batteries []BatteryStatus
|
||||||
BaromRelativeIn float64
|
BaromRelativeIn *float64
|
||||||
BaromAbsoluteIn float64
|
BaromAbsoluteIn *float64
|
||||||
// These fields may be calculated
|
// These fields may be calculated
|
||||||
// if not otherwise set
|
// if not otherwise set
|
||||||
DewPointF float64
|
DewPointF *float64
|
||||||
WindChillF float64
|
WindChillF *float64
|
||||||
|
// First URL parameters given to AWN/Wunderground
|
||||||
|
// if proxying is enabled
|
||||||
|
}
|
||||||
|
|
||||||
|
type BatteryStatus struct {
|
||||||
|
Component string
|
||||||
|
Status *int
|
||||||
|
}
|
||||||
|
|
||||||
|
// CHORE: Maintain this, used to check against
|
||||||
|
// keep and drop lists
|
||||||
|
// TODO: Use refelct/ast to generate code
|
||||||
|
const (
|
||||||
|
FieldDateUTC = "DateUTC"
|
||||||
|
FieldStationType = "StationType"
|
||||||
|
FieldTempOutdoorF = "TempOutdoorF"
|
||||||
|
FieldTempIndoorF = "TempIndoorF"
|
||||||
|
FieldHumidityOudoor = "HumidityOudoor"
|
||||||
|
FieldHumidityIndoor = "HumidityIndoor"
|
||||||
|
FieldWindSpeedMPH = "WindSpeedMPH"
|
||||||
|
FieldWindGustMPH = "WindGustMPH"
|
||||||
|
FieldMaxDailyGust = "MaxDailyGust"
|
||||||
|
FieldWindDir = "WindDir"
|
||||||
|
FieldWindDirAvg10m = "WindDirAvg10m"
|
||||||
|
FieldUV = "UV"
|
||||||
|
FieldSolarRadiation = "SolarRadiation"
|
||||||
|
FieldHourlyRainIn = "HourlyRainIn"
|
||||||
|
FieldEventRainIn = "EventRainIn"
|
||||||
|
FieldDailyRainIn = "DailyRainIn"
|
||||||
|
FieldWeeklyRainIn = "WeeklyRainIn"
|
||||||
|
FieldMonthlyRainIn = "MonthlyRainIn"
|
||||||
|
FieldYearlyRainIn = "YearlyRainIn"
|
||||||
|
FieldTotalRainIn = "TotalRainIn"
|
||||||
|
FieldBatteries = "Batteries"
|
||||||
|
FieldBaromRelativeIn = "BaromRelativeIn"
|
||||||
|
FieldBaromAbsoluteIn = "BaromAbsoluteIn"
|
||||||
|
FieldDewPointF = "DewPointF"
|
||||||
|
FieldWindChillF = "WindChillF"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (u *WeatherUpdate) GetStationName() string {
|
||||||
|
if u.StationConfig != nil {
|
||||||
|
return u.StationConfig.Name
|
||||||
|
}
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user