mirror of
https://github.com/openziti/zrok.git
synced 2025-06-19 17:27:54 +02:00
more limits.Agent elaboration (#271)
This commit is contained in:
parent
b69237e9cc
commit
9418195150
@ -88,9 +88,7 @@ func Run(inCfg *config.Config) error {
|
|||||||
return errors.Wrap(err, "error creating limits agent")
|
return errors.Wrap(err, "error creating limits agent")
|
||||||
}
|
}
|
||||||
ma.AddUsageSink(la)
|
ma.AddUsageSink(la)
|
||||||
if err := la.Start(); err != nil {
|
la.Start()
|
||||||
return errors.Wrap(err, "error starting limits agent")
|
|
||||||
}
|
|
||||||
defer func() { la.Stop() }()
|
defer func() { la.Stop() }()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,23 +5,56 @@ import (
|
|||||||
"github.com/openziti/zrok/controller/store"
|
"github.com/openziti/zrok/controller/store"
|
||||||
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Agent struct {
|
type Agent struct {
|
||||||
|
cfg *Config
|
||||||
|
ifx *influxReader
|
||||||
|
zCfg *zrokEdgeSdk.Config
|
||||||
|
str *store.Store
|
||||||
|
close chan struct{}
|
||||||
|
join chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAgent(cfg *Config, ifxCfg *metrics.InfluxConfig, zCfg *zrokEdgeSdk.Config, str *store.Store) (*Agent, error) {
|
func NewAgent(cfg *Config, ifxCfg *metrics.InfluxConfig, zCfg *zrokEdgeSdk.Config, str *store.Store) (*Agent, error) {
|
||||||
return &Agent{}, nil
|
return &Agent{
|
||||||
|
cfg: cfg,
|
||||||
|
ifx: newInfluxReader(ifxCfg),
|
||||||
|
zCfg: zCfg,
|
||||||
|
str: str,
|
||||||
|
close: make(chan struct{}),
|
||||||
|
join: make(chan struct{}),
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Agent) Start() error {
|
func (a *Agent) Start() {
|
||||||
return nil
|
go a.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Agent) Stop() {
|
func (a *Agent) Stop() {
|
||||||
|
close(a.close)
|
||||||
|
<-a.join
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Agent) Handle(u *metrics.Usage) error {
|
func (a *Agent) Handle(u *metrics.Usage) error {
|
||||||
logrus.Infof("handling: %v", u)
|
logrus.Infof("handling: %v", u)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *Agent) run() {
|
||||||
|
logrus.Info("started")
|
||||||
|
defer logrus.Info("stopped")
|
||||||
|
|
||||||
|
mainLoop:
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-time.After(a.cfg.Cycle):
|
||||||
|
logrus.Info("insepection cycle")
|
||||||
|
|
||||||
|
case <-a.close:
|
||||||
|
close(a.join)
|
||||||
|
break mainLoop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -8,6 +8,7 @@ type Config struct {
|
|||||||
Environments int
|
Environments int
|
||||||
Shares int
|
Shares int
|
||||||
Bandwidth *BandwidthConfig
|
Bandwidth *BandwidthConfig
|
||||||
|
Cycle time.Duration
|
||||||
Enforcing bool
|
Enforcing bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,5 +75,7 @@ func DefaultConfig() *Config {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Enforcing: false,
|
||||||
|
Cycle: 15 * time.Minute,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
18
controller/limits/influxReader.go
Normal file
18
controller/limits/influxReader.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package limits
|
||||||
|
|
||||||
|
import (
|
||||||
|
influxdb2 "github.com/influxdata/influxdb-client-go/v2"
|
||||||
|
"github.com/influxdata/influxdb-client-go/v2/api"
|
||||||
|
"github.com/openziti/zrok/controller/metrics"
|
||||||
|
)
|
||||||
|
|
||||||
|
type influxReader struct {
|
||||||
|
idb influxdb2.Client
|
||||||
|
queryApi api.QueryAPI
|
||||||
|
}
|
||||||
|
|
||||||
|
func newInfluxReader(cfg *metrics.InfluxConfig) *influxReader {
|
||||||
|
idb := influxdb2.NewClient(cfg.Url, cfg.Token)
|
||||||
|
queryApi := idb.QueryAPI(cfg.Org)
|
||||||
|
return &influxReader{idb, queryApi}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user