MoSKito enables you to analyze and monitor your running Java application.
During this blog post, we guide you how to fully integrate MoSKito within Java EE 6 environment und run it with JBoss Application Server 7. Furthermore we provide some hooks for integrating Producers, Threshold and Accumulators.
Prerequirements
We assume you have your Java EE 6 project running against JBoss AS7. In this tutorial we focus on multiple maven project which WAR artifact. Our simple demo application enables you to manage some tasks:
We will cover those steps
- Setting up Maven dependencies
- Integrating Filters and Listeners to web.xml
- CDI integration, beans.xml
- Mark Java Class to be monitored
- Dive into MoSKito – thresholds, accumulators, counters
Setting up Maven dependencies
MoSKito artifacts are available in Maven Central Repository. So you just need to to add dependencies to you root POM. We need MoSKito-CDI and MoSKito-WebUi artifacts.
Please note: As MoSKito is multi module project build for several environments, we need to exclude some artifacts in order to avoid conflicts with container libraries.
1) Integrate MoSKito to Root-POM
<moskito.version>2.4.0</moskito.version> <ano-util.version>2.1.1</ano-util.version> <dependency> <groupId>net.anotheria</groupId> <artifactId>moskito-webui</artifactId> <version>${moskito.version}</version> <exclusions> <exclusion> <groupId>javassist</groupId> <artifactId>javassist</artifactId> </exclusion> <exclusion> <groupId>xerces</groupId> <artifactId>xercesImpl</artifactId> </exclusion> <exclusion> <groupId>xerces</groupId> <artifactId>xmlParserAPIs</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>net.anotheria</groupId> <artifactId>moskito-cdi</artifactId> <version>${moskito.version}</version> <exclusions> <exclusion> <groupId>javassist</groupId> <artifactId>javassist</artifactId> </exclusion> </exclusions> </dependency> <!-- Ignore Blowfish --> <dependency> <groupId>net.anotheria</groupId> <artifactId>ano-util</artifactId> <version>${ano-util.version}</version> <exclusions> <exclusion> <groupId>blowfish</groupId> <artifactId>blowfish</artifactId> </exclusion> </exclusions> </dependency>
2) Integrate MoSKito into artifact POMs:
Add this snippet to your cdi artifacts.
<dependency> <groupId>net.anotheria</groupId> <artifactId>moskito-cdi</artifactId> </dependency>
For web, add WebUI additionally. It contains all the JSP’s and Servlets, on what MoSKito UI is build of.
<dependency> <groupId>net.anotheria</groupId> <artifactId>moskito-webui</artifactId> </dependency>
Integrating Filters and Listeners to web.xml
MoSKito using HTTP Servlet filters and listeners to connect to your application.
[Update] Since MoSKito version 2.4.0 there it’s no need anymore to add filters and listeners to web.xml, manually. From now those are configured by Servlet 3.0 web-fragment.
CDI integration, beans.xml
MoSKito provides Interceptor to hook into CDI by adding this snippet to beans.xml:
<interceptors> <class>net.anotheria.moskito.integration.cdi.WebCallInterceptor</class> </interceptors>
Mark Java Class to be monitored
To enable Java class / service being coverd by MoSKito monitoring, just annotate it properly. In sample we defined class CustomerService to be visible in MoSKito UI within SERVICE category. Service in DAO or WEB could be marked same manner. By use of @Monitor requests to all public methods will be tracked and therefore become eligible for analysis.
import static net.anotheria.moskito.integration.cdi.MonitoringCategorySelector.SERVICE; import net.anotheria.moskito.integration.cdi.Monitor; ... @Monitor(SERVICE) @Stateless public class CustomerService implements Serializable { @Inject private CustomerDao customerDao; ... public void saveCustomer(Client client) { clientDao.persist(client); } ...
Dive into MoSKito – thresholds, accumulators, counters
Thresholds and Accumulators can easily be created during runtime on the fly. They can be configured through XML, REST or straight from Java. See screenshot of some thresholds we configured for task demo application:
For more details please follow our complete MoSkito integration guide: http://blog.anotheria.net/msk/the-full-complete-integration-guide-to-moskito-step-0/
What next
In this post we described how to easily integrate MoSKito monitoring into an existing Java EE + JBoss AS7 environment. We really encourage you to try it out yourself and let MoSKito helping you to understand what’s going on within your live application. Choose your next step(s):
- Run demo in JBoss locally: http://localhost:8080/moskitojboss/ , login with initial user (jim | secret ) or create your own and add some tasks
- View MoSKito locally: http://localhost:8080/moskitojboss/mui/
- Download complete source of demo code and build your own, GitHub: https://github.com/zaunberg/moskito-jboss
- Join Community at http://www.moskito.org
Every Fork and Feedback Welcome – same for MoSKito as it is easy to extend.
Michael