4

I need to monitor java application and I am using javamelody.

But the problem is, I have to get the data that javamelody has so I can show it in another screen. I know that javamelody store its rdd files in temp/javamelody directory, now I need to change the storage-directory to another path so I can get the data from that path.

How can I set the storage-directory of javamelody?

slartidan
  • 20,403
  • 15
  • 83
  • 131
Algorithman
  • 1,309
  • 1
  • 16
  • 39
  • `java -Djava.io.tmpdir=/new/tmp yourjar` (on Linux) or setting `%TMP%` (on Windows) should do the trick. – barti_ddu Jun 12 '13 at 08:19
  • the command can only be used for the project which has main class. javamelody is a library and it doesn't have any main class. How can the command used for the library class which has no main class? – Algorithman Jun 12 '13 at 08:46
  • Hah, even better: http://code.google.com/p/javamelody/wiki/UserGuide and scroll to `storage-directory`, this looks like what you want. – barti_ddu Jun 12 '13 at 08:54
  • I have seen it but it doesn't provide any statement about how to do it – Algorithman Jun 12 '13 at 09:01
  • Right in the beginning of section 6, e.g. `-Djavamelody.storage-directory=/some/dir`. – barti_ddu Jun 12 '13 at 09:07
  • Where should I type that command? I type it in javamelody temp directory and it gave me exception – Algorithman Jun 13 '13 at 02:40
  • This is not a command but a command option; you could set it anywhere where the startup options are set (e.g. startup script, tomcat properties file, etc). What kind of application do you have? Is it a servlet? What servlet container do you use in this case? – barti_ddu Jun 13 '13 at 05:39

4 Answers4

5

Oh I think I've found the answer I just have to set command line or xml file in my tomcat like this

<?xml version="1.0" encoding="UTF-8" ?>
<Context docBase="pathto\appname.war" path="javamelody" reloadable="false" >
        <Parameter name='javamelody.storage-directory' value='pathname' override='false'/>
</Context>

Thank you for the help :D

Algorithman
  • 1,309
  • 1
  • 16
  • 39
  • In this case it is called "context parameter" (which is set in `context.xml` file), not the command-line option :) Glad you've managed, cheers ;) – barti_ddu Jun 13 '13 at 09:22
1

In web.xml, define filter javamelody with parameter storage-directory as below:

<filter>
    <filter-name>javamelody</filter-name>
    <filter-class>net.bull.javamelody.MonitoringFilter</filter-class>
    <init-param>
        <param-name>storage-directory</param-name>
        <param-value>/path/to/the/storage/directory</param-value>
    </init-param>
</filter>

I tested using JavaMelody version 1.60.0. For more information refer to the JavaMelody user guide.

Yuci
  • 27,235
  • 10
  • 114
  • 113
1

for javamelody-spring-boot-starter

 javamelody.init-parameters.storage-directory=/tmp/javamelody-${spring.application.name}
panser
  • 1,949
  • 22
  • 16
0

For Spring Boot

public class JavaMelodyConfiguration implements ServletContextInitializer {

@Value(value="${javamelody.storage-directory}")
String jmStorageDir;

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    servletContext.addListener(new SessionListener());
    servletContext.setInitParameter("javamelody.storage-directory", jmStorageDir);
}

then you can set the javamelody.storage-directory in application.properties

Michal Ambrož
  • 169
  • 1
  • 6
  • This is not the right way to integrate javamelody in Spring boot, neither to set javamelody parameters. See https://github.com/javamelody/javamelody/wiki/SpringBootStarter – evernat Feb 12 '21 at 08:14