Skip to content

Instantly share code, notes, and snippets.

@anthonyserious
Last active August 29, 2015 14:06
Show Gist options
  • Save anthonyserious/827efbbbae8c151c9ccf to your computer and use it in GitHub Desktop.
Save anthonyserious/827efbbbae8c151c9ccf to your computer and use it in GitHub Desktop.
Converts standard JMX MBean names to JavaScript objects, where MBean names are of the form 'domain:key1=value1,key2=value2,...'
function mbeanToObject (mbean) {
var obj = {};
var a = mbean.split(":");
obj.domain = a[0];
obj.properties = [];
a[1].split(",").forEach(function(propPair) {
var pair = propPair.split("=");
obj.properties[pair[0]] = pair[1];
});
return obj;
}
@anthonyserious
Copy link
Author

Example:

> function mbeanToObject (mbean) {
...   var obj = {};
...   var a = mbean.split(":");
...    obj.domain = a[0];
...    obj.properties = [];
...    a[1].split(",").forEach(function(propPair) {
.....       var pair = propPair.split("=");
.....       obj.properties[pair[0]] = pair[1];
.....    });
...    return obj;
... }
undefined
> var x = mbeanToObject('java.lang:name=PS Old Gen,type=MemoryPool')
undefined
> x
{ domain: 'java.lang',
  properties: [ name: 'PS Old Gen', type: 'MemoryPool' ] }
>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment