Google Cloud Functions Tutorial : Monitoring Cloud Functions

Romin Irani
Romin Irani’s Blog
2 min readApr 24, 2018

This is part of a Google Cloud Functions Tutorial Series. Check out the series for all the articles.

In this post, we will take a look at how you can monitor the execution of your Cloud Functions and view other metrics that are provided to you to understand the performance of your Cloud Functions.

Metrics of Serverless

But first up, let us try to understand some metrics around Cloud Functions that you should definitely be keeping a track of. They are:

  • Invocation Time
  • Latency
  • Errors
  • Memory Usage
  • CPU Usage

These metrics are provided to you by default if you visit the specific Function details page. It is available in the Dashboard page. A view of the same from my cloud console is shown below:

Just use the dropdown to view the different metrics for your Cloud Function.

Google Stackdriver

In addition to the above metrics, Google Stackdriver is a useful service that is well integrated with the Google Cloud Platform services. It has support for Google Cloud Functions too.

Using Google Stackdriver, we can:

  • View the monitored metrics and also setup Alerts if needed
  • View the Error and information logs that are generated by our function executions.

Writing to Log

Cloud Functions can use the console.log and console.error statements to report the errors to Stackdriver.

Viewing the Logs

To view the logs, you can visit Stackdriver Logging from the Cloud Console. An example screenshot is shown below:

Notice that you can filter the logs via Cloud Function and view the different log levels (Errors, Info, etc).

Reporting Errors

To report error you can use the console.error method. An example of how to do that in your code is shown below:

console.error(new Error(‘message’));

Few points to note about Errors (from official documentation):

  • Errors also appear in Stackdriver Error Reporting when your function produces an uncaught error, or if you explicitly throw an object of type Error.
  • Stackdriver error will not be emitted if you return normally from your function via the res.send (Foreground functions) or callback methods (Background functions).
  • They will also not be reported if you log or throw a non Error object.

This completes our post on understanding metrics around your Cloud Functions and reporting/logging messages + errors in your code and viewing them in Stackdriver Logging.

Proceed to the next part : Using gcloud Tool or go back to the Google Cloud Functions Tutorial Home Page.

--

--

Romin Irani
Romin Irani’s Blog

My passion is to help developers succeed. ¯\_(ツ)_/¯