0

I have setup a rest service using the guide provided STS at: http://spring.io/guides/gs/rest-service/

I am at the beginning of the development but I want to make sure I have the right tools in place to measure the performance.

Key Performance Indicators I am interesting are:

  • HTTP Request counter
  • HTTP Request rate over a configurable period of time
  • HTTP average latency
  • And more

At the end i am interesting to gather statistics like here: http://ruleoftech.com/2013/monitoring-java-ee-application-with-javamelody

I failed to find any documentation that describe the steps involved for doing such things. The JavaMelody documentation at: https://code.google.com/p/javamelody/wiki/UserGuide talks about copying the relevant jars in WEB-INF/lib but AFAIK there is no equivalent in Spring or at least in the way I am using it. I am not an expert in Spring.

I am looking for help on how to set this up.

Thx in advance.

Stephan
  • 41,764
  • 65
  • 238
  • 329
isaac.hazan
  • 3,772
  • 6
  • 46
  • 76

3 Answers3

4

Add java melody dependencies to your pom.xml:

<!-- javamelody-core -->
    <dependency>
        <groupId>net.bull.javamelody</groupId>
        <artifactId>javamelody-core</artifactId>
        <version>1.54.0</version>
    </dependency>

Add the monitoring spring context to your Application class:

@ComponentScan
@EnableAutoConfiguration
@ImportResource("classpath:net/bull/javamelody/monitoring-spring.xml")
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

Use the "@MonitoredWithSpring" Java melody annotation to monitor your spring object:

@RestController
@MonitoredWithSpring
public class GreetingController {

    private static final String template = "Hello, %s!";
    private final AtomicLong counter = new AtomicLong();


    @RequestMapping("/greeting")
    public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
        return new Greeting(counter.incrementAndGet(),
                        String.format(template, name));
        }
    }
gamerkore
  • 1,105
  • 1
  • 11
  • 16
0

You don't tell how you are "using" Spring but what I quickly looked at the STS guide for rest service it manages dependencies (jars) with Gradle or Maven and provides examples for both. The Rule of Tech example uses Maven (as shown in JavaMelody docs) to get the JavaMelody jars (to WEB-INF/lib) so you can follow the article to configure JavaMelody statistics for your application.

walokra
  • 31
  • 1
  • 6
0

There is now a javamelody spring-boot-starter which is a simpler solution for spring-boot 2.

Add javamelody spring-boot-starter dependencies to your pom.xml:

    <dependency>
        <groupId>net.bull.javamelody</groupId>
        <artifactId>javamelody-spring-boot-starter</artifactId>
        <version>1.76.0</version>
    </dependency>

And you are done (no need to import the monitoring-spring.xml resource and no need to add annotations to controllers).

For spring-boot 1 or to check the latest version, see doc.

evernat
  • 1,713
  • 13
  • 18