Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javamelody support #450

Closed
wants to merge 9 commits into from
Closed

Conversation

dvtoever
Copy link

  • Very basic setup to add a tab for javamelody

  • In your SBA project add a depencendy for spring-boot-admin-server-ui-javamelody

      <dependency>
      	<groupId>de.codecentric</groupId>
      	<artifactId>spring-boot-admin-server-ui-javamelody</artifactId>
      	<version>1.5.1-SNAPSHOT</version>
      </dependency>
    

Requires the following Configuration class in your SBA project

package net.bull.javamelody;

import de.codecentric.boot.admin.event.ClientApplicationDeregisteredEvent;
import de.codecentric.boot.admin.event.ClientApplicationRegisteredEvent;
import de.codecentric.boot.admin.model.Application;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;

import javax.servlet.Filter;
import java.io.IOException;

/**
 * Unfortunately javamelody is rather closed, therefore use the same packagename to access package private logic
 */
@Configuration
public class JavaMelodyConfiguration {

	private static final Logger LOGGER = LoggerFactory.getLogger(JavaMelodyConfiguration.class);
	private static final String CONTEXT_ROOT = "/javamelody";

	@Bean
	public FilterRegistrationBean filterRegistrationBean() {
		final Filter javaMelodyFilter = new MonitoringFilter();

		FilterRegistrationBean javaMelodyFilterBean = new FilterRegistrationBean(javaMelodyFilter);
		javaMelodyFilterBean.addServletNames("monitoring");
		javaMelodyFilterBean.addUrlPatterns("/*");
		return javaMelodyFilterBean;
	}

	@Bean
	public ServletRegistrationBean collectorServletBean() {
		final CollectorServlet servlet = new CollectorServlet();
		ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(servlet);
		servletRegistrationBean.addUrlMappings(CONTEXT_ROOT);

		return servletRegistrationBean;
	}

	@EventListener
	public void onClientApplicationRegistered(ClientApplicationRegisteredEvent event) {
		final Application application = event.getApplication();
		final String applicationName = application.getName() + "-" + application.getId();

		try {
			Parameters.addCollectorApplication(applicationName, Parameters.parseUrl(application.getServiceUrl()));
			LOGGER.info("Added application {} to java melody", applicationName);
		} catch (IOException e) {
			LOGGER.warn("Failed to register application {} to java melody" + applicationName);
		}
	}

	@EventListener
	public void onClientApplicationDeregistered(ClientApplicationDeregisteredEvent event) {
		final Application application = event.getApplication();
		final String applicationName = application.getName() + "-" + application.getId();

		try {
			Parameters.removeCollectorApplication(applicationName);
			LOGGER.info("Removed application {} from java melody", applicationName);
		} catch (IOException e) {
			LOGGER.warn("Failed to unregister application {} from java melody" + applicationName);
		}
	}

}

@dvtoever dvtoever mentioned this pull request May 12, 2017
@joshiste
Copy link
Collaborator

You could turn the JavaMelodyConfiguration into an autoconfiguration and include it (as I did in the tubrine module)

@joshiste joshiste changed the title - initial version for javamelody support in SBA Javamelody support in SBA Jun 8, 2017
@joshiste joshiste changed the title Javamelody support in SBA Javamelody support Jun 8, 2017
* register and unregister applications. Using the {@link EventListener annotations} we receive notifications from service discovery.
*/
@Service
public class JavaMelodyService {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are missing for this class.

* Service class in the javamelody package, so we can access the javamelody Parameters class in which we can
* register and unregister applications. Using the {@link EventListener annotations} we receive notifications from service discovery.
*/
@Service
Copy link
Collaborator

@joshiste joshiste Jun 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't rely on component scan - it might be disabled in the users' projects... since the service is in the config just remove the annotation

@codecentric codecentric deleted a comment Jun 16, 2017
@codecentric codecentric deleted a comment Jun 16, 2017
@joshiste
Copy link
Collaborator

Sorry for coming back to this PR this late. Looking good so far. I left you some comments on minor issues. coul you also add a short chapter to the docs on how to use this module?

@dvtoever
Copy link
Author

Late reply from my side as well :)

Here are the requested changes

@codecentric codecentric deleted a comment Jul 11, 2017
@codecentric codecentric deleted a comment Jul 11, 2017
@codecentric codecentric deleted a comment Jul 11, 2017
Copy link
Collaborator

@joshiste joshiste left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional to the blocker (see comment in net.bull.javamelody.JavaMelodyService) the JavaMelodyServiceTest fails.

@@ -0,0 +1,46 @@
package net.bull.javamelody;
Copy link
Collaborator

@joshiste joshiste Jul 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry that I spotted the foreign package declaration this late, but we can't include classes in foreign packages. It must be a de.codecentric package.

The downside seems that you cannot access the net.bull.javamelody.Parameters. So either you ask the javamelody guys to add a java-api to register applications in java melody or you need to make a post request to javameldoy's CollectorServlet.

@dvtoever
Copy link
Author

I created an issue with the Javamelody project javamelody/javamelody#661

evernat added a commit to javamelody/javamelody that referenced this pull request Aug 25, 2017
@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 86.771% when pulling 46dbaa5 on dvtoever:feature-javamelody into 0a029fc on codecentric:master.

javaMelody.addUrlPatterns("/*");
javaMelody.setFilter(filter);
return javaMelody;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of javamelody-core dependency and of javaMelody FilterRegistrationBean (which is not enough anyway), I suggest to show an example to add javamelody-spring-boot-starter in pom.xml. For example:

<!-- https://github.com/javamelody/javamelody/wiki/SpringBootStarter -->
<dependency>
	<groupId>net.bull.javamelody</groupId>
	<artifactId>javamelody-spring-boot-starter</artifactId>
	<version>${javamelody.version}</version>
</dependency>

<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>${ehcache.version}</version>
</dependency>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ehcache dependency is not needed here anymore: it can be removed.
And I suggest to add the iText 2.1.7 dependency (licence MPL or LGPL at your choice) and the Log4J dependency, in order to have PDF links in reports (I think PDF links are important in the reports) and to have some logs:

		<dependency>
			<groupId>com.lowagie</groupId>
			<artifactId>itext</artifactId>
			<version>2.1.7</version>
			<exclusions>
				<exclusion>
					<groupId>bouncycastle</groupId>
					<artifactId>bcmail-jdk14</artifactId>
				</exclusion>
				<exclusion>
					<groupId>bouncycastle</groupId>
					<artifactId>bcprov-jdk14</artifactId>
				</exclusion>
				<exclusion>
					<artifactId>bctsp-jdk14</artifactId>
					<groupId>bouncycastle</groupId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>1.2.17</version>
</dependency>

You could also copy the collector server log4j.xml file in resources of this module.

And XStream 1.4.10 dependency and aws-java-sdk-cloudwatch dependency could possibly be added to be able to export data as JSON or XML and to export data to AWS CloudWatch, but they are less important and I suppose that they could be added by the "admin" user.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we add this in the documentation instead of the pom.xml so users can choose for themselves if they want javamelody reporting to work. Personally I don't use it and rather don't have a transitive log4j/itext dependency

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I think that many users would be really happy to have the pdf reports. And, adding a iText dependency would be debatable in a monitored app but this dependency (with exclusions on transitive dependencies) is in my opinion not a problem in spring-boot-admin. So I think that we should really keep the iText dependency like it is now.
For Log4J, it is not included at the moment and finally it seems not needed since there is already a log4j-over-slf4j dependency in spring-boot-admin.

javaMelodyFilterBean.addServletNames("monitoring");
javaMelodyFilterBean.addUrlPatterns("/*");
return javaMelodyFilterBean;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This filterRegistrationBean() is not needed to make the collector server work and it should be removed I suppose. (There is a CollectorServlet below.)

Or if what you want is to monitor the spring-boot-admin server itself, then it is not enough (javamelody-spring-boot-starter may be better for this).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was to monitor spring boot admin itself. Why is this not enough?

Copy link

@evernat evernat Sep 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FilterRegistrationBean is not enough because in general a SessionListener is also installed. See https://github.com/javamelody/javamelody/blob/master/javamelody-spring-boot-starter/src/main/java/net/bull/javamelody/JavaMelodyAutoConfiguration.java#L87
Then the spring-boot-starter also adds monitoring of RestControllers, RestTemplates, Services, spring context and more.
So adding the javamelody-spring-boot-starter to monitor the spring-boot-admin server should be much simpler than adding filter, sessionlistener, etc.

final String applicationName = application.getName() + "-" + application.getId();

try {
Parameters.addCollectorApplication(applicationName, Parameters.parseUrl(application.getServiceUrl()));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameters.addCollectorApplication(applicationName, Parameters.parseUrl(application.getServiceUrl())); to be replaced by CollectorServlet.addCollectorApplication(applicationName, application.getServiceUrl())
(using the latest javamelody-core snapshot)

final String applicationName = application.getName() + "-" + application.getId();

try {
Parameters.removeCollectorApplication(applicationName);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be replaced by CollectorServlet.removeCollectorApplication(applicationName);

<artifactId>spring-boot-admin-server-ui-javamelody</artifactId>

<properties>
<javamelody.version>1.67.0</javamelody.version>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<javamelody.version>1.69.0</javamelody.version> can now be used to use the new methods in CollectorServlet

@dvtoever
Copy link
Author

dvtoever commented Oct 4, 2017

What is currently preventing this pull request from being merged?

@joshiste
Copy link
Collaborator

joshiste commented Oct 5, 2017

Sorry I'm currently short on time. And currently want to invest the spare time into the adaption of spring boot 2.0.

@joshiste
Copy link
Collaborator

joshiste commented Mar 5, 2018

So will you rework the code for 2.x?

@joshiste joshiste force-pushed the master branch 2 times, most recently from 8ef0059 to d7acee4 Compare March 18, 2018 13:14
@evernat
Copy link

evernat commented May 11, 2018

@joshiste

So will you rework the code for 2.x?

Do you mean rework the PR (as a new PR certainly) to work with spring-boot-admin 2.0.0-SNAPSHOT?
If yes, can you help us by saying what files in the PR are not good anymore and if possible how those files should be changed? And is there an example similar to this PR or should the (new) PR be the new example of such integration?

evernat added a commit to javamelody/spring-boot-admin-server-ui-javamelody that referenced this pull request May 12, 2018
@joshiste
Copy link
Collaborator

@evernat I guess (mostly) all of it has to be reworked. The ui is now using Vue instead of Angular and also the backend has now a slightly different domain model.

@joshiste
Copy link
Collaborator

joshiste commented May 14, 2018

@evernat I do really like the fact that you published the module 1.5.x as external module, as it doesn't adds the burden of maintaining this on me.
Once #683 is resolved I'd like to go down this route for 2.0.x as well. Do you agree, so that I can close this PR?

@evernat
Copy link

evernat commented May 15, 2018

@joshiste I agree for the module in version 2.0.0 as an external module, if the module is migrated one day.
But @dvtoever is the main concerned by this PR and maybe also by the module migration and by #683 whatever it means, so I suggest to have his voice on this PR.

@dvtoever
Copy link
Author

I agree. Will close this PR

@dvtoever dvtoever closed this May 16, 2018
goldyliang pushed a commit to goldyliang/javamelody that referenced this pull request Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants