This commit is contained in:
@ -34,6 +34,7 @@ type AmbientWeather struct {
|
||||
|
||||
func New(appCtx context.Context, awConfig *AmbientLocalExporterConfig) *AmbientWeather {
|
||||
return &AmbientWeather{
|
||||
config: awConfig,
|
||||
appCtx: appCtx,
|
||||
}
|
||||
}
|
||||
@ -43,6 +44,8 @@ func (aw *AmbientWeather) Init() *AmbientWeather {
|
||||
aw.awnProvider = &awn.AWNProvider{}
|
||||
aw.wuProvider = &wunderground.WUProvider{}
|
||||
aw.l = zerolog.Ctx(aw.appCtx)
|
||||
|
||||
aw.l.Trace().Any("awConfig", aw.config).Send()
|
||||
return aw
|
||||
}
|
||||
|
||||
@ -95,13 +98,15 @@ func (aw *AmbientWeather) handleProviderRequest(
|
||||
// such as dew point and wind chill
|
||||
update.Enrich()
|
||||
|
||||
// Update metrics
|
||||
// Prepare metrics if this is the first update
|
||||
if aw.metrics == nil {
|
||||
if aw.config.MetricPrefix != "" {
|
||||
weather.MetricPrefix = aw.config.MetricPrefix
|
||||
}
|
||||
aw.metrics = weather.MustInitMetrics(aw.appCtx)
|
||||
aw.InitMetrics()
|
||||
}
|
||||
|
||||
// Enrich station if configured
|
||||
aw.enrichStation(update)
|
||||
|
||||
// Update metrics
|
||||
aw.metrics.Update(update)
|
||||
|
||||
l.Debug().
|
||||
@ -110,3 +115,26 @@ func (aw *AmbientWeather) handleProviderRequest(
|
||||
Msg("successfully handled update")
|
||||
w.Write([]byte("ok"))
|
||||
}
|
||||
|
||||
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.StationInfo = &weather.StationInfo{
|
||||
Type: update.StationType,
|
||||
Equipment: &station.Equipment,
|
||||
Name: &station.Name,
|
||||
Keep: station.KeepMetrics,
|
||||
Drop: station.DropMetrics,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,10 @@ type WeatherStation struct {
|
||||
ProxyToWunderground bool `yaml:"proxyToWunderground"`
|
||||
|
||||
// Unreliable / unwanted metrics by name of WeatherUpdate Field
|
||||
// These fields are mapped from the provider fields
|
||||
DiscardMetrics []weather.WeatherUpdateField `yaml:"discardMetrics"`
|
||||
// will be excluded if present in discardMetrics
|
||||
//
|
||||
// If anything is present in keepMetrics, it is solely applied,
|
||||
// ignoring discardMetrics
|
||||
KeepMetrics []weather.WeatherUpdateField `yaml:"keepMetrics"`
|
||||
DropMetrics []weather.WeatherUpdateField `yaml:"dropMetrics"`
|
||||
}
|
||||
|
Reference in New Issue
Block a user