JMX data source
Dynatrace provides a framework to create metrics from JMX MBeans. Every process monitored by OneAgent Java code module is capable of processing JMX 2.0 extensions.
You need to enable the Java Metric Extensions 2.0 (JMX) OneAgent feature
Every MBean has a unique object name. Every object name consists of a domain name and a list of key properties. Every key property consists of a name and a (string) value.
JMX defines a standardized syntax to write those object names, for example,
java.lang:type=GarbageCollector,name=YoungGen. Every MBean has 0 or more attributes (see MBeanServer::getAttribute). Attributes can be of any Java type (including booleans, numbers and strings).
Numeric attributes can be directly used to produce metrics in Dynatrace. It's also possible to extract numeric values from complex attributes.
We assume the following:
Supported Dynatrace versions
Dynatrace version 1.265+
OneAgent version 1.265+
JMX extension YAML file
Let's start with a minimal JMX extension:
1# required extension metadata2name: custom:com.example.jmx3version: 1.0.04minDynatraceVersion: 1.265.05author:6 name: John Doe78# optional metric metadata9metrics:10 - key: com.example.jmx.thread_count11 metadata:12 displayName: Thread Count13 description: Number of active Java threads14 unit: Count1516# defines how to create metrics from JMX MBeans17jmx:18 groups:19 - group: jvm20 subgroups:21 - subgroup: basic22 query: java.lang:type=Threading23 metrics:24 - key: com.example.jmx.thread_count25 type: gauge26 value: attribute:ThreadCount
The first two parts should already be familiar to you, we will focus on the
jmx section of the YAML file.
Groups and subgroups can be used to share configuration between multiple metrics. In our specific sample, we only have one group and one subgroup.
Extract metrics from MBeans
Every subgroup has to select a set of MBeans that should contribute to a metric. This is done with the
query field and follows the standard JMX object name syntax
Here, the query is
java.lang:type=Threading. This breaks down into looking for a bean in domain
java.lang that has exactly one property with name
type and value
Every subgroup also needs to define at least one metric that should be extracted from the selected MBeans. In our sample we create a Dynatrace gauge metric called
com.example.jmx.thread_count by querying the numeric JMX attribute
ThreadCount from the MBean
OneAgent will automatically add the following dimensions to your metric:
For more information, see JMX data source reference.