Monitoring existing application using MoSKito Javaagent

Leo Ertuna - January 3, 2018 - 3 comments

In this tutorial we will demonstrate how to use MoSKito Javaagent to monitor existing web-application with no changes to the app’s source code. We will show how to add MoSKito Javaagent to the app deployed in Tomcat servlet container, and how to connect to this app using MoSKito Inspect.

If you run into any build issues during this tutorial please note that we are using the following tools:

  1. MoSKio 2.8.5
  2. Java 8
  3. Maven 3.3.9
  4. Git 2.15.1
  5. Tomcat 9.0.2
  6. MySQL Community Server 5.7.20

1) Download MoSKito Javaagent and MoSKito Inspect

Download MoSKito 2.8.5 here, locate moskito-javaagent folder in the downloaded archive. You can move this folder closer to your working directory. Take a note somewhere of the full path to moskito-javaagent-2.8.5.jar, you’re going to need it later on. This is the Javaagent that we are gonna use to monitor our app.

Now to observe all the data monitored from our app we need MoSKito Inspect standalone. From the same downloaded archive locate moskito-inspect folder and run MoSKito Inspect using the provided Tomcat server. Go to http://localhost:8088/moskito/ and make sure that it works.

2) Setup the demo app

You can follow this tutorial with your own app, all the steps will be fairly similar, but for demonstration purposes we suggest you to use our demo app first.

Clone the demo app from github

Run maven clean install, please note that this app contains Spring and Hibernate frameworks so setup your IDE accordingly.

We use MySQL database in this project, so in order to run the demo app create new MySQL schema named burgershop and create a new table in it as follows.

  `ITEM_BREAD` varchar(45) NOT NULL,
  `ITEM_MEAT` varchar(45) NOT NULL,
  `ITEM_EXTRA` varchar(45) NOT NULL,

Deploy the web-app using Tomcat server. Make sure that everything runs correctly. Play around, place a few orders, check if the orders get stored in the database. Once you make sure that everything functions as intended, proceed to adding the Javaagent.

3) Add MoSKito Javaagent to web-app’s Tomcat server

In your Tomcat’s add the following in the beginning of the file

export JAVA_OPTS=" $JAVA_OPTS -javaagent:[full path to moskito javaagent]/moskito-javaagent-2.8.5.jar"
export JAVA_OPTS=" $JAVA_OPTS -DapplicationPackages=org.moskito.demo.burgershop.burgershopstripped"

By this you specify the path to Javaagent jar and packages of your app that should be monitored.

In our demo app we use only one root package, but you can add multiple packages similar to “-DapplicationPackages=com.myPackage1,com.myPackage2“.

By default MoSKito Javaagent uses 9451 port to connect to MoSKito Inspect, but you can change it either by modifying moskitoBackendPort property in moskito-javaagent/configuration/moskito-javaagent-config.json file, or by adding another command to of your web-app’s server:

export JAVA_OPTS=" $JAVA_OPTS -DmoskitoAgentPort=[your port]"

4) Run and connect to MoSKito inspect

With everything setup we can now test our demo-app. Make a few orders and go to MoSKito Inspect, connect to localhost port 9451, and switch to producers tab.

Under Producers-Service you should see producers named OrderController, ShopController and ShopServiceImpl. These are the producers from our app. By default all classes that contain DAO, Repository, Service, Manager, or Controller in their names are monitored. You can specify your own name patterns for classes that should be monitored by default in moskito-javaagent/configuration/moskito-javaagent-config.json file under @monitoringDefaultClassConfig property.

You should also see the SQLQueries producer, this producer keeps track of all interactions between our app and the database. We can observe insert queries that store our orders in the database.

That’s it! We used MoSKito Javaagent and successfully added core MoSKito monitoring functionality to our existing web-app without any modifications to the app’s source code.


  1. martin

    Hi, Can I use Moskito in websphere with java 6 ?

  2. Leonardo


    Thank you to provide this great tool opensource, it is a wonderful project.
    I am trying to config Java Agent in OpenJdk 11, is it possible or Oracle’s Java VM is mandatory?


Post a Comment

Your email address will not be published.