Skip to content

Commit

Permalink
chore: update to weatherflow v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tris committed May 30, 2023
1 parent a2af30a commit dc180f3
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# weatherflow_exporter

weatherflow_exporter is a Prometheus exporter for
weatherflow_exporter is a [Prometheus](https://prometheus.io) exporter for
[WeatherFlow Tempest](https://weatherflow.com/tempest-home-weather-system/)
weather stations.

Expand Down Expand Up @@ -31,7 +31,8 @@ are no other configuration options.
## Grafana dashboard

TBD. You can get some inspiration from the
[Mussel Rock Weather](https://mr.ethereal.net) dashboard, which this powers.
[Mussel Rock Weather](https://mr.ethereal.net) dashboard, which is powered by
this exporter.

[Dave Schmid](https://github.com/lux4rd0) has also built some excellent
dashboards as part of his own
Expand Down
6 changes: 2 additions & 4 deletions exporter/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,10 @@ func (wc *WeatherCollector) Collect(ch chan<- prometheus.Metric) {
}

func (wc *WeatherCollector) update(msg weatherflow.Message, apiToken string) {
deviceID := msg.GetDeviceID()

switch m := msg.(type) {
case *weatherflow.MessageObsSt:
timestamp := time.Unix(int64(m.Obs[0].TimeEpoch), 0)
deviceIDStr := strconv.Itoa(deviceID)
deviceIDStr := strconv.Itoa(m.DeviceID)
wc.metric.WindLull = prometheus.NewMetricWithTimestamp(timestamp, prometheus.MustNewConstMetric(
desc.WindLull,
prometheus.GaugeValue,
Expand Down Expand Up @@ -366,7 +364,7 @@ func (wc *WeatherCollector) update(msg weatherflow.Message, apiToken string) {

case *weatherflow.MessageRapidWind:
timestamp := time.Unix(int64(m.Ob.TimeEpoch), 0)
deviceIDStr := strconv.Itoa(deviceID)
deviceIDStr := strconv.Itoa(m.DeviceID)
wc.metric.WindSpeed = prometheus.NewMetricWithTimestamp(timestamp, prometheus.MustNewConstMetric(
desc.WindSpeed,
prometheus.GaugeValue,
Expand Down
8 changes: 4 additions & 4 deletions exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

const (
timeoutDuration = 30 * time.Minute
idleTimeout = 30 * time.Minute
)

type WeatherExporter struct {
Expand Down Expand Up @@ -61,15 +61,15 @@ func (we *WeatherExporter) ScrapeHandler(w http.ResponseWriter, r *http.Request)

collector, ok := collectorsForToken[deviceID]
if ok {
collector.timer.Reset(timeoutDuration)
collector.timer.Reset(idleTimeout)
} else {
collector = NewWeatherCollector(deviceID)
collectorsForToken[deviceID] = collector
we.initCollectorTimer(collector, apiToken, deviceID)

client, clientExists := we.clients[apiToken]
if !clientExists {
client = weatherflow.NewClient(apiToken, prefixedLogger(apiToken, log.Printf))
client = weatherflow.NewClient(apiToken, nil, prefixedLogger(apiToken, log.Printf))
we.clients[apiToken] = client
client.Start(func(msg weatherflow.Message) {
collector.update(msg, apiToken)
Expand All @@ -96,7 +96,7 @@ func (we *WeatherExporter) ScrapeHandler(w http.ResponseWriter, r *http.Request)
}

func (we *WeatherExporter) initCollectorTimer(collector *WeatherCollector, apiToken string, deviceID int) {
collector.timer = time.AfterFunc(timeoutDuration, func() {
collector.timer = time.AfterFunc(idleTimeout, func() {
we.mu.Lock()
defer we.mu.Unlock()

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/prometheus/client_golang v1.15.1
github.com/tris/weatherflow v0.2.0
github.com/tris/weatherflow v0.3.0
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/tris/weatherflow v0.2.0 h1:CEFvaV8Pg0ilsey1G2wuDRJ71K+xP6G8FqSqGxMUONo=
github.com/tris/weatherflow v0.2.0/go.mod h1:56/nMqI3UNeWVaNuau28D1MrgLlJyHYfvn2wcwPrtE8=
github.com/tris/weatherflow v0.3.0 h1:3dbEat7zTErBZ3DLB457OeRkwAySt3jjZWRW5eigFN8=
github.com/tris/weatherflow v0.3.0/go.mod h1:56/nMqI3UNeWVaNuau28D1MrgLlJyHYfvn2wcwPrtE8=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
Expand Down

0 comments on commit dc180f3

Please sign in to comment.