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
现在,让我们添加javamelody的spring boot依赖关系
<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.
指标将开始被捕获,但是我们的应用程序中仍然没有代码。 让我们创建一个休息端点。
Create a Rest Controller
添加一个新的类HelloController,如下所示:
@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
如您所见,指标开始收集:
More JavaMelody Resources
JavaMelody具有许多功能,例如:
- 插件:(Jenkins,JIRA,Bamboo,Liferay,Alfresco,Sonar,Grails)PDF报告生成(通过邮件每周,每日或每月生成报告)脚本和警报(詹金斯与Groovy)集中监控服务器真实用户监控数据库监控将指标发送到AWS CloudWatch,Graphite自定义报告,样式,图标和其他资源
Conclusion
JavaMelody helps you anticipate problems with your application. For best results, use with some stress tool, such as ĴMeter.
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