指標と割り当てを表示する

コンソールで指標を表示する

Google Cloud コンソールで、実行時間、実行回数、メモリ使用量などの Cloud Run functions の情報を表示できます。これらの指標は、Cloud Monitoring でも確認でき、これらの指標に対してカスタム アラートを設定できます。詳細については、Cloud Monitoring のドキュメントをご覧ください。

API 呼び出しの指標は、 Google Cloud コンソールの 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();