Skip to content
This repository has been archived by the owner on Oct 6, 2018. It is now read-only.

echocat/jemoni

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

echocat JeMoni

…is a toolset for monitoring JVMs. Generally it aims features around JMX.

JMX

Make a bean to a MBean

You can simply use annotations to publish the information and operations of your beans.

@Bean(description = "Very cool things here")
public class Foo {
    
    private String _message;

    @Attribute(description = "A nice message")
    public String getMessage() {
        return _message;
    }

    public void setMessage(String message) {
        _message = message;
    }

    @Attribute(name= "numberOfDevil")
    public int getNumber() {
        return 666;
    }

    @Operation(description = "Say something")
    public String say(@Argument(description = "magicNumber") int forInteger) {
        return "What a cool number: " + forInteger;
    }

    public long getNumberThatIsHiddenInJmx() {
        return 1234;
    }
}

Publish your bean

final JmxRegistry registry = new JmxRegistry();
final Registration registration = registry.register(new Foo());

// Do something here ... you bean is now known in you local MBeanServer

registration.close(); // Never forget to release it from the JMX context

JvmHealth

The org.echocat.jemoni.jmx.support.JvmHealth bean is a container with the most important values of the JVM. Normally this values are widespread in the whole JMX context. Here you can find all values at one place.

final JvmHealth jvmHealth = new JvmHealth(jmxRegistry);
// Run your application...
jvmHealth.close(); // Close it at shutdown of your application

The resulting MBean will be located under org.echocat.jemoni.jmx.support:name=JvmHealth and provides the attributes:

  • long gcCollectionCount
  • long gcCollectionTime
  • long heapCommitted
  • long heapInit
  • long heapMax
  • long heapUsed
  • long nonHeapCommitted
  • long nonHeapInit
  • long nonHeapMax
  • long nonHeapUsed
  • long loadedClassCount
  • long unloadedClassCount
  • long totalLoadedClassCount
  • long busyThreadCount
  • long totalThreadCount
  • long uptime Yes there are possible usage scenarios ;-)

… and operations:

  • void exit(int exitCode)
  • void gc()
  • java.util.Map<String, String> getSystemProperties()
  • String getSystemProperty(String name)
  • void setSystemProperty(String name, String value)

ServletHealth

The org.echocat.jemoni.jmx.support.ServletHealth is a ServletFilter which could be used to determinate the performance of running requests. It will measure all incoming request and will create a statistic of requests per second and average request duration.

The values could be separated in scopes that could configured in the web.xml.

Default usage in web.xml

<filter>
    <filter-name>serlvetHealth</filter-name>
    <filter-class>org.echocat.jemoni.jmx.support.ServletHealth</filter-class>
    <init-param>
        <param-name>mapping</param-name>
        <param-value>
            /foo.*>foo
            /bar.*>bar
            .*\.html>html
            .*\.action>action
        </param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>serlvetHealth</filter-name>
    <url-pattern>*</url-pattern>
</filter-mapping>

The resulting MBean will be located under org.echocat.jemoni.jmx.support:name=ServletHealth and provides the attributes:

  • double foo.requestsPerSecond
  • double foo.averageRequestDuration
  • double bar.requestsPerSecond
  • double bar.averageRequestDuration
  • double html.requestsPerSecond
  • double html.averageRequestDuration
  • double action.requestsPerSecond
  • double action.averageRequestDuration
  • double requestsPerSecond – includes also the values of all other *.requestsPerSecond
  • double averageRequestDuration – includes also the values of all other *.averageRequestDuration

Use an interceptor

It is possible to use an interceptor to ignore requests or modify the target scope name. You have to implement org.echocat.jemoni.jmx.support.ServletHealth.Interceptor and define it in the web.xml.

<init-param>
    <param-name>interceptor</param-name>
    <param-value>my.InterceptorImpl</param-value>
</init-param>

Use it with spring

You have to ways. You could initialize this filter directly with spring and inject the dependencies directly. Our define it in the filter config and the filter will resolve the values over the WebApplicationContext.

<init-param>
    <param-name>interceptor-ref</param-name>
    <param-value>myInterceptorBeanId</param-value>
</init-param>
<init-param>
    <param-name>registry-ref</param-name>
    <param-value>myJmxRegistryBeanId</param-value>
</init-param>

Carbon

…or Graphite is a tool to visualize measure points. It could be used to visualize performance data of websites, memory usage, …

Visit the Graphite website to get in touch with it.

Writer

The first important tool is the CarbonWriter to write measure points to a carbon server.

Initialize with Spring

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:carbon="https://jemoni.echocat.org/schemas/carbon.xsd"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                           https://jemoni.echocat.org/schemas/carbon.xsd https://jemoni.echocat.org/schemas/carbon-1.0.xsd">

    <carbon:writer address="my.carbon.server:666" />

</beans>

Initialize direct

final CarbonWriter writer = new CarbonWriter();
writer.setAddress(new InetSocketAddress("my.carbon.server", 666));
writer.init();
// your application is running
writer.close(); // Do not forget to close it on JVM shutdown

Use it

writer.write("my.path", 12.3);

Jmx2CarbonBridge

If you want to push data of MBeans to a carbon you simply have to configure the Jmx2CarbonBridge. It automatically detects all MBeans that machtes the given rules and export it in a defined interval to the carbon server.

Initialize with Spring

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:carbon="https://jemoni.echocat.org/schemas/carbon.xsd"
       xmlns:j2cr="https://jemoni.echocat.org/schemas/jmx2carbonRules.xsd"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                           https://jemoni.echocat.org/schemas/carbon.xsd https://jemoni.echocat.org/schemas/carbon-1.0.xsd
                           https://jemoni.echocat.org/schemas/jmx2carbonRules.xsd https://jemoni.echocat.org/schemas/jmx2carbonRules-1.0.xsd">

    <carbon:writer address="my.carbon.server:666" />
    <carbon:jmx2carbonBridge writer-ref="org.echocat.jemoni.carbon.CarbonWriter">
        <j2cr:configuration>
            <j2cr:rule updateEvery="1s">
                <j2cr:include pattern="/.*org\.echocat\.jemoni\.demo1.*/" />
                <j2cr:exclude>
                    <j2cr:attribute pattern="/.*ignored/"/>
                </j2cr:exclude>
            </j2cr:rule>
            <j2cr:rule updateEvery="10s">
                <j2cr:include pattern="/.*org\.echocat\.jemoni\.demo2.*/" />
            </j2cr:rule>
        </j2cr:configuration>
    </carbon:jmx2carbonBridge>
</beans>

Initialize direct

final Jmx2CarbonBridge bridge = new Jmx2CarbonBridge(writer);
bridge.setConfiguration(configuration().rules(
    rule().updateEvery("1s").includes(
        object().pattern("/.*org\\.echocat\\.jemoni\\.demo1.*/")
    ).excludes(
        object().attributes(
            attribute("/.*ignored/")
        )
    ), rule().updateEvery("10s").includes(
        object().pattern("/.*org\\.echocat\\.jemoni\\.demo2.*/")
    )
));
bridge.init();
// your application is running
bridge.close(); // Do not forget to close it on JVM shutdown

Use it

You have nothing to do. Until the bridge is running it will write all the time to the carbon server. If it is not reachable some measure points will be lost. The carbon writer only buffers a limited amount of measure points.

Links

Use with Maven

<dependencies>
    <dependency>
        <groupId>org.echocat.jemoni</groupId>
        <artifactId>jmx</artifactId>
        <version>-- version --</version>
    </dependency>
    <dependency>
        <groupId>org.echocat.jemoni</groupId>
        <artifactId>carbon</artifactId>
        <version>-- version --</version>
    </dependency>
</dependencies>

Find out what are the possible versions or what is the latest version.

License

echocat Velma is licensed under MPL 2.0.

Want to help?

You are welcome. Fork or contact us.

About

Tools to monitor the JVM including some convenience JMX beans and an JMX to Carbon bridge.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages