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.
1 2 3 4 5 6 7 8 9 10 |
#!/bin/bash apt-get update # Install Stackdriver logging curl -sSO https://dl.google.com/cloudagents/install-logging-agent.sh sudo bash install-logging-agent.sh # Install Stackdriver monitoring curl -sSO https://dl.google.com/cloudagents/install-monitoring-agent.sh sudo bash install-monitoring-agent.sh |
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
1 |
dpkg -l stackdriver-agent |
Output:
1 |
stackdriver-agent 5.5.2-382.stre amd64 Stackdriver system metrics collection daemon |
Stackdriver Logging
1 |
dpkg -l google-fluentd |
Output:
1 |
google-fluentd 1.6.0-1 amd64 Google Fluentd: A data collector for Google |
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:
1 2 3 4 5 6 7 8 9 10 |
#!/bin/bash apt-get update # Install Stackdriver logging curl -sSO https://dl.google.com/cloudagents/install-logging-agent.sh bash install-logging-agent.sh # Install Stackdriver monitoring curl -sSO https://dl.google.com/cloudagents/install-monitoring-agent.sh bash install-monitoring-agent.sh |
Execute the following command from your desktop:
1 |
gcloud compute instances add-metadata INSTANCE_NAME --metadata-from-file startup-script=startup.script |
You can also store your scripts in Google Storage:
1 |
gcloud compute instances add-metadata INSTANCE_NAME --metadata startup-script-url=gs://bucket/file |
The startup script will be executed the next time the instance reboots.
1 |
gcloud compute instances reset INSTANCE_NAME --zone=ZONE |
Installing the Monitoring Agent
I design software for enterprise-class systems and data centers. My background is 30+ years in storage (SCSI, FC, iSCSI, disk arrays, imaging) virtualization. 20+ years in identity, security, and forensics.
For the past 14+ years, I have been working in the cloud (AWS, Azure, Google, Alibaba, IBM, Oracle) designing hybrid and multi-cloud software solutions. I am an MVP/GDE with several.
February 28, 2019 at 12:23 PM
Is possible install logging-agent into other VPS infrastructure?
February 28, 2019 at 12:41 PM
Yes, you can install Stackdriver in sytems running in your datacenter, your home, AWS, etc.
This link discusses installing Stackdriver outside of GCP:
https://cloud.google.com/docs/compare/data-centers/management#logging