This project has retired. For details please refer to its Attic page.
Apache ESME - JMX REST API

JMX REST API

The following text is copied directly from the mailing list.

I have finished a REST api for generic jmx MBeans. It allows for listing mbeans, getting mbeaninfo, reading and setting attributes and invoking operations with parameters that can be represented as Strings ( i.e. String, Long etc. serialized classes don't count). Before I send to code to Richard I would like some feedback to see if I am missing something or should do something different. Here is the api and sample returns. Bad requests or errors will return BadResponse.

GET /jmx/mbeans - returns a list of mbean names
GET /jmx/mbean/\[mbean name\](mbean-name\.html)
/info - returns MBeanInfo for specified mbean
GET /jmx/mbean/\[mbean name\](mbean-name\.html)
/attributes - returns attribute name and string
values
POST /jmx/mbean/\[mbean name\](mbean-name\.html)
/invoke/\[operation name\]
<Params>
&nbsp;<Param>pone</Param>
&nbsp;<Param signature="java.lang.Long">123</Param>
</Params>
POST /jmx/mbean/\[mbean name/set - sets a single attribute
<Attribute name="attr" value="val" />
POST /jmx/mbean/\[mbean name\](mbean-name\.html)
/set - sets multiple attributes
<AttributeList>
&nbsp;<Attribute name="att1" value="val1" />
&nbsp;<Attrubute name="att2" value="val2" />
</AttributeList>

SAMPLES

GET /jmx/mbeans
<esme_api operation="mbeans" success="true">
<MBeans>
<MBean name="java.lang:type=Memory"/>
<MBean name="java.lang:type=GarbageCollector,name=Copy"/>
<MBean name="java.lang:type=MemoryPool,name=Code Cache"/>
<MBean name="java.lang:type=Runtime"/>
<MBean name="java.lang:type=ClassLoading"/>
<MBean name="java.lang:type=MemoryPool,name=Perm Gen \[shared-rw\](shared-rw\.html)
"/>
<MBean name="java.lang:type=Threading"/>
<MBean name="java.util.logging:type=Logging"/>
<MBean name="java.lang:type=MemoryPool,name=Perm Gen \[shared-ro\](shared-ro\.html)
"/>
<MBean name="java.lang:type=Compilation"/>
<MBean name="java.lang:type=MemoryPool,name=Eden Space"/>
<MBean name="org.apache.esme.stats:type=Stats"/>
<MBean name="StatsAgent:name=htmlAdaptor,port=9092"/>
<MBean name="com.sun.management:type=HotSpotDiagnostic"/>
<MBean name="java.lang:type=GarbageCollector,name=MarkSweepCompact"/>
<MBean name="java.lang:type=MemoryPool,name=Survivor Space"/>
<MBean name="java.lang:type=MemoryPool,name=Tenured Gen"/>
<MBean name="java.lang:type=MemoryPool,name=Perm Gen"/>
<MBean name="java.lang:type=OperatingSystem"/>
<MBean name="JMImplementation:type=MBeanServerDelegate"/>
<MBean name="java.lang:type=MemoryManager,name=CodeCacheManager"/>
</MBeans>
</esme_api>
GET /jmx/mbean/org.apache.esme.stats:type=Stats/attributes
<esme_api operation="mbean" success="true">
<MBeanAttributes name="org.apache.esme.stats:type=Stats">
<MBeanAttribute value="1" name="counter_userCount"/>
<MBeanAttribute value="1" name="counter_liftSessions"/>
<MBeanAttribute value="1.0" name="gauge_users"/>
<MBeanAttribute value="1.0" name="gauge_listener"/>
</MBeanAttributes>
</esme_api>
GET /jmx/mbean/org.apache.esme.stats:type=Stats/info
<esme_api operation="mbean" success="true">
<MBeanInfo name="org.apache.esme.stats:type=Stats">
<MBeanAttributes>
<MBeanAttributeInfo isIs="false" type="java.lang.Long"
description="counter"
isReadable="true" name="counter_userCount" isWritable="false"/>
<MBeanAttributeInfo isIs="false" type="java.lang.Long"
description="counter"
isReadable="true" name="counter_liftSessions" isWritable="false"/>
<MBeanAttributeInfo isIs="false" type="java.lang.Long" description="gauge"
isReadable="true" name="gauge_users" isWritable="false"/>
<MBeanAttributeInfo isIs="false" type="java.lang.Long" description="gauge"
isReadable="true" name="gauge_listener" isWritable="false"/>
</MBeanAttributes>
<MBeanOperations>
<MBeanOperationInfo impact="ACTION" description="Remove all Counters,
Timers, Gauges and restart gathering timestamp."
returnType="java.lang.String" name="clear">
<Signature>
</Signature>
</MBeanOperationInfo>
</MBeanOperations>
<MBeanNotifications/>
</MBeanInfo>
</esme_api>

Notes

There is no security on the api. This obviously should not stay like this and should only be accessable with an administrator account. I tested it with the Stats MBean and the java.util.Logging MBean and it is working. I can access stats, reset them and change logging levels. It would be nice to be able to change runtime properties though JMX however most of the Lift and ESME code uses vals and immutable data structures that are set when the app is originally loaded. The lift Props object used by esme is totally immutable after it is constructed. It is worth thinking about switching to a property api like Configgy which uses mutable data structures for properties.

We could change in real time things like resent & links period, refresh intervals, analyzer settings like long query time, db connection pool sizes etc.

I didn't enable sending serialized objects through the REST api because it seems like more trouble than it's worth. Besides that sort of JMX functionality is only useful between servers and this api is really just for the cloud environment like stax which doesn't allow you to bind to ports.