Brief introduction
As you learned in part 1th of this series (three articles), monitoring the availability and performance of Java applications and dependencies in production is critical to ensuring problem detection and accelerating problem diagnosis and repair. Source-code-level inserts for classes that need to be monitored have the advantages that are discussed in part 1th, but this method is often not available or impractical. For example, many of the monitoring points you are interested in may be in third party components, and the source code for Third-party components is unknown to you. In the 2nd part, I focused on ways to insert Java classes and resources without modifying the original source code.
Alternative methods for arranging inserts in the source code are:
Intercept
Class packaging
Byte code cartridge
This article uses the ITracer interface presented in part 1th to implement performance data tracking, illustrating these techniques in turn.
Java Inserts by intercepting
The basic premise of interception is the conversion of a particular invocation pattern through an interception construct and the collection of incoming inbound and outbound call information. The implementation of a basic Interceptor program will:
Gets the current time of the request to the inbound call.
Retrieves the current time of the outbound response.
Calculates the run time as an increment of two measures.
Submits the call's elapsed time to the application performance management (APM) system.
Figure 1 shows the process:
Figure 1. Basic process of performance data collection and interception program
Many Java frameworks, such as Java Platform and Enterprise Edition (Java EE), include core support for the interception stack, which can be passed through a series of preprocessing and reprocessing components in the interception stack. With these stacks, it is possible to inject the cartridge into the execution path. There are two benefits to doing this: first, you don't need to modify the source code of the target class; second, you insert an interceptor class into the execution process by inserting it into the JVM's classpath and modifying the component's deployment descriptor.