Package com.googlecode.jmxtrans.example

Source Code of com.googlecode.jmxtrans.example.Ehcache

package com.googlecode.jmxtrans.example;

import com.google.inject.Guice;
import com.google.inject.Injector;
import com.googlecode.jmxtrans.JmxTransformer;
import com.googlecode.jmxtrans.guice.JmxTransModule;
import com.googlecode.jmxtrans.model.JmxProcess;
import com.googlecode.jmxtrans.model.Query;
import com.googlecode.jmxtrans.model.Server;
import com.googlecode.jmxtrans.model.output.GraphiteWriter;
import com.googlecode.jmxtrans.util.JsonPrinter;

/**
* This example shows how to query ehcache for its statistics information.
*
* @author jon
*/
public class Ehcache {

  private static final String GW_HOST = "192.168.192.133";
  private static final JsonPrinter printer = new JsonPrinter(System.out);

  /** */
  public static void main(String[] args) throws Exception {

    JmxProcess process = new JmxProcess(Server.builder()
        .setHost("w2")
        .setPort("1099")
        .setAlias("w2_ehcache_1099")
        .addQuery(Query.builder()
            .setObj("net.sf.ehcache:CacheManager=net.sf.ehcache.CacheManager@*,name=*,type=CacheStatistics")
            .addAttr("CacheHits")
            .addAttr("InMemoryHits")
            .addAttr("OnDiskHits")
            .addAttr("CacheMisses")
            .addAttr("ObjectCount")
            .addAttr("MemoryStoreObjectCount")
            .addAttr("DiskStoreObjectCount")
            .addOutputWriter(GraphiteWriter.builder()
                .addTypeName("name")
                .setDebugEnabled(true)
                .setHost(GW_HOST)
                .setPort(2003)
                .build())
            .build())
        .build());

    printer.prettyPrint(process);

    Injector injector = Guice.createInjector(new JmxTransModule(null));
    JmxTransformer transformer = injector.getInstance(JmxTransformer.class);

    transformer.executeStandalone(process);
  }
}
TOP

Related Classes of com.googlecode.jmxtrans.example.Ehcache

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.