Skip to content

Commit 162a1d1

Browse files
authored
Merge pull request #92 from zianazhao/dev/gaap
Dev/gaap
2 parents 42c2487 + ff23178 commit 162a1d1

File tree

6 files changed

+381
-69
lines changed

6 files changed

+381
-69
lines changed

pkg/client/client.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package client
22

33
import (
4+
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/regions"
45
"net/http"
56
"net/url"
67

@@ -10,6 +11,7 @@ import (
1011
kafka "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka/v20190819"
1112
clb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb/v20180317"
1213
cmq "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cmq/v20190304"
14+
apiCommon "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
1315
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
1416
cvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312"
1517
cynosdb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb/v20190107"
@@ -305,3 +307,14 @@ func NewGAAPClient(cred common.CredentialIface, conf *config.TencentConfig) (*ga
305307
}
306308
return gaap.NewClient(cred, conf.Credential.Region, cpf)
307309
}
310+
311+
func NewGAAPCommonClient(cred common.CredentialIface, conf *config.TencentConfig) *apiCommon.Client {
312+
cpf := profile.NewClientProfile()
313+
if conf.Credential.IsInternal == true {
314+
cpf.HttpProfile.Endpoint = "gaap.internal.tencentcloudapi.com"
315+
} else {
316+
cpf.HttpProfile.Endpoint = "gaap.tencentcloudapi.com"
317+
}
318+
cpf.HttpProfile.ReqMethod = "POST"
319+
return apiCommon.NewCommonClient(cred, regions.Guangzhou, cpf)
320+
}

pkg/collector/handler_qaap.go

Lines changed: 149 additions & 16 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+
"strings"
1112
"time"
1213
)
1314

@@ -16,14 +17,32 @@ const (
1617
QaapInstanceidKey = "channelId"
1718
)
1819

20+
var (
21+
QaapDetail2GroupidMetricNames = []string{
22+
"GroupInFlow", "GroupOutFlow", "GroupInbandwidth", "GroupOutbandwidth",
23+
}
24+
QaapIpDetailMetricNames = []string{
25+
"IpConnum", "IpInbandwidth", "IpInpacket", "IpLatency", "IpOutbandwidth", "IpOutpacket", "IpPacketLoss",
26+
}
27+
QaapListenerStatMetricNames = []string{
28+
"ListenerConnum", "ListenerOutbandwidth", "ListenerInpacket", "ListenerOutpacket", "ListenerInbandwidth",
29+
}
30+
QaapListenerRsMetricNames = []string{
31+
"ListenerRsStatus",
32+
}
33+
QaapRuleRsMetricNames = []string{
34+
"RuleRsStatus",
35+
}
36+
)
37+
1938
func init() {
2039
registerHandler(QaapNamespace, defaultHandlerEnabled, NewQaapHandler)
2140
}
2241

2342
type QaapHandler struct {
2443
baseProductHandler
25-
tcpListenersRepo instance.QaapTcInstanceTCPListenersRepository
26-
udpListenersRepo instance.QaapTcInstanceUDPListenersRepository
44+
commonQaapInstanceInfoRepo instance.CommonQaapTcInstanceRepository
45+
qaapInstanceInfoRepo instance.QaapTcInstanceInfoRepository
2746
}
2847

2948
func (h *QaapHandler) IsMetricMetaVaild(meta *metric.TcmMeta) bool {
@@ -137,17 +156,23 @@ func (h *QaapHandler) getSeriesByMetricType(m *metric.TcmMetric, ins instance.Tc
137156
for _, v := range m.Meta.SupportDimensions {
138157
dimensions = append(dimensions, v)
139158
}
140-
141-
if util.IsStrInList(dimensions, "listenerId") {
142-
return h.getListenerIdSeries(m, ins)
159+
if util.IsStrInList(QaapDetail2GroupidMetricNames, m.Meta.MetricName) {
160+
return h.getQaapDetail2GroupidSeries(m, ins)
161+
} else if util.IsStrInList(QaapIpDetailMetricNames, m.Meta.MetricName) {
162+
return h.getQaapIpDetailSeries(m, ins)
163+
} else if util.IsStrInList(QaapListenerStatMetricNames, m.Meta.MetricName) {
164+
return h.getQaapListenerStatSeries(m, ins)
165+
} else if util.IsStrInList(QaapListenerRsMetricNames, m.Meta.MetricName) {
166+
return h.getQaapListenerRsSeries(m, ins)
167+
} else if util.IsStrInList(QaapRuleRsMetricNames, m.Meta.MetricName) {
168+
return h.getRuleRsSeries(m, ins)
143169
} else {
144170
return h.getInstanceSeries(m, ins)
145171
}
146172
}
147173

148174
func (h *QaapHandler) getInstanceSeries(m *metric.TcmMetric, ins instance.TcInstance) ([]*metric.TcmSeries, error) {
149175
var series []*metric.TcmSeries
150-
151176
ql := map[string]string{
152177
h.monitorQueryKey: ins.GetMonitorQueryKey(),
153178
}
@@ -160,9 +185,10 @@ func (h *QaapHandler) getInstanceSeries(m *metric.TcmMetric, ins instance.TcInst
160185
return series, nil
161186
}
162187

163-
func (h *QaapHandler) getListenerIdSeries(m *metric.TcmMetric, ins instance.TcInstance) ([]*metric.TcmSeries, error) {
188+
func (h *QaapHandler) getQaapListenerRsSeries(m *metric.TcmMetric, ins instance.TcInstance) ([]*metric.TcmSeries, error) {
164189
var series []*metric.TcmSeries
165-
tcpListenersInfos, err := h.tcpListenersRepo.GetTCPListenersInfo(ins.GetInstanceId())
190+
191+
tcpListenersInfos, err := h.qaapInstanceInfoRepo.GetTCPListenersInfo(ins.GetInstanceId())
166192
if err != nil {
167193
return nil, err
168194
}
@@ -182,7 +208,7 @@ func (h *QaapHandler) getListenerIdSeries(m *metric.TcmMetric, ins instance.TcIn
182208
series = append(series, s)
183209
}
184210
}
185-
udpListenersInfos, err := h.udpListenersRepo.GetUDPListenersInfo(ins.GetInstanceId())
211+
udpListenersInfos, err := h.qaapInstanceInfoRepo.GetUDPListenersInfo(ins.GetInstanceId())
186212
if err != nil {
187213
return nil, err
188214
}
@@ -205,28 +231,135 @@ func (h *QaapHandler) getListenerIdSeries(m *metric.TcmMetric, ins instance.TcIn
205231
return series, nil
206232
}
207233

234+
func (h *QaapHandler) getQaapDetail2GroupidSeries(m *metric.TcmMetric, ins instance.TcInstance) ([]*metric.TcmSeries, error) {
235+
var series []*metric.TcmSeries
236+
proxyGroupLists, err := h.qaapInstanceInfoRepo.GetProxyGroupList(ins.GetInstanceId())
237+
if err != nil {
238+
return nil, err
239+
}
240+
for _, proxyGroupList := range proxyGroupLists.Response.ProxyGroupList {
241+
ql := map[string]string{
242+
"GroupId": *proxyGroupList.GroupId,
243+
}
244+
s, err := metric.NewTcmSeries(m, ql, ins)
245+
if err != nil {
246+
return nil, err
247+
}
248+
series = append(series, s)
249+
}
250+
return series, nil
251+
}
252+
253+
func (h *QaapHandler) getQaapIpDetailSeries(m *metric.TcmMetric, ins instance.TcInstance) ([]*metric.TcmSeries, error) {
254+
var series []*metric.TcmSeries
255+
noneBgpIpLists, err := h.commonQaapInstanceInfoRepo.GetCommonQaapNoneBgpIpList(ins.GetInstanceId())
256+
if err != nil {
257+
return nil, err
258+
}
259+
for _, instanceSet := range noneBgpIpLists.Response.InstanceSet {
260+
ql := map[string]string{
261+
"ip": instanceSet.IP,
262+
"proxyid": instanceSet.ProxyId,
263+
"groupid": instanceSet.GroupId,
264+
"isp": strings.ToLower(instanceSet.Isp),
265+
}
266+
s, err := metric.NewTcmSeries(m, ql, ins)
267+
if err != nil {
268+
return nil, err
269+
}
270+
series = append(series, s)
271+
}
272+
return series, nil
273+
}
274+
275+
func (h *QaapHandler) getQaapListenerStatSeries(m *metric.TcmMetric, ins instance.TcInstance) ([]*metric.TcmSeries, error) {
276+
var series []*metric.TcmSeries
277+
ProxyInstances, err := h.commonQaapInstanceInfoRepo.GetCommonQaapProxyInstances(ins.GetInstanceId())
278+
if err != nil {
279+
return nil, err
280+
}
281+
for _, proxySet := range ProxyInstances.Response.ProxySet {
282+
for _, l4Listener := range proxySet.L4ListenerSet {
283+
ql := map[string]string{
284+
"instanceid": proxySet.ProxyId,
285+
"listenerid": l4Listener.ListenerId,
286+
"protocol": l4Listener.Protocol,
287+
}
288+
s, err := metric.NewTcmSeries(m, ql, ins)
289+
if err != nil {
290+
return nil, err
291+
}
292+
series = append(series, s)
293+
}
294+
for _, l7Listener := range proxySet.L7ListenerSet {
295+
ql := map[string]string{
296+
"instanceid": proxySet.ProxyId,
297+
"listenerid": l7Listener.ListenerId,
298+
"protocol": l7Listener.ForwardProtocol,
299+
}
300+
s, err := metric.NewTcmSeries(m, ql, ins)
301+
if err != nil {
302+
return nil, err
303+
}
304+
series = append(series, s)
305+
}
306+
307+
}
308+
return series, nil
309+
}
310+
func (h *QaapHandler) getRuleRsSeries(m *metric.TcmMetric, ins instance.TcInstance) ([]*metric.TcmSeries, error) {
311+
var series []*metric.TcmSeries
312+
ProxyInstances, err := h.commonQaapInstanceInfoRepo.GetCommonQaapProxyInstances(ins.GetInstanceId())
313+
if err != nil {
314+
return nil, err
315+
}
316+
for _, proxySet := range ProxyInstances.Response.ProxySet {
317+
for _, l7Listener := range proxySet.L7ListenerSet {
318+
for _, rule := range l7Listener.RuleSet {
319+
for _, rs := range rule.RsSet {
320+
ql := map[string]string{
321+
"instanceid": proxySet.ProxyId,
322+
"listenerid": l7Listener.ListenerId,
323+
"ruleid": rule.RuleId,
324+
"rs_ip": rs.RsInfo,
325+
}
326+
s, err := metric.NewTcmSeries(m, ql, ins)
327+
if err != nil {
328+
return nil, err
329+
}
330+
series = append(series, s)
331+
}
332+
333+
}
334+
335+
}
336+
337+
}
338+
return series, nil
339+
}
340+
208341
func NewQaapHandler(cred common.CredentialIface, c *TcProductCollector, logger log.Logger) (handler ProductHandler, err error) {
209-
tcpListenersRepo, err := instance.NewQaapTcInstanceTCPListenersRepository(cred, c.Conf, logger)
342+
qaapInstanceInfo, err := instance.NewQaapTcInstanceInfoRepository(cred, c.Conf, logger)
210343
if err != nil {
211344
return nil, err
212345
}
213-
relodInterval := time.Duration(c.ProductConf.RelodIntervalMinutes * int64(time.Minute))
214-
tcpListenersRepoCache := instance.NewTcGaapInstanceeTCPListenersCache(tcpListenersRepo, relodInterval, logger)
346+
reloadInterval := time.Duration(c.ProductConf.RelodIntervalMinutes * int64(time.Minute))
347+
qaapInstanceInfoCache := instance.NewTcGaapInstanceeInfosCache(qaapInstanceInfo, reloadInterval, logger)
215348

216-
udpListenersRepo, err := instance.NewQaapTcInstanceUDPListenersRepository(cred, c.Conf, logger)
349+
commonQaapInstanceInfoRepo, err := instance.NewCommonQaapTcInstanceRepository(cred, c.Conf, logger)
217350
if err != nil {
218351
return nil, err
219352
}
220-
udpListenersRepoCache := instance.NewTcGaapInstanceeUDPListenersCache(udpListenersRepo, relodInterval, logger)
353+
commonQaapInstanceInfoCache := instance.NewTcCommonGaapInstanceeInfosCache(commonQaapInstanceInfoRepo, reloadInterval, logger)
221354

222355
handler = &QaapHandler{
223356
baseProductHandler: baseProductHandler{
224357
monitorQueryKey: QaapInstanceidKey,
225358
collector: c,
226359
logger: logger,
227360
},
228-
tcpListenersRepo: tcpListenersRepoCache,
229-
udpListenersRepo: udpListenersRepoCache,
361+
commonQaapInstanceInfoRepo: commonQaapInstanceInfoCache,
362+
qaapInstanceInfoRepo: qaapInstanceInfoCache,
230363
}
231364
return
232365

pkg/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ type TencentConfig struct {
144144
RateLimit float64 `yaml:"rate_limit"`
145145
MetricQueryBatchSize int `yaml:"metric_query_batch_size"`
146146
Filename string `yaml:"filename"`
147-
CacheInterval int64 `yaml:"cache_interval"` // 单位 s
147+
CacheInterval int64 `yaml:"cache_interval"` // 单位 s
148148
IsInternational bool `yaml:"is_international"` // true 表示是国际站
149149
}
150150

0 commit comments

Comments
 (0)