Skip to content

Commit a1860c5

Browse files
author
zianazhao
committed
1、vbc:支持地域间类指标数据查询
2、dts:支持数据同步类指标数据查询 3、gaap:支持全球应用加速-通道监控、4层源站监控类指标查询
1 parent 2353fa5 commit a1860c5

File tree

12 files changed

+606
-70
lines changed

12 files changed

+606
-70
lines changed

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ require (
1515
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.334
1616
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.334
1717
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cmq v1.0.334
18-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.479
18+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.531
1919
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.334
2020
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.413
2121
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dc v1.0.334
2222
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dcdb v1.0.334
23-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dts v1.0.479
23+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dts v1.0.531
2424
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/es v1.0.334
25+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap v1.0.528
2526
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse v1.0.334
2627
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mariadb v1.0.334
2728
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/memcached v1.0.334

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
212212
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
213213
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
214214
github.com/tencentcloud/tencentcloud-sdk-go v1.0.485 h1:l1xeZUO2ddcouOpxO7dhkXcmcYembuCG5EZ6O+Cox/o=
215+
github.com/tencentcloud/tencentcloud-sdk-go v1.0.528 h1:6HidDboNfqxPVD6/hSgK4vcw3B/sNLHi8ysAAj70Bsc=
216+
github.com/tencentcloud/tencentcloud-sdk-go v1.0.532 h1:8AmaxcmnFwH5HTcmE9suGsI2CROtiVkNQvot64Y+gv0=
215217
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cbs v1.0.334 h1:GijOjoDBcWXtra6hmzpj4IXOahWmsTE3bwpOcp5VBDw=
216218
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cbs v1.0.334/go.mod h1:PTp058qpOV//RukBVdYQT962rZg71lIt6eHLK1zdvEc=
217219
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdb v1.0.413 h1:6cQPfHc3I1pKUj23csRd9P/xxUPcnGRLRK2e5NGqtzc=
@@ -231,6 +233,10 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.437 h1:Qa0q
231233
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.437/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
232234
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.479 h1:3kwDb6p1J3LxmwnNgSSEheemPffo+vMewoDzKysYdig=
233235
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.479/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
236+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.528 h1:ECUVFkluily8Cr0VHzcKmC0M7PLNqEOkoKoS5DukSmA=
237+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.528/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
238+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.531 h1:E8vq0WQBjB3jjtCK3u5DPrWGqlgyQUvQ19EkgBob1A8=
239+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.531/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
234240
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.334 h1:ulfSODMy8rpKa8MfnTIPbe5HyOArnlB4RJ1qmpj09to=
235241
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.334/go.mod h1:AqyM/ZZMD7q5mHBqNY9YImbSpEpoEe7E/vrTbUWX+po=
236242
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.413 h1:MomwSkFrSLB16s51Yu1h4JO+p3Pzc1yesIj+oNwAVM0=
@@ -241,8 +247,12 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dcdb v1.0.334 h1:Xxe889
241247
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dcdb v1.0.334/go.mod h1:uvcrduqH3pPyyZoZyEX0WXlXIR554ys3ctSsKoeJp64=
242248
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dts v1.0.479 h1:Tuo8zLhHaO+AxHlk7WOYGs6j/3bfD3FMNB3fWAgIxWM=
243249
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dts v1.0.479/go.mod h1:CNPxkXeOC/vOmu9a/yaxp+2immIjDL/WsGC/H2rcWQA=
250+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dts v1.0.531 h1:U0diLtuiEK8RDjfEh7X/BKetd+OppXWvoCW3CFJCMKE=
251+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dts v1.0.531/go.mod h1:Mwk3VuBuWg6d2JtT5pKXKfNKxYRH1mrWquMcTVZQ7gc=
244252
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/es v1.0.334 h1:oXOMQ2EmNjqMfpShQeCrWS5QH2MwrAhJfd0rLJOxccE=
245253
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/es v1.0.334/go.mod h1:UegCt4vv9jAlzpgDu31ZJTuRP5T2BTV8w+jZBTsZIzg=
254+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap v1.0.528 h1:CS8HIQNpfYQogrPR/WEFdVNJX6GIOwDyBzn1IHMb46g=
255+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap v1.0.528/go.mod h1:J+xFyeGmSCp0x4tXPu5mlAhg2BAYQPIy3fQ4afy26tI=
246256
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.194/go.mod h1:yrBKWhChnDqNz1xuXdSbWXG56XawEq0G5j1lg4VwBD4=
247257
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse v1.0.334 h1:druwbDkTAvVwEGW4nHVuTuOX0bjk1CtLUDiC3r4gmgY=
248258
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse v1.0.334/go.mod h1:r8txjlw4DjLDZFOpnPC/hOFHr1VckZc0jjBK6XIFLP0=

pkg/client/client.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import (
1616
dc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dc/v20180410"
1717
dcdb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dcdb/v20180411"
1818
dts "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dts/v20180330"
19+
dtsNew "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dts/v20211206"
1920
es "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/es/v20180416"
21+
gaap "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap/v20180529"
2022
lh "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse/v20200324"
2123
mariadb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mariadb/v20170312"
2224
memcached "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/memcached/v20190318"
@@ -284,3 +286,22 @@ func NewDTSClient(cred common.CredentialIface, conf *config.TencentConfig) (*dts
284286
}
285287
return dts.NewClient(cred, conf.Credential.Region, cpf)
286288
}
289+
func NewDTSNewClient(cred common.CredentialIface, conf *config.TencentConfig) (*dtsNew.Client, error) {
290+
cpf := profile.NewClientProfile()
291+
if conf.Credential.IsInternal == true {
292+
cpf.HttpProfile.Endpoint = "dts.internal.tencentcloudapi.com"
293+
} else {
294+
cpf.HttpProfile.Endpoint = "dts.tencentcloudapi.com"
295+
}
296+
return dtsNew.NewClient(cred, conf.Credential.Region, cpf)
297+
}
298+
299+
func NewGAAPClient(cred common.CredentialIface, conf *config.TencentConfig) (*gaap.Client, error) {
300+
cpf := profile.NewClientProfile()
301+
if conf.Credential.IsInternal == true {
302+
cpf.HttpProfile.Endpoint = "gaap.internal.tencentcloudapi.com"
303+
} else {
304+
cpf.HttpProfile.Endpoint = "gaap.tencentcloudapi.com"
305+
}
306+
return gaap.NewClient(cred, conf.Credential.Region, cpf)
307+
}

pkg/collector/handler_dts.go

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/tencentyun/tencentcloud-exporter/pkg/instance"
99
"github.com/tencentyun/tencentcloud-exporter/pkg/metric"
1010
"github.com/tencentyun/tencentcloud-exporter/pkg/util"
11+
"time"
1112
)
1213

1314
const (
@@ -21,7 +22,7 @@ func init() {
2122

2223
type dtsHandler struct {
2324
baseProductHandler
24-
// replicationRepo instance.DtsTcInstanceReplicationsRepository
25+
replicationRepo instance.DtsTcInstanceReplicationsRepository
2526
migrateInfosRepo instance.DtsTcInstanceMigrateInfosRepository
2627
}
2728

@@ -136,6 +137,7 @@ func (h *dtsHandler) getSeriesByMetricType(m *metric.TcmMetric, ins instance.TcI
136137
for _, v := range m.Meta.SupportDimensions {
137138
dimensions = append(dimensions, v)
138139
}
140+
139141
if util.IsStrInList(dimensions, "replicationjobid") {
140142
return h.getReplicationSeries(m, ins)
141143
} else if util.IsStrInList(dimensions, "migratejobid") {
@@ -162,25 +164,25 @@ func (h *dtsHandler) getInstanceSeries(m *metric.TcmMetric, ins instance.TcInsta
162164

163165
func (h *dtsHandler) getReplicationSeries(m *metric.TcmMetric, ins instance.TcInstance) ([]*metric.TcmSeries, error) {
164166
var series []*metric.TcmSeries
165-
// replications, err := h.replicationsRepo.GetReplicationInfo()
166-
// if err != nil {
167-
// return nil, err
168-
// }
169-
// for _, replication := range replications.Response.JobList {
170-
// ql := map[string]string{
171-
// "replicationjobid": *replication.JobId,
172-
// }
173-
// s, err := metric.NewTcmSeries(m, ql, ins)
174-
// if err != nil {
175-
// return nil, err
176-
// }
177-
// series = append(series, s)
178-
// }
167+
replications, err := h.replicationRepo.GetReplicationsInfo("")
168+
if err != nil {
169+
return nil, err
170+
}
171+
for _, replication := range replications.Response.JobList {
172+
ql := map[string]string{
173+
"replicationjobid": *replication.JobId,
174+
}
175+
s, err := metric.NewTcmSeries(m, ql, ins)
176+
if err != nil {
177+
return nil, err
178+
}
179+
series = append(series, s)
180+
}
179181
return series, nil
180182
}
181183
func (h *dtsHandler) getMigrateInfoSeries(m *metric.TcmMetric, ins instance.TcInstance) ([]*metric.TcmSeries, error) {
182184
var series []*metric.TcmSeries
183-
migrateInfos, err := h.migrateInfosRepo.GetMigrateInfosInfo()
185+
migrateInfos, err := h.migrateInfosRepo.GetMigrateInfos("")
184186
if err != nil {
185187
return nil, err
186188
}
@@ -199,12 +201,18 @@ func (h *dtsHandler) getMigrateInfoSeries(m *metric.TcmMetric, ins instance.TcIn
199201
}
200202

201203
func NewDTSHandler(cred common.CredentialIface, c *TcProductCollector, logger log.Logger) (handler ProductHandler, err error) {
202-
migrateInfosRepoCahe, err := instance.NewDtsTcInstanceMigrateInfosRepository(cred, c.Conf, logger)
204+
migrateInfosRepo, err := instance.NewDtsTcInstanceMigrateInfosRepository(cred, c.Conf, logger)
205+
if err != nil {
206+
return nil, err
207+
}
208+
relodInterval := time.Duration(c.ProductConf.RelodIntervalMinutes * int64(time.Minute))
209+
migrateInfosRepoCahe := instance.NewTcDtsInstanceMigrateInfosCache(migrateInfosRepo, relodInterval, logger)
210+
211+
replicationRepo, err := instance.NewDtsTcInstanceReplicationsRepository(cred, c.Conf, logger)
203212
if err != nil {
204213
return nil, err
205214
}
206-
// relodInterval := time.Duration(c.ProductConf.RelodIntervalMinutes * int64(time.Minute))
207-
// migrateInfosRepoCahe := instance.NewDtsTcInstanceMigrateInfosCache(migrateInfoRepo, relodInterval, logger)
215+
replicationRepoCache := instance.NewTcDtsInstanceReplicationsInfosCache(replicationRepo, relodInterval, logger)
208216

209217
handler = &dtsHandler{
210218
baseProductHandler: baseProductHandler{
@@ -213,6 +221,7 @@ func NewDTSHandler(cred common.CredentialIface, c *TcProductCollector, logger lo
213221
logger: logger,
214222
},
215223
migrateInfosRepo: migrateInfosRepoCahe,
224+
replicationRepo: replicationRepoCache,
216225
}
217226
return
218227

pkg/collector/handler_qaap.go

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
package collector
2+
3+
import (
4+
"fmt"
5+
"github.com/go-kit/log"
6+
"github.com/go-kit/log/level"
7+
sdk "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap/v20180529"
8+
"github.com/tencentyun/tencentcloud-exporter/pkg/common"
9+
"github.com/tencentyun/tencentcloud-exporter/pkg/instance"
10+
"github.com/tencentyun/tencentcloud-exporter/pkg/metric"
11+
"github.com/tencentyun/tencentcloud-exporter/pkg/util"
12+
)
13+
14+
const (
15+
QaapNamespace = "QCE/QAAP"
16+
QaapInstanceidKey = "channelId"
17+
)
18+
19+
func init() {
20+
registerHandler(QaapNamespace, defaultHandlerEnabled, NewQaapHandler)
21+
}
22+
23+
type QaapHandler struct {
24+
baseProductHandler
25+
}
26+
27+
func (h *QaapHandler) IsMetricMetaVaild(meta *metric.TcmMeta) bool {
28+
return true
29+
}
30+
31+
func (h *QaapHandler) GetNamespace() string {
32+
return QaapNamespace
33+
}
34+
35+
func (h *QaapHandler) IsMetricVaild(m *metric.TcmMetric) bool {
36+
_, ok := excludeMetricName[m.Meta.MetricName]
37+
if ok {
38+
return false
39+
}
40+
p, err := m.Meta.GetPeriod(m.Conf.StatPeriodSeconds)
41+
if err != nil {
42+
return false
43+
}
44+
if p != m.Conf.StatPeriodSeconds {
45+
return false
46+
}
47+
return true
48+
}
49+
50+
func (h *QaapHandler) GetSeries(m *metric.TcmMetric) ([]*metric.TcmSeries, error) {
51+
if m.Conf.IsIncludeOnlyInstance() {
52+
return h.GetSeriesByOnly(m)
53+
}
54+
55+
if m.Conf.IsIncludeAllInstance() {
56+
return h.GetSeriesByAll(m)
57+
}
58+
59+
if m.Conf.IsCustomQueryDimensions() {
60+
return h.GetSeriesByCustom(m)
61+
}
62+
63+
return nil, fmt.Errorf("must config all_instances or only_include_instances or custom_query_dimensions")
64+
}
65+
66+
func (h *QaapHandler) GetSeriesByOnly(m *metric.TcmMetric) ([]*metric.TcmSeries, error) {
67+
var slist []*metric.TcmSeries
68+
for _, insId := range m.Conf.OnlyIncludeInstances {
69+
ins, err := h.collector.InstanceRepo.Get(insId)
70+
if err != nil {
71+
level.Error(h.logger).Log("msg", "Instance not found", "id", insId)
72+
continue
73+
}
74+
sl, err := h.getSeriesByMetricType(m, ins)
75+
if err != nil {
76+
level.Error(h.logger).Log("msg", "Create metric series fail",
77+
"metric", m.Meta.MetricName, "instacne", ins.GetInstanceId())
78+
continue
79+
}
80+
slist = append(slist, sl...)
81+
}
82+
return slist, nil
83+
}
84+
85+
func (h *QaapHandler) GetSeriesByAll(m *metric.TcmMetric) ([]*metric.TcmSeries, error) {
86+
var slist []*metric.TcmSeries
87+
insList, err := h.collector.InstanceRepo.ListByFilters(m.Conf.InstanceFilters)
88+
if err != nil {
89+
return nil, err
90+
}
91+
for _, ins := range insList {
92+
if len(m.Conf.ExcludeInstances) != 0 && util.IsStrInList(m.Conf.ExcludeInstances, ins.GetInstanceId()) {
93+
continue
94+
}
95+
sl, err := h.getSeriesByMetricType(m, ins)
96+
if err != nil {
97+
level.Error(h.logger).Log("msg", "Create metric series fail",
98+
"metric", m.Meta.MetricName, "instacne", ins.GetInstanceId())
99+
continue
100+
}
101+
slist = append(slist, sl...)
102+
}
103+
return slist, nil
104+
}
105+
106+
func (h *QaapHandler) GetSeriesByCustom(m *metric.TcmMetric) ([]*metric.TcmSeries, error) {
107+
var slist []*metric.TcmSeries
108+
for _, ql := range m.Conf.CustomQueryDimensions {
109+
v, ok := ql[h.monitorQueryKey]
110+
if !ok {
111+
level.Error(h.logger).Log(
112+
"msg", fmt.Sprintf("not found %s in queryDimensions", h.monitorQueryKey),
113+
"ql", fmt.Sprintf("%v", ql))
114+
continue
115+
}
116+
ins, err := h.collector.InstanceRepo.Get(v)
117+
if err != nil {
118+
level.Error(h.logger).Log("msg", "Instance not found", "err", err, "id", v)
119+
continue
120+
}
121+
122+
sl, err := h.getSeriesByMetricType(m, ins)
123+
if err != nil {
124+
level.Error(h.logger).Log("msg", "Create metric series fail",
125+
"metric", m.Meta.MetricName, "instacne", ins.GetInstanceId())
126+
continue
127+
}
128+
slist = append(slist, sl...)
129+
}
130+
return slist, nil
131+
}
132+
133+
func (h *QaapHandler) getSeriesByMetricType(m *metric.TcmMetric, ins instance.TcInstance) ([]*metric.TcmSeries, error) {
134+
var dimensions []string
135+
for _, v := range m.Meta.SupportDimensions {
136+
dimensions = append(dimensions, v)
137+
}
138+
139+
if util.IsStrInList(dimensions, "listenerId") {
140+
return h.getListenerIdSeries(m, ins)
141+
} else {
142+
return h.getInstanceSeries(m, ins)
143+
}
144+
}
145+
146+
func (h *QaapHandler) getInstanceSeries(m *metric.TcmMetric, ins instance.TcInstance) ([]*metric.TcmSeries, error) {
147+
var series []*metric.TcmSeries
148+
149+
ql := map[string]string{
150+
h.monitorQueryKey: ins.GetMonitorQueryKey(),
151+
}
152+
s, err := metric.NewTcmSeries(m, ql, ins)
153+
if err != nil {
154+
return nil, err
155+
}
156+
series = append(series, s)
157+
158+
return series, nil
159+
}
160+
161+
func (h *QaapHandler) getListenerIdSeries(m *metric.TcmMetric, ins instance.TcInstance) ([]*metric.TcmSeries, error) {
162+
var series []*metric.TcmSeries
163+
meta, ok := ins.GetMeta().(*sdk.ProxyDetail)
164+
if !ok {
165+
return nil, fmt.Errorf("get instacne raw meta fail, metric=%s, instacne=%s",
166+
m.Meta.MetricName, ins.GetInstanceId())
167+
}
168+
for _, l4ListenerSet := range meta.L4ListenerSet {
169+
for _, rsSet := range l4ListenerSet.RsSet {
170+
ql := map[string]string{
171+
h.monitorQueryKey: ins.GetMonitorQueryKey(),
172+
"listenerId": *l4ListenerSet.ListenerId,
173+
"originServerInfo": *rsSet.RsInfo,
174+
"protocol": *l4ListenerSet.Protocol,
175+
}
176+
s, err := metric.NewTcmSeries(m, ql, ins)
177+
if err != nil {
178+
return nil, err
179+
}
180+
series = append(series, s)
181+
}
182+
}
183+
return series, nil
184+
}
185+
186+
func NewQaapHandler(cred common.CredentialIface, c *TcProductCollector, logger log.Logger) (handler ProductHandler, err error) {
187+
handler = &QaapHandler{
188+
baseProductHandler{
189+
monitorQueryKey: QaapInstanceidKey,
190+
collector: c,
191+
logger: logger,
192+
},
193+
}
194+
return
195+
196+
}

0 commit comments

Comments
 (0)