Last active
March 27, 2018 13:40
-
-
Save craigafinch/a2025a867eae1dfc236c6162072024a5 to your computer and use it in GitHub Desktop.
Google Stackdriver logging advanced filter to view logs across multiple Compute Engine instances by instance name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource.type="gce_instance" | |
logName="projects/my-project-name/logs/apache-error" | |
labels."compute.googleapis.com/resource_name":"-web-" | |
textPayload:"execution time" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use case: I'm a developer troubleshooting an error on a cluster of web servers, and I want to view the Apache logs from all servers, in chronological order.
The Stackdriver Logging docs only show you how to select instances by their instance ID. Finding each server's ID is a hassle, especially for a large cluster, and it is especially impractical for managed instance groups that auto-scale. This filter allows you to select log entries from an arbitrary group of servers with a partial name match. For example, assume that your servers are Google Compute Engine instances that are named [region]-[zone]-web-[id].
logName
selects the log (use auto-complete to find the exact name)labels
selects the servers by a partial name matchtextPayload
searches within each log entry (in this case, for PHP processes that exceeded the max execution time)