Skip to content

Commit

Permalink
Add enable/disable power price collecting
Browse files Browse the repository at this point in the history
  • Loading branch information
GJSBRT committed Apr 12, 2024
1 parent e95d151 commit 05d9123
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
16 changes: 14 additions & 2 deletions power_prices/power_prices.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import (
)

type PowerPriceSourceConfigs struct {
AllInPower AllInPowerConfig `mapstructure:"all-in-power"`
Entsoe EntsoeConfig `mapstructure:"entsoe"`
}

type Config struct {
Enabled bool `mapstructure:"enabled"`
Sources PowerPriceSourceConfigs `mapstructure:"sources"`
}

Expand Down Expand Up @@ -45,8 +47,13 @@ func New(
logger *logrus.Logger,
victoriaMetrics *victoria_metrics.VictoriaMetrics,
) *PowerPrices {
sources = append(sources, newAllInPower())
sources = append(sources, newEntsoe(config.Sources.Entsoe))
if !config.Sources.AllInPower.Enable {
sources = append(sources, newAllInPower(config.Sources.AllInPower))
}

if !config.Sources.Entsoe.Enable {
sources = append(sources, newEntsoe(config.Sources.Entsoe))
}

return &PowerPrices{
Config: config,
Expand Down Expand Up @@ -97,6 +104,11 @@ func (pp *PowerPrices) updateMetrics() error {
}

func (pp *PowerPrices) Start() {
if !pp.Config.Enabled {
pp.logger.Warn("Power price collector is disabled")
return
}

pp.logger.Info("Starting power price collector")

err := pp.updateMetrics()
Expand Down
8 changes: 7 additions & 1 deletion power_prices/source_allinpower.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ import (
"encoding/json"
)

type AllInPowerConfig struct {
Enable bool `mapstructure:"enable"`
}

type AllInPower struct {
name string
Client *http.Client
Config AllInPowerConfig
}

func newAllInPower() *AllInPower {
func newAllInPower(config AllInPowerConfig) *AllInPower {
return &AllInPower{
name: "all-in-power",
Client: &http.Client{},
Config: config,
}
}

Expand Down
1 change: 1 addition & 0 deletions power_prices/source_entsoe.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
const entsoeTimestampFormat = "200601021504"

type EntsoeConfig struct {
Enable bool `mapstructure:"enable"`
SecurityToken string `mapstructure:"security-token"`
Domain string `mapstructure:"domain"`
}
Expand Down

0 comments on commit 05d9123

Please sign in to comment.