DEV Community

Cover image for Monitoring Java Microservices with JavaMelody
Sandro Giacomozzi
Sandro Giacomozzi

Posted on • Updated on

Monitoring Java Microservices with JavaMelody

Javamelody is an open source project that helps you get metrics from your service. With it you can discover possible failures before sending you code to production. It is very easy to include in your application and in this tutorial, we will show you how to do it.

Creating Demo App

Let's start creating a spring boot application. Access https://start.spring.io/ to generate our demo app. You can use your own package name on Group field.

And add only Web dependency

And then, generate project.

A zip file will be generated with our project and can be imported into your preferred IDE.
A generated project looks like this:

If you prefer to use this demo code, clone the github project:
https://github.com/sandrogiacom/javamelody-spring-demo

Add JavaMelody dependency

Now, let's add javamelody's spring boot dependency

<dependency>
    <groupId>net.bull.javamelody</groupId>
    <artifactId>javamelody-spring-boot-starter</artifactId>
    <version>1.77.0</version>
</dependency>

Run app

Next you can run your spring-boot application and open http://localhost:8080/monitoring to browse the monitoring reports.

The metrics will begin to be captured, but we still do not have code in our application. Let's create a rest endpoint.

Create a Rest Controller

Add a new class HelloController as below:

@RestController
@RequestMapping("/hello")
public class HelloController {
    @GetMapping
    public String sayHello() {
        return "Hello JavaMelody!";
    }
}

Restart your application and open http://localhost:8080/hello
Run this URL many times. After that, open http://localhost:8080/monitoring again.

Results

As you can see, the metrics began to be collected:

More JavaMelody Resources

JavaMelody has many, many features such as:

  • Plugins: (Jenkins, JIRA, Bamboo, Liferay, Alfresco, Sonar, Grails)
  • PDF report generation (Weekly, daily or monthly reports by mail)
  • Scripts and alerts (Jenkins with Groovy)
  • Centralized Monitoring Server
  • Real User Monitoring
  • Database monitoring
  • Sending metrics to AWS CloudWatch, Graphite
  • Custom reports, styles, icons and other resources

Conclusion

JavaMelody helps you anticipate problems with your application. For best results, use with some stress tool, such as JMeter.

GitHub logo sandrogiacom / javamelody-spring-demo

How to monitoring your spring boot app with Javamelody

Top comments (2)

Collapse
 
claytonpassos profile image
Clayton K. N. Passos

Is the same propose that Spring Framework Actuator?

Collapse
 
sandrogiacom profile image
Sandro Giacomozzi

No, there are many more features besides spring boot. They do not compete with each other, but can be used as a complement.

github.com/javamelody/javamelody/w...