diff --git a/pkg/config/config.go b/pkg/config/config.go index ae4c976..e7e55cc 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -144,7 +144,8 @@ type TencentConfig struct { RateLimit float64 `yaml:"rate_limit"` MetricQueryBatchSize int `yaml:"metric_query_batch_size"` Filename string `yaml:"filename"` - CacheInterval int64 `yaml:"cache_interval"` // 单位 s + CacheInterval int64 `yaml:"cache_interval"` // 单位 s + IsInternational bool `yaml:"is_international"` // true 表示是国际站 } func NewConfig() *TencentConfig { diff --git a/pkg/metric/repository.go b/pkg/metric/repository.go index 052f3ee..43c10be 100644 --- a/pkg/metric/repository.go +++ b/pkg/metric/repository.go @@ -39,8 +39,10 @@ type TcmMetricRepositoryImpl struct { credential common.CredentialIface monitorClient *monitor.Client monitorClientInGuangzhou *monitor.Client + monitorClientInSinapore *monitor.Client limiter *rate.Limiter // 限速 ctx context.Context + IsInternational bool queryMetricBatchSize int @@ -133,7 +135,9 @@ func (repo *TcmMetricRepositoryImpl) GetSamples(s *TcmSeries, st int64, et int64 } response := &v20180724.GetMonitorDataResponse{} - if util.IsStrInList(config.QcloudNamespace, s.Metric.Meta.ProductName) { + if repo.IsInternational && s.Metric.Meta.ProductName == "QAAP" { + response, err = repo.monitorClientInSinapore.GetMonitorData(request) + } else if util.IsStrInList(config.QcloudNamespace, s.Metric.Meta.ProductName) { response, err = repo.monitorClientInGuangzhou.GetMonitorData(request) } else { response, err = repo.monitorClient.GetMonitorData(request) @@ -185,7 +189,9 @@ func (repo *TcmMetricRepositoryImpl) listSampleByBatch( request := repo.buildGetMonitorDataRequest(m, seriesList, st, et) response := &v20180724.GetMonitorDataResponse{} - if util.IsStrInList(config.QcloudNamespace, m.Meta.ProductName) { + if repo.IsInternational && m.Meta.ProductName == "QAAP" { + response, err = repo.monitorClientInSinapore.GetMonitorData(request) + } else if util.IsStrInList(config.QcloudNamespace, m.Meta.ProductName) { response, err = repo.monitorClientInGuangzhou.GetMonitorData(request) } else { response, err = repo.monitorClient.GetMonitorData(request) @@ -282,13 +288,21 @@ func NewTcmMetricRepository(cred common.CredentialIface, conf *config.TencentCon if err != nil { return } + var monitorClientInSingapore *monitor.Client + if conf.IsInternational { + if monitorClientInSingapore, err = client.NewMonitorClient(cred, conf, "ap-singapore"); err != nil { + return + } + } repo = &TcmMetricRepositoryImpl{ credential: cred, monitorClient: monitorClient, monitorClientInGuangzhou: monitorClientInGuangzhou, + monitorClientInSinapore: monitorClientInSingapore, limiter: rate.NewLimiter(rate.Limit(conf.RateLimit), 1), ctx: context.Background(), + IsInternational: conf.IsInternational, queryMetricBatchSize: conf.MetricQueryBatchSize, logger: logger, }