Software Secret Weapons™
|
Adding SNMP Monitoring Support To Http Session Listener by Pavel Simakov on 2006-03-23 23:57:52 under Linguine Watch, view comments |
|||
|
|
Most of J2EE multi-tier applications have a servlet container that forwards HTTP request to servlets and Java Server Pages (JSP). I like this part of the complete multi-tiered application because it is relatively simple to monitor. At the same time, many of the growth problems found in the large e-commerce software products can be inferred by monitoring only this area.
Let's add Linguine Watch performance monitor to our servlets and JSP pages so we can monitor number of sessions created and freed in the web application. In order to monitor how many sessions are in memory it is sufficient to know a number of instances created and a number of instances freed. The number of live sessions can be computed as the difference between them.
For adding session monitor to servlet container and updating monitor values we can quickly write custom javax.servlet.http.HttpSessionListener. I will use standard framework class ObjectLifetimeMonitor. Every time a session is created or freed we will call incCreated() or incFreed() on the monitor class to update the values of individual performance monitors inside of it. Here is a complete example of TestHttpSessionListener that implements HttpSessionListener and monitors session lifetimes. You can try this example with any JSP capable web server, Apache Tomcat for example.
import javax.servlet.http.HttpSessionEvent; import javax.servlet.http.HttpSessionListener; Now we need to write custom javax.servlet.ServletContextListener to intercept start/stop of the web application context. We need to create an instance of LinguineSNMPWatch class and start monitoring services when contextInitialized() is called. Similarly, we need to stop monitoring services when web application context is about to be destroyed in contextDestroyed().
Notice the order of the initialization of LinguineSNMPWatch as it is quite important. An instance of LinguineSNMPWatch has to be created first and its various options must be set. Monitoring services must be started with call to start(), after which, the monitoring objects must be registered one by one. The performance counters become available via SNMP immediately after they are registered.
import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener;
The last step in the initialization part is generation of the MIB file.
You can see the content of generated MIB file here
|
|
||
|
Copyright © 2004-2012 by Pavel Simakov
any conclusions, recommendations, ideas, thoughts or the source code presented on this site are my own and do not reflect a official opinion of my current or past employers, partners or clients |
No comments yet
Leave a comment