Yammer metrics tutorial with JMX to gather metrics

Note: Yammer metrics has now moved to metrics-core.

from com.yammer.metrics:metrics-core:2.2.0 (NOT supported anymore) to com.codahale.metrics:metrics-core:3.0.*

from com.codahale.metrics:metrics-core:3.0.* to io.dropwizard.metrics:metrics-core:3.1.* since 2014.

When you are running long term applications like web applications, batch jobs, or stand-alone status update jobs, it is good to know some statistics about them, like number of requests served or request duration. You can also gather more generic information like the state of your internal collections, how many times some portion of code is being executed, or health checks like database availability, or any kind of connection to an external system.

All this kind of instrumentation can be achieved by using native JMX or using a modular project like yammer Metrics. Metrics provides a powerful way to measure the behaviour of your critical components and reporting them to a variety of systems like, JConsole, System Console, Ganglia, Graphite, CSV, or making them available through a web services as JSON data.

Step 1: Create a new Maven based Java project.

Step 2: Import it into eclipse via File –> Import –> Maven –> “Existing Maven Projects”


Step 3: It should look like as shown below after completing the steps below.


Step 4: Update the pom.xml file as shown below

Step 5: The dummy Request class.

Step 6: The dummy trading engine interface.

Step 7: The dummy trading engine implementation with yammer annotations to gather metrics.

Step 8: The spring context file to wire up Yammer and Java class defined above.


Step 8: The main class that starts the trading engine and fires requests every 5 seconds in a continuos loop.

Step 9: Run the “TradeEngineMain“, which starts the trading engine in a continous loop.

Step 10: Whilst the engine is running, from a DOS prompt invoke the JMX window by typing “jconsole”. You can type “jps” to find the process id of the trading engine that is running.



Step 11: You can see the metrics in the jconsole JMX window as shown below. Yammer supports more outputs including RESTful web service to report stats.



(Visited 6 times, 1 visits today)

800+ Java & Big Data Interview Q&As

200+ Java & Big Data Tutorials