monitoring-with-collectd-jmxtrans-graphite-bootstrap

This repos is a bootstrap for Java Monitoring with Collectd, JMXTrans and Graphite. Run scripts/start.sh will create and provision an Ubuntu VM and configure & run the tools on a sample project. You will be allowed to access to the sample web application from the host at localhost:8091/cocktail-app/ and to the Graphite web application at localhost:8090

Prerequisites

  • Shell
  • Vagrant

Configuration

You can studie all the configuration realized to run up Collectdm JMXTrans and Graphite in the file scripts/provisioning.sh

The configurations to monitor the sample application are specified below.

Queries

This sample configuration collects a mix metrics

Extract of classpath:jmxtrans.json

"queries": [
  {
    "objectName": "cocktail:type=CocktailManager,name=CocktailManager",
    "resultAlias": "cocktail",
    "attributes": [
      "AddedCommentCount",
      "CreatedCocktailCount",
      "DisplayedCocktailCount",
      "SearchedCocktailCount",
      "UpdatedCocktailCount"
    ]

  }
]

Output Writers

This sample application outputs the metrics to 2 writers: Slf4jWriter and GraphiteWriter.

Extract of classpath:jmxtrans.json

{
  "@class": "org.embedded-jmxtrans.output.Slf4jWriter"
},
{
  "@class": "org.embedded-jmxtrans.output.GraphiteWriter",
  "settings": {
    "host": "${graphite.host:localhost}",
    "port": "${graphite.port:2003}",
    "namePrefix":"${graphite.namePrefix:servers.#hostname#.}"
  }
}

By default, graphite writer connects to a graphite server on localhost:2003. An alternate configuration can be defined using Java system properties (ie "-D" command line parameters) who can be defined in the "catalina.properties" file of the underlying Tomcat server.

Spring Integration

In src/main/webapp/WEB-INF/spring-mvc-servlet.xml:

<beans ...
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:jmxtrans="http://www.jmxtrans.org/schema/embedded"
       xsi:schemaLocation="...
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
		http://www.jmxtrans.org/schema/embedded http://www.jmxtrans.org/schema/embedded/jmxtrans-1.0.xsd">

    <context:annotation-config/>

    <jmxtrans:jmxtrans>
        <jmxtrans:configuration>classpath:jmxtrans.json</jmxtrans:configuration>
        <jmxtrans:configuration>classpath:org/jmxtrans/embedded/config/tomcat-6.json</jmxtrans:configuration>
        <jmxtrans:configuration>classpath:org/jmxtrans/embedded/config/jmxtrans-internals.json</jmxtrans:configuration>
        <jmxtrans:configuration>classpath:org/jmxtrans/embedded/config/jvm-sun-hotspot.json</jmxtrans:configuration>
    </jmxtrans:jmxtrans>
</beans>

NOTE: Don't forget to declare <context:annotation-config/> to handle embedded-jmxtrans' lifecycle annotation @PreDestroy at shutdown.

Maven Setup

pom.xml

<dependency>
    <groupId>org.jmxtrans.embedded</groupId>
    <artifactId>embedded-jmxtrans</artifactId>
    <version>1.0.8</version>
</dependency>