From d44d2c206bb7ae5a75804c952f028ff5c5a15e6b Mon Sep 17 00:00:00 2001 From: "G.Grandes" Date: Mon, 4 May 2020 17:30:27 +0200 Subject: [PATCH 1/2] Map support in addition to the current CompositeData --- src/main/java/org/jmxtrans/agent/Query.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jmxtrans/agent/Query.java b/src/main/java/org/jmxtrans/agent/Query.java index 01873ad9..ca7d4717 100644 --- a/src/main/java/org/jmxtrans/agent/Query.java +++ b/src/main/java/org/jmxtrans/agent/Query.java @@ -219,11 +219,23 @@ private void collectAndExportAttribute(MBeanServer mbeanServer, OutputWriter out } else { value = compositeData.get(key); } + } else if (attributeValue instanceof Map) { + Map mapData = (Map) attributeValue; + if (key == null) { + // Get for all keys + for (String key : mapData.keySet()) { + value = mapData.get(key); + processAttributeValue(outputWriter, objectName, attribute, key, value); + } + return; + } else { + value = mapData.get(key); + } } else { if (key == null) { value = attributeValue; } else { - logger.warning("Ignore NON compositeData for specified key for '" + objectName + + logger.warning("Ignore NON compositeData/Map for specified key for '" + objectName + "'#" + attribute + "#" + key + ": " + attributeValue); return; } From 8b0dc6a418ef58c8dd8be733d4b754e49464affb Mon Sep 17 00:00:00 2001 From: "G.Grandes" Date: Mon, 4 May 2020 17:45:41 +0200 Subject: [PATCH 2/2] Update doc: Map support in addition to the current CompositeData --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2e249d9b..25c1d160 100644 --- a/README.md +++ b/README.md @@ -104,16 +104,16 @@ See `javax.management.MBeanServer.getAttribute(objectName, attribute)`. ``` -### MBean Composite Data attribute +### MBean Composite Data attribute (CompositeData or Map) -Use `key` to specify the key of the CompositeData. See `javax.management.openmbean.CompositeData#get(key)`. +Use `key` to specify the key of the CompositeData or Map. See `javax.management.openmbean.CompositeData#get(key)`. ```xml ``` -* You can collect all the keys of the composite data omitting `key` in the `` declaration. +* You can collect all the keys of the composite data or map omitting `key` in the `` declaration. * Use the [expression language](https://github.com/jmxtrans/jmxtrans-agent/wiki/Expression-Language) `#key#` (or its synonym `#compositeDataKey#`) in the `resultAlias` to use the composite data key in the metric name. Sample: ```xml