查看指標和配額

在主控台中查看指標

您可以在Google Cloud 控制台查看 Cloud Run 函式,瞭解執行時間、執行次數和記憶體用量。這些指標也適用於 Cloud Monitoring,您可以在其中設定這些指標的自訂快訊。詳情請參閱 Cloud Monitoring 說明文件

您可以在 Google Cloud 主控台的「API 總覽」頁面查看 API 呼叫的指標。

最後,您可以在 Google Cloud 主控台的「API 配額」頁面中,查看 API 呼叫和函式執行作業的配額指標。您可以在 Cloud Monitoring 中設定配額錯誤快訊,方法是篩除 STATUS 指標標籤具有 out of quota 值的執行作業。詳情請參閱快訊簡介

以程式輔助方式讀取指標

以下程式碼片段說明如何從程式碼讀取指標。

Node.js

// Imports the Google Cloud client library
const monitoring = require('@google-cloud/monitoring');

// Creates a client
const client = new monitoring.MetricServiceClient();

async function readTimeSeriesData() {
  /**
   * 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"';

  const request = {
    name: client.projectPath(projectId),
    filter: filter,
    interval: {
      startTime: {
        // Limit results to the last 20 minutes
        seconds: Date.now() / 1000 - 60 * 20,
      },
      endTime: {
        seconds: Date.now() / 1000,
      },
    },
  };

  // Writes time series data
  const [timeSeries] = await client.listTimeSeries(request);
  timeSeries.forEach(data => {
    console.log(`${data.metric.labels.instance_name}:`);
    data.points.forEach(point => {
      console.log(JSON.stringify(point.value));
    });
  });
}
readTimeSeriesData();