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.
图片[1]-Monitoring Java Microservices with JavaMelody - 拾光赋-拾光赋
And add only Web dependency
图片[2]-Monitoring Java Microservices with JavaMelody - 拾光赋-拾光赋
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>

Enter fullscreen mode Exit fullscreen mode

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!";
    }
}

Enter fullscreen mode Exit fullscreen mode

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.

sandrogiacom / javamelody-spring-demo

How to monitoring your spring boot app with Javamelody

javamelody-spring-demo

How to monitoring your spring boot app with Javamelody

https://dev.to/sandrogiacom/monitoring-java-microservices-with-javamelody-1ndg


View on GitHub

原文链接:Monitoring Java Microservices with JavaMelody

© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容