@@ -465,7 +465,8 @@ class SlsMonitor {
465
465
responses . push ( newP50 )
466
466
}
467
467
468
- async describeCCMInstanceDatas ( id , instances , startTime , endTime ) {
468
+ async describeCCMInstanceDatas ( id , instances , startTime , endTime , i , limit ) {
469
+
469
470
const client = new TencentCloudClient ( this . credentials , {
470
471
host : 'monitor.tencentcloudapi.com' ,
471
472
path : '/'
@@ -479,7 +480,20 @@ class SlsMonitor {
479
480
EndTime : endTime ,
480
481
TypeId : 'SCF'
481
482
}
482
- return client . doCloudApiRequest ( req )
483
+
484
+ const timeCost = 1000
485
+ let sleep = false
486
+ if ( ! ( ( i + 1 ) % limit ) ) {
487
+ sleep = true
488
+ }
489
+ return new Promise ( function ( resolve , rejecte ) {
490
+ if ( ! sleep ) {
491
+ return resolve ( client . doCloudApiRequest ( req ) )
492
+ }
493
+ setTimeout ( function ( ) {
494
+ resolve ( client . doCloudApiRequest ( req ) )
495
+ } , timeCost )
496
+ } ) ;
483
497
}
484
498
485
499
async describeAttributes ( offset , limit ) {
@@ -498,7 +512,7 @@ class SlsMonitor {
498
512
}
499
513
500
514
async getCustomMetrics ( region , announceInstance , rangeTime , period ) {
501
- const apiQPSLimit = 80
515
+ const apiQPSLimit = 100
502
516
const metricsRule = [
503
517
/ ^ ( G E T | P O S T | D E L | D E L E T E | P U T | O P T I O N S | H E A D ) _ ( [ a - z A - Z 0 - 9 ] + ) _ l a t e n c y $ / i,
504
518
/ ^ ( G E T | P O S T | D E L | D E L E T E | P U T | O P T I O N S | H E A D ) _ ( [ a - z A - Z 0 - 9 ] + ) _ ( \d + ) $ / i,
@@ -538,45 +552,36 @@ class SlsMonitor {
538
552
let results
539
553
let firstRequestFlag = true
540
554
const attributes = await this . describeAttributes ( 0 , 200 )
541
- for ( var i = 0 ; i < attributes . Response . Data . TotalCount ; i ++ ) {
542
- const metricAttribute = attributes . Response . Data . Data [ i ]
555
+ attributes . Response . Data . Data . push ( attributes . Response . Data . Data [ 10 ] )
543
556
544
- if ( ! filterAttributeName ( metricAttribute . AttributeName , metricsRule ) ) {
545
- continue
546
- }
547
- metricAttributeHash [ metricAttribute . AttributeId ] = metricAttribute
548
- requestHandlers . push (
549
- this . describeCCMInstanceDatas (
557
+ let i = 0
558
+ const _this = this
559
+ function run ( ) {
560
+ if ( attributes . Response . Data . Data . length > 0 ) {
561
+ const metricAttribute = attributes . Response . Data . Data . shift ( )
562
+ metricAttributeHash [ metricAttribute . AttributeId ] = metricAttribute
563
+
564
+ return _this . describeCCMInstanceDatas (
550
565
metricAttribute . AttributeId ,
551
566
announceInstance ,
552
567
rangeTime . rangeStart ,
553
- rangeTime . rangeEnd
554
- )
555
- )
556
-
557
- if ( ! ( ( i + 1 ) % apiQPSLimit ) ) {
558
- if ( i + 1 != apiQPSLimit ) {
559
- sleep . sleep ( 1 )
560
- }
561
- firstRequestFlag = false
562
- results = await getMetricsResponse ( requestHandlers )
563
- responses = responses . concat ( results )
564
- requestHandlers = [ ]
568
+ rangeTime . rangeEnd ,
569
+ i ++ , apiQPSLimit
570
+ ) . then ( res => {
571
+ responses . push ( res )
572
+ return run ( )
573
+ } )
565
574
}
566
575
}
567
- if ( requestHandlers . length === 0 ) {
568
- responses = this . cleanEmptyMetric ( responses , metricAttributeHash )
576
+
577
+ const promiseList = Array ( Math . min ( apiQPSLimit , attributes . Response . Data . Data . length ) )
578
+ . fill ( Promise . resolve ( ) )
579
+ . map ( promise => promise . then ( run ) )
580
+
581
+ return Promise . all ( promiseList ) . then ( ( ) => {
569
582
this . aggrCustomDatas ( responses , period , metricAttributeHash )
570
583
return responses
571
- }
572
- if ( ! firstRequestFlag ) {
573
- sleep . sleep ( 1 )
574
- }
575
- results = await getMetricsResponse ( requestHandlers )
576
- results = this . cleanEmptyMetric ( results , metricAttributeHash )
577
- responses = responses . concat ( results )
578
- this . aggrCustomDatas ( responses , period , metricAttributeHash )
579
- return responses
584
+ } )
580
585
}
581
586
582
587
cleanEmptyMetric ( datas , metricAttributeHash ) {
0 commit comments