What Goes Into Log Analysis?
Tags: logging, programming
Published: 2020-04-14 14:58:01

I've talked here before about <a href="https://www.scalyr.com/blog/log-management-what-is-it-and-why-you-need-it/">log management in some detail</a>.&nbsp; And I've talked about log analysis in high-level terms when <a href="https://www.scalyr.com/blog/calculating-the-roi-of-log-analysis-tools/">making the case for its ROI</a>.&nbsp; But I haven't gone into a ton of detail about log analysis.&nbsp; Let's do that today.

At the surface level, this might seem a little indulgent.&nbsp; What's so hard?&nbsp; You take a log file and you analyze it, right?

Well, sure, but what does that mean, exactly?&nbsp; Do&nbsp;<em>you</em>, as a&nbsp;<em>human,</em> SSH into some server, open a gigantic server log file, and start thumbing through it like a newspaper?&nbsp; If I had to guess, I'd say probably not.&nbsp; It's going to be some interleaving of tooling, human intelligence, and heuristics.&nbsp; So let's get a little more specific about what that looks like, exactly.
<h3>Log Analysis, In the Broadest Terms</h3>
In the rest of this post, I'll explain some of the most important elements of log analysis.&nbsp; But, before I do that, I want to give you a very broad working definition.

Log analysis is the process of turning your log files into data and then making intelligent decisions based on that data.

It sounds simple in principle.&nbsp; But it's pretty involved in practice.&nbsp; Your production operations generate all sorts of logs: server logs, OS logs, application logs, etc.&nbsp; You need to take these things, gather them up, treat them as data, and make sense of them somehow.&nbsp; And it doesn't help matters any that log files have some of the most unstructured and noisy data imaginable in them.

So log analysis takes you from "unstructured and noisy" to "ready to make good decisions."&nbsp; Let's see how that happens.

<img class="aligncenter wp-image-1447" src="https://library.scalyr.com/2018/07/19175312/Magnifying_Glass_Doing_Log_Analysis.png" alt="" width="304" height="245">

<!--more-->
<h3>Collection and Aggregation</h3>
As I just mentioned, your production systems are going to produce all sorts of different logs.&nbsp; Your applications themselves produce them.&nbsp; So, too, do some of the things your applications use directly, such as databases.&nbsp; And then, of course, you have server logs and operating system logs.&nbsp; Maybe you need information from your mail server or other, more peripheral places.&nbsp; The point is, you've got a lot of sources of log data.

<img class=" wp-image-1448 alignleft" src="https://library.scalyr.com/2018/07/19175313/Pull_quote-you_can_start_to_regard_your_production_operations_as_a_more_deliberate_whole.png" alt="" width="238" height="226">So, you need to collect these different logs somehow.&nbsp; And then you need to <a href="https://www.scalyr.com/blog/what-is-log-aggregation-and-how-does-it-help-you/">aggregate them</a>, meaning you gather the collection together into a whole.

By doing this, you can start to regard your production operations not as a hodgepodge collection of unrelated systems but as a more deliberate whole.
<h3>Parsing and Semantic Interpretation</h3>
Let's say you've gathered up all of your log files and kind of smashed them together as your aggregation strategy.&nbsp; That might leave you with some, shall we say, variety.
<pre class="lang:default decode:true">111.222.333.123 HOME - [03/Mar/2017:02:44:19 -0800] "GET /some/subsite.htm HTTP/1.0" 200 198 "http://someexternalsite.com/somepage" "Mozilla/4.01 (Macintosh; I; PPC)"</pre>
<pre class="lang:default decode:true">2015-12-10 04:53:32,558 [10] ERROR WebApp [(null)] - Something happened!
</pre>
<pre class="lang:default decode:true">6/15/16,8:23:25 PM,DNS,Information,None,2,N/A,ZETA,The DNS Server has started.</pre>
As you can see, parsing these three very different styles of log entry would prove interesting.&nbsp; There seems to be a timestamp, albeit in different formats, and then a couple of the messages have kind of a general message payload.&nbsp; But beyond that, what do you do?

That's where the ideas of parsing and semantic interpretation come in.&nbsp; When you set up aggregation of the logs, you also specify different parsing algorithms, and you assign significance to the information that results.&nbsp; With some effort and intelligence, you can start weaving this into a chronological ordering of events that serve as parts of a whole.
<h3>Data Cleaning and Indexing</h3>
You're going to need to do more with the data than just extract it and assign it semantic meaning, though.&nbsp; You'll have missing entries where you need default values.&nbsp; You're going to need to apply certain rules and transformations to it.&nbsp; And you're probably going to need to filter some of the data out, frankly.&nbsp; Not every last byte capture by every last logging entity in your ecosystem is actually valuable to you.

In short, you're going to need to "clean" the data a little.

Once you've done that, you're in good shape, storage-wise.&nbsp; But you're also going to want to do what databases do: <a href="https://en.wikipedia.org/wiki/Database_index">index the data</a>.&nbsp; This means storing it in such a way to optimize information retrieval.
<h3>High-Powered Search</h3>
The reason you need to index as part of your storage and cleaning process is pretty straightforward.&nbsp; Any good log analysis paradigm is going to be predicated upon search.&nbsp; And not just any search ---&nbsp;<a href="https://www.scalyr.com/blog/searching-1tb-sec-systems-engineering-before-algorithms/"><em>really good&nbsp;</em>search</a>.

This makes sense when you think about it.&nbsp; Logs collect tons and tons of data about what your systems are doing in production.&nbsp; To make use of that data, you're going to need to search it, and the scale alone means that search has to be fast and sophisticated.&nbsp; We're not talking about looking up the customer address in an MS Access table with 100 customer records.
<h3>Visualization Capabilities</h3>
Once you have log files aggregated, parsed, stored, and indexed, you're in good shape.&nbsp; But the story doesn't end there.&nbsp; What happens with the information is just as important for analysis.

First of all, you definitely want good visualization capabilities.&nbsp; This includes relatively obvious things, like seeing graphs of traffic or dashboards warning you about spikes in errors.&nbsp; But it can also mean some <a href="https://www.scalyr.com/blog/surprising-use-cases-for-log-visualization/">relatively unusual or interesting visualization scenarios</a>.

Part of log analysis means having the capability for deep understanding of the data, and visualization is critical for that.
<h3>Analytics Capability</h3>
You've stored and visualized your data, but now you also want to be able to slice and dice it to get a deeper understanding of it.&nbsp; You're going to need analytics capability for your log analysis.

To get a little more specific, analytics involves automated assistance interpreting your data and discovering patterns in it.&nbsp; Analytics is a discipline unto itself, but it can include concerns such as the following:
<ul>
 	<li>Statistical modeling and assessing the significance of relationships.</li>
 	<li>Predictive modeling.</li>
 	<li>Pattern recognition.</li>
 	<li>Machine learning.</li>
</ul>
To zoom back out, you want to gather the data, have the ability to search it, and be able to visualize it.&nbsp; But then you also want automated assistance with combing through it, looking for trends, patterns, and generally interesting insights.
<h3>Human Intelligence</h3>
Everything I've mentioned so far should be automated in your operation.&nbsp; Of course, the automation will require setup and intervention as you go. But you shouldn't be doing this stuff yourself manually.&nbsp; In fact, you shouldn't even write your own tools for this because <a href="https://www.scalyr.com/product">good ones already exist</a>.

But none of this is complete without human intervention, so I'll close by mentioning that.&nbsp; Log analysis requires excellent tooling with sophisticated capabilities.&nbsp; But it also requires a team of smart people around it that know how to set it up, monitor it, and act on the insights that it provides.

Your systems generate an awful lot of data about what they're doing, via many log files.&nbsp; Log analysis is critical to gathering, finding, visualizing, understanding, and acting on that information.&nbsp; It can even mean the difference in keeping an edge on your competition.