Skip to content

Instantly share code, notes, and snippets.

@craigafinch
Last active March 27, 2018 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigafinch/a2025a867eae1dfc236c6162072024a5 to your computer and use it in GitHub Desktop.
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
resource.type="gce_instance"
logName="projects/my-project-name/logs/apache-error"
labels."compute.googleapis.com/resource_name":"-web-"
textPayload:"execution time"
@craigafinch
Copy link
Author

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 match
  • textPayload searches within each log entry (in this case, for PHP processes that exceeded the max execution time)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment