Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map support in addition to the current CompositeData #148

Merged
merged 4 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<query objectName="java.lang:type=Memory" attribute="HeapMemoryUsage" key="used"
resultAlias="jvm.heapMemoryUsage.used"/>
```

* You can collect all the keys of the composite data omitting `key` in the `<query />` declaration.
* You can collect all the keys of the composite data or map omitting `key` in the `<query />` 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
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/org/jmxtrans/agent/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,23 @@ private void collectAndExportAttribute(MBeanServer mbeanServer, OutputWriter out
} else {
value = compositeData.get(key);
}
} else if (attributeValue instanceof Map) {
Map<String, Object> mapData = (Map<String, Object>) 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;
}
Expand Down