Skip to content

Commit 591fb8e

Browse files
committed
feat: add apigw metrics api
1 parent c9ba331 commit 591fb8e

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "tencent-cloud-sdk",
33
"description": "Tencent Cloud SDK For Serverless Framework",
4-
"version": "0.1.8",
4+
"version": "0.2.0",
55
"main": "./index.js",
66
"publishConfig": {
77
"access": "public"

src/client.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,60 @@ class SlsMonitor {
825825
}
826826
}
827827

828+
async getApigwMetrics(region, rangeTime, period, serviceId, env) {
829+
const metricName = ['NumOfReq', 'ResponseTime']
830+
const client = new TencentCloudClient(
831+
this.credentials,
832+
{
833+
host: 'monitor.tencentcloudapi.com',
834+
path: '/'
835+
},
836+
{
837+
region: region
838+
}
839+
)
840+
841+
const req = {
842+
Action: 'GetMonitorData',
843+
Version: '2018-07-24',
844+
Namespace: 'QCE/APIGATEWAY',
845+
Period: period,
846+
StartTime: rangeTime.rangeStart,
847+
EndTime: rangeTime.rangeEnd
848+
}
849+
850+
const requestHandlers = []
851+
852+
for (let i = 0; i < metricName.length; i++) {
853+
req.MetricName = metricName[i]
854+
req.Instances = [
855+
{
856+
Dimensions: [
857+
{
858+
Name: 'environmentName',
859+
Value: env || 'release'
860+
},
861+
{
862+
Name: 'serviceId',
863+
Value: serviceId
864+
}
865+
]
866+
}
867+
]
868+
requestHandlers.push(client.doCloudApiRequest(req))
869+
}
870+
871+
return new Promise((resolve, reject) => {
872+
Promise.all(requestHandlers)
873+
.then((results) => {
874+
resolve(results)
875+
})
876+
.catch((error) => {
877+
reject(error)
878+
})
879+
})
880+
}
881+
828882
async createService() {
829883
const client = new TencentCloudClient(this.credentials, {
830884
host: 'monitor.tencentcloudapi.com',

0 commit comments

Comments
 (0)