@@ -127,6 +127,18 @@ class TagClient {
127
127
}
128
128
}
129
129
130
+ class TcbClient {
131
+ constructor ( credentials = { } ) {
132
+ this . credentials = credentials
133
+ }
134
+ async request ( data ) {
135
+ return await new TencentCloudClient ( this . credentials , {
136
+ host : 'tcb.tencentcloudapi.com' ,
137
+ path : '/'
138
+ } ) . doCloudApiRequest ( data )
139
+ }
140
+ }
141
+
130
142
class ApigwClient {
131
143
constructor ( credentials = { } ) {
132
144
this . credentials = credentials
@@ -151,6 +163,18 @@ class CamClient {
151
163
}
152
164
}
153
165
166
+ class CamV2Client {
167
+ constructor ( credentials = { } ) {
168
+ this . credentials = credentials
169
+ }
170
+ async request ( data ) {
171
+ return await new TencentCloudClient ( this . credentials , {
172
+ host : 'cam.api.qcloud.com' ,
173
+ path : '/v2/index.php'
174
+ } ) . doCloudApiRequest ( data )
175
+ }
176
+ }
177
+
154
178
class CnsClient {
155
179
constructor ( credentials = { } ) {
156
180
this . credentials = credentials
@@ -182,23 +206,6 @@ class SlsMonitor {
182
206
this . credentials = credentials
183
207
}
184
208
185
- static rfc3339 ( t ) {
186
- const year = t . getFullYear ( )
187
- const month = t . getMonth ( ) + 1
188
- const day = t . getDate ( )
189
- const hours = t . getHours ( )
190
- const minutes = t . getMinutes ( )
191
- const sec = t . getSeconds ( )
192
-
193
- const offset = Math . abs ( t . getTimezoneOffset ( ) )
194
- const offsetH = Math . floor ( offset / 60 )
195
- const offsetM = offset % 60
196
-
197
- return util . format ( '%d-%s-%sT%s:%s:%s+%s:%s' , year , month . toString ( ) . padStart ( 2 , 0 ) ,
198
- day . toString ( ) . padStart ( 2 , 0 ) , hours . toString ( ) . padStart ( 2 , 0 ) , minutes . toString ( ) . padStart ( 2 , 0 ) , sec . toString ( ) . padStart ( 2 , 0 ) , offsetH . toString ( ) . padStart ( 2 , 0 ) ,
199
- offsetM . toString ( ) . padStart ( 2 , 0 ) )
200
- }
201
-
202
209
async request ( data ) {
203
210
return await new TencentCloudClient ( this . credentials , {
204
211
host : 'monitor.tencentcloudapi.com' ,
@@ -231,7 +238,7 @@ class SlsMonitor {
231
238
}
232
239
}
233
240
234
- async getScfMetrics ( region , rangeTime , funcName , ns , version ) {
241
+ async getScfMetrics ( region , rangeTime , period , funcName , ns , version ) {
235
242
const client = new TencentCloudClient ( this . credentials , {
236
243
host : 'monitor.tencentcloudapi.com' ,
237
244
path : '/'
@@ -240,32 +247,17 @@ class SlsMonitor {
240
247
Action : 'GetMonitorData' ,
241
248
Version : '2018-07-24' ,
242
249
}
243
- if ( rangeTime . rangeEnd <= rangeTime . rangeStart ) {
244
- throw new Error ( 'The rangeStart provided is after the rangeEnd' )
245
- }
246
250
247
251
const metrics = [ 'Duration' , 'Invocation' , 'Error' , 'ConcurrentExecutions' , 'ConfigMem' , 'FunctionErrorPercentage' , 'Http2xx' , 'Http432' , 'Http433' , 'Http434' , 'Http4xx' , 'Mem' , 'MemDuration' , 'Syserr' ] ;
248
252
249
- const diffMinutes = ( rangeTime . rangeEnd - rangeTime . rangeStart ) / 1000 / 60
250
- let period ,
251
- aggrFlag = false
252
-
253
- if ( diffMinutes <= 16 ) {
254
- // 16 mins
255
- period = 60 // 1 min
256
- } else if ( diffMinutes <= 61 ) {
257
- // 1 hour
258
- period = 300 // 5 mins
259
- } else if ( diffMinutes <= 1500 ) {
260
- // 24 hours
261
- period = 3600 // hour
262
- } else {
253
+ let aggrFlag = false
254
+ if ( period == 86400 ) {
263
255
period = 3600 // day
264
256
aggrFlag = true
265
257
}
266
258
const result = {
267
- rangeStart : SlsMonitor . rfc3339 ( rangeTime . rangeStart ) ,
268
- rangeEnd : SlsMonitor . rfc3339 ( rangeTime . rangeEnd ) ,
259
+ rangeStart : rangeTime . rangeStart ,
260
+ rangeEnd : rangeTime . rangeEnd ,
269
261
metrics : [ ]
270
262
}
271
263
@@ -274,8 +266,8 @@ class SlsMonitor {
274
266
req . Namespace = 'qce/scf_v2' ;
275
267
req . MetricName = metrics [ i ] ;
276
268
req . Period = period ;
277
- req . StartTime = SlsMonitor . rfc3339 ( rangeTime . rangeStart ) ;
278
- req . EndTime = SlsMonitor . rfc3339 ( rangeTime . rangeEnd ) ;
269
+ req . StartTime = rangeTime . rangeStart ;
270
+ req . EndTime = rangeTime . rangeEnd ;
279
271
req . Instances = [ {
280
272
Dimensions : [
281
273
{
@@ -311,9 +303,11 @@ module.exports = {
311
303
ScfClient,
312
304
TagClient,
313
305
CamClient,
306
+ CamV2Client,
314
307
CnsClient,
315
308
ApigwClient,
316
309
DomainClient,
317
310
CosClient,
318
- SlsMonitor
311
+ SlsMonitor,
312
+ TcbClient
319
313
}
0 commit comments