Note: I have written a newer version of this article that goes much deeper into setting up Google Stackdriver on Compute Engine.

Google Compute – Stackdriver Logging – Installation, Setup & Debugging

Google Stackdriver is a very good product for monitoring and logging your compute instances on Google Cloud, AWS, Azure, Alibaba, etc.

To make sure that Stackdriver is installed on each instance, I create instance templates that contain a script in the custom metadata section to automate Stackdriver installation and setup.

An important item to remember, startup scripts are executed every time an instance starts and not just on instance creation.

In my startup script for Debian 9 Stretch, I install Google Stackdriver logging and monitoring agents.

If you are manually creating a Compute instance, copy this script into the Automation -> Startup script section when creating the instance.

To determine the currently installed versions:

Stackdriver Monitoring



Stackdriver Logging


You can add a startup-script for a running instance from the CLI. Note: this command will replace the existing startup script.

Copy the following to a local file. In this example startup.script. Modify to fit your requirements:


Execute the following command from your desktop:


You can also store your scripts in Google Storage:


The startup script will be executed the next time the instance reboots.


Installing the Logging Agent

Installing the Monitoring Agent