Monitoring Java Microservices with JavaMelody
Tags: java, opensource, monitoring
Published: 2019-06-08 19:04:51

---
title: Monitoring Java Microservices with JavaMelody
published: true
description: Javamelody is an open source project that helps you get metrics from your service.
tags: java, opensource, monitoring
cover_image: https://thepracticaldev.s3.amazonaws.com/i/p7si644iyvp0izctsq1z.png
tags: java, opensource, monitoring
---

[**Javamelody**](https://github.com/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.
![](https://thepracticaldev.s3.amazonaws.com/i/qxo94wo5cpbfc2w6re2k.png)
And add only Web dependency
![](https://thepracticaldev.s3.amazonaws.com/i/50ksvzxpmxy7599s9iru.png)
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:
![](https://thepracticaldev.s3.amazonaws.com/i/t3avf2knwbxpc80hifd6.png)

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
```xml
<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:
```java
@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:

![](https://thepracticaldev.s3.amazonaws.com/i/vlki732zcpexdhc61con.png)

![](https://thepracticaldev.s3.amazonaws.com/i/t3v3yqcq400rziphs772.png)

##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](https://jmeter.apache.org/).

{% github sandrogiacom/javamelody-spring-demo %}

[![](https://thepracticaldev.s3.amazonaws.com/i/gmrz82bjwhej1f1iqb1e.png)](https://twitter.com/sandrogiacom)