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+
1938func init () {
2039 registerHandler (QaapNamespace , defaultHandlerEnabled , NewQaapHandler )
2140}
2241
2342type QaapHandler struct {
2443 baseProductHandler
25- tcpListenersRepo instance.QaapTcInstanceTCPListenersRepository
26- udpListenersRepo instance.QaapTcInstanceUDPListenersRepository
44+ commonQaapInstanceInfoRepo instance.CommonQaapTcInstanceRepository
45+ qaapInstanceInfoRepo instance.QaapTcInstanceInfoRepository
2746}
2847
2948func (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
148174func (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+
208341func 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
0 commit comments