Skip to content

Segence/jmx-collector

Repository files navigation

JMX Collector

Build Status Download

A library to collect JMX metrics.

Usage

  1. Add the Segence OSS Releases Maven repo to your project, click here for instructions
  2. Import the artifact, click here for instructions
  3. Query JMX metrics by specifying some MBean names and attributes. Example:
import com.segence.commons.jmx.collector.JmxCollector

...

Map<ObjectName, Set<String>> mbeansAndAttributesToQuery = new HashMap<ObjectName, Set<String>>() {{
    try {
        put(
            new ObjectName("java.lang:type=OperatingSystem"),
            new HashSet<String>() {{
                add("Arch");
                add("AvailableProcessors");
            }}
        );
    } catch (MalformedObjectNameException e) {
        e.printStackTrace();
    }
}};

Set<MBeanMetricResult> results = JmxCollector.queryAsSet(mbeansAndAttributesToQuery);