<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Logging on shocksolution.com</title><link>https://shocksolution.com/tags/logging/</link><description>Recent content in Logging on shocksolution.com</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Tue, 08 Sep 2020 16:31:08 +0000</lastBuildDate><atom:link href="https://shocksolution.com/tags/logging/index.xml" rel="self" type="application/rss+xml"/><item><title>Alert Policies for Log Metrics on Google Stackdriver Monitoring</title><link>https://shocksolution.com/posts/alert-policies-for-log-metrics-on-google-stackdriver-monitoring/</link><pubDate>Tue, 08 Sep 2020 16:31:08 +0000</pubDate><guid>https://shocksolution.com/posts/alert-policies-for-log-metrics-on-google-stackdriver-monitoring/</guid><description>&lt;p&gt;Google Cloud Operations, formerly known as Stackdriver Logging and Monitoring, can be very confusing to set up. It&amp;rsquo;s easy to monitor something simple, but more complex cases quickly get confusing. One of the more flexible but confusing types of alert policies in Stackdriver Monitoring is a Logs-Based Metrics policy, which gives you the ability to monitor entries in Stackdriver Logging.&lt;/p&gt;&#10;&lt;h2 id="create-a-logs-based-metric"&gt;Create a Logs-Based Metric&lt;/h2&gt;&#10;&lt;p&gt;The first step is to go to Stackdriver (Operations) Logging and create a user-defined metric. Go to the Logs Viewer and build a query to return the subset of log entries that you want to monitor (the details of query building are beyond the scope of this article). As of Sept. 2020, I highly recommend enabling the Preview Mode of the Logs Viewer interface, which is much better at guiding you through the process of building the query. If you must use the Classic interface, click the little black arrow at the right side of the filter box, near the top of the Logs Viewer screen. Select &amp;ldquo;Convert to advanced filter&amp;rdquo; from the drop-down menu, and &lt;a href="https://cloud.google.com/logging/docs/view/advanced-queries"&gt;create an advanced filter using the query language&lt;/a&gt;. Once you have created the right filter (query) that selects the log entries that you want to monitor, proceed to the next step:&lt;/p&gt;</description></item><item><title>Viewing logs for a cluster of instances on Google Stackdriver Logging</title><link>https://shocksolution.com/posts/viewing-logs-for-a-cluster-of-instances-on-google-stackdriver-logging/</link><pubDate>Tue, 27 Mar 2018 14:01:51 +0000</pubDate><guid>https://shocksolution.com/posts/viewing-logs-for-a-cluster-of-instances-on-google-stackdriver-logging/</guid><description>&lt;p&gt;StackDriver Logging is a great feature of Google Compute Engine (GCE). You pretty much need a centralized logging solution if you are taking maximum advantage of the features offered by GCE. For example, most production applications will run on a cluster of web servers. If you set up the cluster as a managed instance group on GCE, Google can auto-scale the size of the cluster based on traffic. The challenge is that it&amp;rsquo;s much  harder to troubleshoot errors across a cluster. The requests that caused the error could be spread across any number of servers, with randomly assigned names. If load drops and the server pool contracts, you will entirely lose any log data on a server that&amp;rsquo;s auto-deleted. StackDriver Logging is the answer to this problem. Configure all servers to send all logs to StackDriver, and you can view all of your web server logs in one interface, with the entries in chronological order. &lt;a href="https://gist.github.com/craigafinch/a2025a867eae1dfc236c6162072024a5"&gt;View StackDriver Advanced Filter as a Gist on GitHub&lt;/a&gt; The problem is that the Stackdriver docs only explain how to select an instance by the instance ID, which is a random-looking string that is not visible in the Console. Further, if you have a large cluster of disposable servers, you would have to look up the ID for every instance. If an instance was deleted when the cluster was auto-scaled, you won&amp;rsquo;t even know what to look up. Therefore, it&amp;rsquo;s much better to search for the logs based on a human-readable server name. For example, assume that your servers are Google Compute Engine instances that are named [region]-[zone]-web-[id]. Here&amp;rsquo;s a filter to match on that naming convention: [sourcecode language=&amp;ldquo;plain&amp;rdquo;] resource.type=&amp;ldquo;gce_instance&amp;rdquo; logName=&amp;ldquo;projects/my-project-name/logs/apache-error&amp;rdquo; labels.&amp;ldquo;compute.googleapis.com/resource_name&amp;rdquo;:&amp;quot;-web-&amp;quot; textPayload:&amp;ldquo;execution time&amp;rdquo; [/sourcecode]&lt;/p&gt;</description></item></channel></rss>