最後,您可以在 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"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-14 (世界標準時間)。"],[[["You can view Cloud Run function metrics like execution times, counts, and memory usage in the Google Cloud console and Cloud Monitoring."],["Metrics for API calls can be viewed on the API overview page in the Google Cloud console."],["Quota metrics for API calls and function execution are available in the API quotas page of the Google Cloud console."],["You can set up alerts for quota errors in Cloud Monitoring by filtering executions with an `out of quota` status."],["Metrics can also be read programmatically from your code using the Google Cloud client library, as shown in the provided Node.js example."]]],[]]