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

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

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

API 呼び出しの指標は、Google Cloud コンソールの API の概要ページで確認できます。

Google Cloud コンソールの API 割り当てページで、API 呼び出しと関数実行の両方の割り当て指標を確認できます。STATUS 指標ラベルの out of quota 値が割り当て量を超えている実行をフィルタリングすることで、Cloud Monitoring で割り当てエラーのアラートを設定できます。詳細については、アラートの概要をご覧ください。

プログラムで指標を読み取る

次のスニペットは、コードから指標を読み取る方法を示しています。

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();