observatory.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. package conf
  2. import (
  3. "google.golang.org/protobuf/proto"
  4. "github.com/xtls/xray-core/app/observatory"
  5. "github.com/xtls/xray-core/app/observatory/burst"
  6. "github.com/xtls/xray-core/infra/conf/cfgcommon/duration"
  7. )
  8. type ObservatoryConfig struct {
  9. SubjectSelector []string `json:"subjectSelector"`
  10. ProbeURL string `json:"probeURL"`
  11. ProbeInterval duration.Duration `json:"probeInterval"`
  12. EnableConcurrency bool `json:"enableConcurrency"`
  13. }
  14. func (o *ObservatoryConfig) Build() (proto.Message, error) {
  15. return &observatory.Config{SubjectSelector: o.SubjectSelector, ProbeUrl: o.ProbeURL, ProbeInterval: int64(o.ProbeInterval), EnableConcurrency: o.EnableConcurrency}, nil
  16. }
  17. type BurstObservatoryConfig struct {
  18. SubjectSelector []string `json:"subjectSelector"`
  19. // health check settings
  20. HealthCheck *healthCheckSettings `json:"pingConfig,omitempty"`
  21. }
  22. func (b BurstObservatoryConfig) Build() (proto.Message, error) {
  23. if result, err := b.HealthCheck.Build(); err == nil {
  24. return &burst.Config{SubjectSelector: b.SubjectSelector, PingConfig: result.(*burst.HealthPingConfig)}, nil
  25. } else {
  26. return nil, err
  27. }
  28. }