Application database monitoring:
the middle way

A different way to look into your application's database activity

Sometimes you just need to know what a database client is doing in the database. You might be:

  • debugging an application and trying to figure out if its database interactions are a problem

  • analyzing the performance of a serverless function to determine if some queries take too long

  • testing an application and making sure its database interactions are as expected

  • auditing a system to make sure it does not do anything funny in the database

  • reverse engineering an application

  • you get the picture -- the list is endless

By database client, we mean anything that talks directly to a database: it might be a Java application running in an app server, a report writer, Excel, a web app written in PHP, a lambda function in the cloud, and so on.

Whatever the reason, getting visibility into a client's database interactions is hugely helpful to understand that client's behavior.

Generally speaking, there are two common approaches: server-based and client-based.

There is also a third option, which so far remains relatively unexplored: monitoring database connections. This is the middle way: it focuses neither on the database servers, nor on the database clients, but rather on the connection between them.

Let's examine the advantages and disadvantages of current solutions, and see what this third way brings to the table.


Server-side monitoring

Most enterprise databases have built-in monitoring capabilities. If you have admin-level access to the database, this type of monitoring might be a good solution, but it may not always be easy to use if there is more than one client accessing the database.

Server-side monitoring is preferred by people who view the world mostly from the perspective of database, since this type of monitoring gives you full access to everything happening in the database server: CPU and memory, network and disk usage, deadlocks, etc...

The main disadvantages of this type of solution are:

  • it requires privileged access to the database

  • for cloud databases, you are often stuck with whatever is provided by the cloud vendor

  • you have visibility to all requests from all clients, which can be overwhelming, and might be a security problem


Client-side monitoring

The solutions focusing on the database clients require you to install an agent in the client(s). This can take the form of a library or module, or perhaps a replacement driver library that intercepts all database calls.

For instance, for a Java application, the agent might be a jar file that gets loaded with a -javaagent option on the Java command line, or it might be a substitute JDBC library.

For a JavaScript application, the agent is usually installed as an additional module that must then activated by making a call -- which requires you to make a small change to your application.

Every language does this differently, and how much you need to change the client depends on how the monitoring vendor implements the agent.

Client monitoring is of course preferred by people who care more about the database client's perspective, such as application developers and testers. It allows you to focus on one specific client and see exactly what that client is doing, what requests it sends, what responses it gets, how long it takes from the client's point of view, and so on. Most solutions do a lot more than just monitoring database interactions.

There are, however, downsides to this type of monitoring:

  • it requires you to make some changes to the client(s)

  • ... which may not be an option if you don't control the client (third-party app, no longer maintained, etc...)

  • it's usually not an option if the client's language or platform is not supported by the monitoring solution

  • it can be inconvenient if you need to monitor multiple clients, since you need to install the agent in each client

Proxy-based monitoring: the middle way

There is a third option: monitoring the connection between clients and servers using a database proxy.

Instead of connecting directly to the database, the clients connect to the proxy, which forwards all requests and responses between the clients and the servers, and reports this activity to the monitoring service.

The proxy works at the wire protocol level: it behaves exactly like the database server, so there is no way for the client to know that it is not in fact talking directly to the database server.

The main advantage of this approach is that it requires no changes to either the database clients or the database servers, and can therefore work in any environment, for any client in any language. The only requirement is that the client should connect to the proxy instead of the database, which can usually be accomplished by changing a configuration parameter, a data source definition, or sometimes a network setting.

This is especially useful when dealing with third-party applications that you do not control, or with older applications that are no longer maintained. In these situations, making any change to the applications is often a daunting prospect. By comparison, directing the client to connect to the proxy instead of the database is normally trivial.

Proxy-based monitoring can also be a big help for clients written in a language that is not supported by the monitoring system.

For instance, New Relic has application performance monitoring libraries for C, Java, JavaScript, Go, Ruby, .NET, PHP and Python. If your client is written in another language, you may be out of luck.

Proxy-based monitoring can easily be put in place by application developers and testers, without needing the collaboration of the database owners. One proxy can be used for many clients, which is helpful when you need to monitor a suite of applications.

Advantages of the proxy approach

  • Requires no changes to the database clients or to the database servers

  • Works with on-site and cloud databases

  • Supports all platforms and languages because it works at the wire protocol level

  • Can be applied to multiple clients at the same time


Disadvantages of the proxy approach

  • Requires proxy server

  • Small increase in response time due to traffic going through the proxy

Which approach is right for you?

If you care mostly about the database, for instance as a DBA, or as a systems manager, then server-based monitoring is most likely the right solution for you -- no surprise there.

If you are an application developer or tester, or you just need to know what a database client is doing in the database, then you have a choice between client-based monitoring and proxy-based monitoring.

If it's reasonable for you to install an agent in your client, that's a fine approach. You will get good insights into your client's behavior, and there are many products to choose from (just Google "APM database").

If installing an agent in your client is an unattractive prospect, or if your client uses an unsupported platform or language, then a proxy-based approach is probably your best choice -- perhaps even your only choice. As an example, take a look at Gallium Data's application database monitoring tutorial.