@@ -5,7 +5,6 @@ const request = require('../lib/request/index')
55const crypto = require ( 'crypto' )
66const cos = require ( '../lib/cos/cos' )
77const _ = require ( 'lodash' )
8- const sleep = require ( 'sleep' )
98
109const DEFAULTS = {
1110 signatureMethod : 'HmacSHA1' ,
@@ -466,7 +465,6 @@ class SlsMonitor {
466465 }
467466
468467 async describeCCMInstanceDatas ( id , instances , startTime , endTime , i , limit ) {
469-
470468 const client = new TencentCloudClient ( this . credentials , {
471469 host : 'monitor.tencentcloudapi.com' ,
472470 path : '/'
@@ -486,14 +484,15 @@ class SlsMonitor {
486484 if ( ! ( ( i + 1 ) % limit ) ) {
487485 sleep = true
488486 }
489- return new Promise ( function ( resolve , rejecte ) {
487+
488+ return new Promise ( function ( resolve ) {
490489 if ( ! sleep ) {
491490 return resolve ( client . doCloudApiRequest ( req ) )
492491 }
493492 setTimeout ( function ( ) {
494493 resolve ( client . doCloudApiRequest ( req ) )
495494 } , timeCost )
496- } ) ;
495+ } )
497496 }
498497
499498 async describeAttributes ( offset , limit ) {
@@ -524,18 +523,6 @@ class SlsMonitor {
524523 / ^ 5 x x $ / i
525524 ]
526525
527- const getMetricsResponse = ( promiseHandlers ) => {
528- return new Promise ( ( resolve , reject ) => {
529- Promise . all ( promiseHandlers )
530- . then ( ( results ) => {
531- resolve ( results )
532- } )
533- . catch ( ( error ) => {
534- reject ( error )
535- } )
536- } )
537- }
538-
539526 const filterAttributeName = function ( name , mRule ) {
540527 const len = mRule . length
541528 for ( var i = 0 ; i < len ; i ++ ) {
@@ -547,37 +534,39 @@ class SlsMonitor {
547534 }
548535
549536 const metricAttributeHash = { }
550- let requestHandlers = [ ]
551- let responses = [ ]
552- let results
553- let firstRequestFlag = true
537+ const responses = [ ]
554538 const attributes = await this . describeAttributes ( 0 , 200 )
555539 attributes . Response . Data . Data . push ( attributes . Response . Data . Data [ 10 ] )
556540
557541 let i = 0
558542 const _this = this
559543 function run ( ) {
560- if ( attributes . Response . Data . Data . length > 0 ) {
544+ if ( attributes . Response . Data . Data . length > 0 ) {
561545 const metricAttribute = attributes . Response . Data . Data . shift ( )
562546 metricAttributeHash [ metricAttribute . AttributeId ] = metricAttribute
563-
564- return _this . describeCCMInstanceDatas (
565- metricAttribute . AttributeId ,
566- announceInstance ,
567- rangeTime . rangeStart ,
568- rangeTime . rangeEnd ,
569- i ++ , apiQPSLimit
570- ) . then ( res => {
571- responses . push ( res )
547+ if ( ! filterAttributeName ( metricAttribute . AttributeName , metricsRule ) ) {
572548 return run ( )
573- } )
549+ }
550+ return _this
551+ . describeCCMInstanceDatas (
552+ metricAttribute . AttributeId ,
553+ announceInstance ,
554+ rangeTime . rangeStart ,
555+ rangeTime . rangeEnd ,
556+ i ++ ,
557+ apiQPSLimit
558+ )
559+ . then ( ( res ) => {
560+ responses . push ( res )
561+ return run ( )
562+ } )
574563 }
575564 }
576565
577566 const promiseList = Array ( Math . min ( apiQPSLimit , attributes . Response . Data . Data . length ) )
578567 . fill ( Promise . resolve ( ) )
579- . map ( promise => promise . then ( run ) )
580-
568+ . map ( ( promise ) => promise . then ( run ) )
569+
581570 return Promise . all ( promiseList ) . then ( ( ) => {
582571 this . aggrCustomDatas ( responses , period , metricAttributeHash )
583572 return responses
0 commit comments