Viewing Monitored Metrics

Viewing metrics in the console

You can view your Cloud Functions with their execution times and execution counts in the Cloud Platform Console.

Retrieving metrics from the API

This example uses the Stackdriver Monitoring Client Library for Node.js to retrieve recorded metrics for a project's Cloud Functions:

Node.js

// By default, the client will authenticate using the service account file
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
// the project specified by the GCLOUD_PROJECT environment variable. See
// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication
const Monitoring = require('@google-cloud/monitoring');

function getMetrics (callback) {
  // Instantiates a client
  const monitoring = Monitoring.v3().metricServiceApi();

  // Create two datestrings, a start and end range
  let oneWeekAgo = new Date();
  oneWeekAgo.setHours(oneWeekAgo.getHours() - (7 * 24));

  const options = {
    name: monitoring.projectPath(process.env.GCLOUD_PROJECT),
    // There is also: cloudfunctions.googleapis.com/function/execution_count
    filter: 'metric.type="cloudfunctions.googleapis.com/function/execution_times"',
    interval: {
      startTime: {
        seconds: oneWeekAgo.getTime() / 1000
      },
      endTime: {
        seconds: Date.now() / 1000
      }
    },
    view: 1
  };

  console.log('Data:');

  let error;

  // Iterate over all elements.
  monitoring.listTimeSeries(options)
    .on('error', (err) => {
      error = err;
    })
    .on('data', (element) => console.log(element))
    .on('end', () => callback(error));

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

Cloud Functions Documentation