Viewing Monitored Metrics

Viewing metrics in the console

You can view your Cloud Functions with their execution times, execution counts, and memory usage in the Cloud Console. These metrics are also available in Stackdriver Monitoring, where you can set up custom alerting on these metrics. See the Stackdriver Monitoring documentation for more information.

You can view the metrics for API calls in the API overview page of the Cloud Console.

Finally, you can view the quota metrics for both API calls and function execution in the API quotas page of the Cloud Console. You can set up alerting on quota errors in Stackdriver Monitoring by filtering executions that have an out of quota value for the STATUS metric label. See Introduction to Alerting for more information.

Sample

Node.js

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

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

/**
 * 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));
  });
});
  • Logs emitted using console.log() have the INFO log level.
  • Logs emitted using console.error() have the ERROR log level.
  • Logs written directly to stdout or stderr do not have an associated log level.
  • Internal system messages have the DEBUG log level.