@@ -563,21 +563,45 @@ class SlsMonitor {
563
563
requestHandlers = [ ]
564
564
}
565
565
}
566
- if ( requestHandlers . length == 0 ) {
567
- console . log ( 'getCustomMetrics' , JSON . stringify ( responses ) )
566
+ if ( requestHandlers . length === 0 ) {
567
+ responses = this . cleanEmptyMetric ( responses , metricAttributeHash )
568
568
this . aggrCustomDatas ( responses , period , metricAttributeHash )
569
569
return responses
570
570
}
571
571
if ( ! firstRequestFlag ) {
572
572
await SlsMonitor . sleep ( 1000 )
573
573
}
574
574
results = await getMetricsResponse ( requestHandlers )
575
+ results = this . cleanEmptyMetric ( results , metricAttributeHash )
575
576
responses = responses . concat ( results )
576
- console . log ( 'getCustomMetrics' , JSON . stringify ( responses ) )
577
577
this . aggrCustomDatas ( responses , period , metricAttributeHash )
578
578
return responses
579
579
}
580
580
581
+ cleanEmptyMetric ( datas , metricAttributeHash ) {
582
+ const metrics = [ ]
583
+ const rule = / ^ ( 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 ) _ ( .* ) $ / i
584
+ for ( var i = 0 ; datas && i < datas . length ; i ++ ) {
585
+ const item = datas [ i ]
586
+ if ( item . Response . Data . length === 0 ) {
587
+ continue
588
+ }
589
+ const name = metricAttributeHash [ item . Response . Data [ 0 ] . AttributeId ] . AttributeName
590
+ if ( ! name . match ( rule ) ) {
591
+ metrics . push ( item )
592
+ continue
593
+ }
594
+ for ( var n = 0 ; n < item . Response . Data [ 0 ] . Values . length ; n ++ ) {
595
+ const val = item . Response . Data [ 0 ] . Values [ n ]
596
+ if ( val . Value !== 0 ) {
597
+ metrics . push ( item )
598
+ break
599
+ }
600
+ }
601
+ }
602
+ return metrics
603
+ }
604
+
581
605
async getScfMetrics ( region , rangeTime , period , funcName , ns , version ) {
582
606
const client = new TencentCloudClient (
583
607
this . credentials ,
0 commit comments