측정항목 및 할당량 보기

Console에서 측정항목 보기

Google Cloud Console에서 실행 시간, 실행 횟수, 메모리 사용량과 함께 Cloud Functions를 확인할 수 있습니다. 이러한 측정항목은 Cloud Monitoring을 통해서도 확인할 수 있으며 해당 측정항목에 커스텀 알림을 설정할 수 있습니다. 자세한 내용은 Cloud Monitoring 문서를 참조하세요.

Google Cloud Console의 API 개요 페이지에서 API 호출의 측정항목을 확인할 수 있습니다.

마지막으로 Google Cloud Console의 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();