What Is Whitebox Monitoring? Everything You Need to Know
Tags: monitoring
Published: 2020-03-10 16:11:12

<!-- wp:paragraph -->
<p>When I first heard about whitebox monitoring, I thought I knew what it was just by name. But like many software terms, it's easy to conflate one thing for another. It's also easy to jump to conclusions too quickly and think you know everything about a term. Whitebox monitoring is a very valuable tool in our DevOps toolbox. Because of this, it's prudent for us to ensure we fully understand what it is and how to use it.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>We're going to cover quite a bit about whitebox monitoring: why it's valuable, how it differs from <a href="https://www.scalyr.com/blog/black-box-monitoring-track-opaque-systems/">blackbox monitoring</a>, and how such monitoring is implemented in a system.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5064,"align":"center"} -->
<div class="wp-block-image"><figure class="aligncenter"><img src="https://library.scalyr.com/2019/08/09161546/An_open_white_box_signifying_whitebox_monitoring.png" alt="An open white box signifying whitebox monitoring" class="wp-image-5064"/></figure></div>
<!-- /wp:image -->

<!-- wp:more -->
<!--more-->
<!-- /wp:more -->

<!-- wp:heading -->
<h2>Blackbox vs. Whitebox Monitoring</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Whitebox has often come with its counterpart, blackbox, through many variations. One famous example is <a href="http://softwaretestingfundamentals.com/black-box-testing/">blackbox</a> vs.<a href="http://softwaretestingfundamentals.com/white-box-testing/"> whitebox testing</a>. I'll quickly cover the difference between blackbox and whitebox monitoring.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Blackbox Monitoring</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The name blackbox invokes a feeling of mystery. Black is opaque; we cannot see through it. In the same way, we can't see into the system we're monitoring. Take a series of houses on a street, for example. From the outside, we can know a few things. We can see if anyone is home by whether the lights are on or how many cars are in the driveway. If we read the gas meter, we know how much gas they use per month. It's the same for the water meter and water usage.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>But we don't know what happens inside. We have no idea what sort of interesting celebrations, arguments, or hobbies could be happening in these houses. It's the same for monitoring. I can monitor the traffic and responses of the software. I can measure the CPU and memory utilization. But in blackbox monitoring, I have no idea what's happening inside these requests. I don't know what database calls it's making or what sort of fancy rules it applies to the data.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Whitebox Monitoring</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Whitebox monitoring is, of course, the opposite of blackbox. The idea of a whitebox invokes a feeling of transparency, though maybe clearbox would be a better name. Imagine a household with a swear jar, a calendar of events, or a weekly menu. I can record and watch these things change, as long as I have a window to see inside. Whitebox monitoring is the same. It's the act of putting windows into our code and showing the outside world, usually our developers, what's happening inside.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>What Do I Get out of Whitebox Monitoring?</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>If you know exactly what's happening inside your application, you can easily answer questions that may pop up from time to time. Back to our household, what if we wanted to know how often they eat fish? Well, we just need to peek through the window and record their menu. We keep doing this every week, and we can get an average for how much fish they eat per month.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>With software, having such things gives us some key benefits in two categories: operations and product insights.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Operations</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Operational whitebox monitoring helps us keep our system alive and healthy. It also helps us keep the risk low when trying new architectures and techniques. It does this by giving us quick feedback once we've released something. For example, if we see traffic is slowing down for one of our endpoints, we need a way to drill down and see what internal method is causing the bottleneck. Monitoring database queries is a fantastic example of a whitebox monitor. It gives us insight into a key part of our system that is often the cause of slowdowns. Operational whitebox monitoring helps us build a thing right.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5065,"align":"center"} -->
<div class="wp-block-image"><figure class="aligncenter"><img src="https://library.scalyr.com/2019/08/09162405/whitebox_pull_quote_1.png" alt="" class="wp-image-5065"/></figure></div>
<!-- /wp:image -->

<!-- wp:heading {"level":3} -->
<h3>Product Insights</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>While operational monitoring helps us build a thing right, product insight monitors help us build the right thing. They help us answer the question, are we making customers happy? One popular version of this monitoring is shopping cart abandonment. It's common in e-commerce to see how often customers put things inside a shopping cart, but never place an order. By looking at what they put in, or where they clicked next, we can improve our systems to encourage customers to place more orders.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>How Do I Wire up Whitebox Monitoring?</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Armed with an understanding of what whitebox monitoring is, the question naturally pops up on how to implement it. This is extremely sensitive to the languages and frameworks you're using, but I'll describe some important characteristics here.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Monitoring Categories</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>There are two main categories of whitebox monitoring that affect how we implement them: event-centric monitors and time-series data.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Event-Centric Monitors</h4>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Event-centric monitoring is where we report out interesting events from our system. For our household, this could be tallying on a chalkboard every time a family has an argument. We may record what room the argument was in, how many decibels the speaking reached, and how long it lasted. We don't know up front how the data will be used—we just know it's interesting. With software, this could be things like what web requests occurred, whether they were successful, how many database calls they made, and how long they took.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Event-centric data is great when we need to <a href="https://www.scalyr.com/blog/five-reasons-need-log-monitoring/">answer questions</a> that we don't know we have ahead of time. Oftentimes production incidents catch us by surprise, and we need answers right now! Event-centric data can give us these answers.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Time-Series Data</h4>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Time-series data is information that is aggregated over a time period. For our households, it might be the number of dishes used per week or pounds of food consumed per day. In software, this can be things like the number of requests per minute or average latency per hour. The key to time-series data is that it's aggregated inside the application before being sent through our window. This makes it ready to be shown in graphs so that we can see trends over time.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Reporting</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The cost of whitebox monitoring is that it must be built into the app as a first-class concept. I need the application itself to tell me what's going on inside it. In a household, this would be equivalent to the family telling me what they ate that night or giving me a key to their house. This usually consists of a reporter component that blasts out the data to somewhere else. It also involves some sort of instrumentation that plugs into our workflow life cycle. Many frameworks give us extensions to plug in such instrumentation. Sometimes we have to do it ourselves via things like <a href="https://en.wikipedia.org/wiki/Aspect-oriented_programming">aspect-oriented programming</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Key Traits</h4>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>However we report, here are some key traits. Most reporters, especially event-centric ones, should be asynchronous. This is because we don't want the time it takes to report out the data to interfere with our responsiveness to customers. We should also ensure its failures are isolated. We don't want a failed log event to stop up someone trying to make a payment!</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Storage</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Once we have a reporter, we need something to report to. Sometimes we report to multiple places. We should have a persistent store somewhere that we can send this data to. As a note, this place should exist outside our production system. It'd be quite a pain to troubleshoot when production is down if your monitoring goes down with it!</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>For the record, Scalyr offers both storage and reporters as part of its product. Other offerings may focus solely on one or the other. Spring Sleuth, for example, only handles reporting and instrumentation. It leaves where to put it up to you.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Viewing Monitors</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Now that we have the data stored, we likely want to see it and see it frequently. We have a few options for that.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Dashboard</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The almighty dashboard is the most popular way for visualizing monitors. There's nothing quite like the feeling of confidence a trending graph gives. Dashboards excel at giving you a pulse of the system at a glance. Healthy ones let you see patterns and detect abnormalities. They should be uncluttered, focusing only on a few things. The flip side to this is that they should easily let you drill down at runtime into more specific data. This will make it easier to diagnose problems quickly.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Search</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Search is the <a href="https://www.scalyr.com/blog/log-management-need/">ultimate ability to answer questions</a> you didn't know you would need to ask in advance. Searchable storage works very well with event-centric monitoring. It gives you the full flexibility to ask very specific questions about your system. No amount of dashboards can always tell you all the information about a bug, but searching can.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5066,"align":"center"} -->
<div class="wp-block-image"><figure class="aligncenter"><img src="https://library.scalyr.com/2019/08/09162441/whitebox_pull_quote_2.png" alt="" class="wp-image-5066"/></figure></div>
<!-- /wp:image -->

<!-- wp:heading {"level":3} -->
<h3>Alerts</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Alerts are when the system tells you when something is going on, as opposed to the other way around. These are great for letting you relax, and not having to spend time every day looking through graphs or logs. They let the system do the hard work of detecting abnormalities. On the other hand, they can easily get out of hand. I have seen badly managed alerts that can ping you every five minutes for the next four hours while your system is down.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>What to Monitor</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Once we get whitebox monitoring up and running, we want to leverage it effectively. I'll be using a couple of ideas from Google's <a href="https://landing.google.com/sre/books/"><em>Site Reliability Engineering</em> book</a> to touch on this.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Service Level Indices</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Service level indices are the baseline of what's happening in your system today. They're useful to get a pulse on how your system works. You may find some surprising results. What things you want to index are usually based on what service level objectives you have.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Service Level Objectives</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>This is one of the keys to all monitoring. Monitoring is by no means a purely technical endeavor. A team should have objectives on how to make its customers happy. If your system deals with payments it could be "we want payments 20% more likely to succeed without a snag." In this case, let's measure the rate of successful vs. failed payment transactions. Service level objectives are something for which you should intimately collaborate with all of your stakeholders. You all are responsible for these, and they'll help guide what monitors you plug in.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Conclusion</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>In a household, there are many interesting things that happen inside. We have to explicitly create systems that let us measure those things, like swear jars. In the same way, software systems are full of valuable details that let us peer into what's happening. Building whitebox monitoring into our app will let us turn these details into valuable insights. There are many tools, like Scalyr, that help us implement this quickly, leaving us time to figure out what service level objectives we want to measure.</p>