最后,您可以在 Google Cloud 控制台的 API 配额页面中查看 API 调用和函数执行的配额指标。您可以在 Cloud Monitoring 中设置配额错误提醒,只需过滤 STATUS 指标标签值为 out of quota 的执行项即可。如需了解详情,请参阅提醒简介。
以编程方式读取指标
以下代码段展示了如何从代码读取指标。
Node.js
// Imports the Google Cloud client libraryconstmonitoring=require('@google-cloud/monitoring');// Creates a clientconstclient=newmonitoring.MetricServiceClient();asyncfunctionreadTimeSeriesData(){/** * TODO(developer): Uncomment and edit the following lines of code. */// const projectId = 'YOUR_PROJECT_ID';// const filter = 'metric.type="compute.googleapis.com/instance/cpu/utilization"';constrequest={name:client.projectPath(projectId),filter:filter,interval:{startTime:{// Limit results to the last 20 minutesseconds:Date.now()/1000-60*20,},endTime:{seconds:Date.now()/1000,},},};// Writes time series dataconst[timeSeries]=awaitclient.listTimeSeries(request);timeSeries.forEach(data=>{console.log(`${data.metric.labels.instance_name}:`);data.points.forEach(point=>{console.log(JSON.stringify(point.value));});});}readTimeSeriesData();
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2024-12-22。"],[],[]]