@@ -14,6 +14,7 @@ import (
1414 "golang.org/x/time/rate"
1515
1616 monitor "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/monitor/v20180724"
17+ v20180724 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/monitor/v20180724"
1718 "github.com/tencentyun/tencentcloud-exporter/pkg/client"
1819 "github.com/tencentyun/tencentcloud-exporter/pkg/config"
1920)
@@ -35,10 +36,11 @@ type TcmMetricRepository interface {
3536}
3637
3738type TcmMetricRepositoryImpl struct {
38- credential common.CredentialIface
39- monitorClient * monitor.Client
40- limiter * rate.Limiter // 限速
41- ctx context.Context
39+ credential common.CredentialIface
40+ monitorClient * monitor.Client
41+ monitorClientInGuangzhou * monitor.Client
42+ limiter * rate.Limiter // 限速
43+ ctx context.Context
4244
4345 queryMetricBatchSize int
4446
@@ -130,7 +132,12 @@ func (repo *TcmMetricRepositoryImpl) GetSamples(s *TcmSeries, st int64, et int64
130132 request .EndTime = & etStr
131133 }
132134
133- response , err := repo .monitorClient .GetMonitorData (request )
135+ response := & v20180724.GetMonitorDataResponse {}
136+ if s .Metric .Meta .ProductName == "COS" {
137+ response , err = repo .monitorClientInGuangzhou .GetMonitorData (request )
138+ } else {
139+ response , err = repo .monitorClient .GetMonitorData (request )
140+ }
134141 if err != nil {
135142 return
136143 }
@@ -175,9 +182,14 @@ func (repo *TcmMetricRepositoryImpl) listSampleByBatch(
175182 return nil , err
176183 }
177184
178- //level.Info(repo.logger).Log("st", st, "et", et)
179185 request := repo .buildGetMonitorDataRequest (m , seriesList , st , et )
180- response , err := repo .monitorClient .GetMonitorData (request )
186+
187+ response := & v20180724.GetMonitorDataResponse {}
188+ if m .Meta .ProductName == "COS" {
189+ response , err = repo .monitorClientInGuangzhou .GetMonitorData (request )
190+ } else {
191+ response , err = repo .monitorClient .GetMonitorData (request )
192+ }
181193 if err != nil {
182194 return nil , err
183195 }
@@ -262,18 +274,23 @@ func (repo *TcmMetricRepositoryImpl) buildSamples(
262274}
263275
264276func NewTcmMetricRepository (cred common.CredentialIface , conf * config.TencentConfig , logger log.Logger ) (repo TcmMetricRepository , err error ) {
265- monitorClient , err := client .NewMonitorClient (cred , conf )
277+ monitorClient , err := client .NewMonitorClient (cred , conf , conf .Credential .Region )
278+ if err != nil {
279+ return
280+ }
281+ monitorClientInGuangzhou , err := client .NewMonitorClient (cred , conf , "ap-guangzhou" )
266282 if err != nil {
267283 return
268284 }
269285
270286 repo = & TcmMetricRepositoryImpl {
271- credential : cred ,
272- monitorClient : monitorClient ,
273- limiter : rate .NewLimiter (rate .Limit (conf .RateLimit ), 1 ),
274- ctx : context .Background (),
275- queryMetricBatchSize : conf .MetricQueryBatchSize ,
276- logger : logger ,
287+ credential : cred ,
288+ monitorClient : monitorClient ,
289+ monitorClientInGuangzhou : monitorClientInGuangzhou ,
290+ limiter : rate .NewLimiter (rate .Limit (conf .RateLimit ), 1 ),
291+ ctx : context .Background (),
292+ queryMetricBatchSize : conf .MetricQueryBatchSize ,
293+ logger : logger ,
277294 }
278295
279296 return
0 commit comments