[collectd] Using GenericJMX to consume array's of objects ?

matthew sporleder msporleder at gmail.com
Thu Oct 14 13:18:55 CEST 2010


On Wed, Oct 13, 2010 at 5:17 PM, Joe Armstrong <jarmstrong at postpath.com> wrote:
> Hi Guys,
>
>
>
> I have a webservice that is instrumented with JMX (MXBean) that produces an
> array of objects, I can’t seem to figure out what the collectd.conf should
> look like to consume this information.
>
>
>
> I have the GenericJMX plugin consuming other data from this server, so the
> basic’s are setup OK.  Here are some details (hopefully not too much…):
>
>
>
> The MXBean interface:
>
>
>
> package com.joe.sample.RESTService;
>
>
>
> public interface ConnectArrayMXBean {
>
>       public ConnectData[] getConnectData();
>
> }
>
>
>
> The MXBean implementation:
>
>
>
> package com.joe.sample.RESTService;
>
>
>
> import javax.management.ObjectName;
>
>
>
> public class ConnectArray implements ConnectArrayMXBean {
>
>
>
>       private static ConnectData[] data = null;
>
>       private static int index;
>
>
>
>       private ObjectName ObjName;
>
>       private static MBServer server = null;
>
>
>
>       public ConnectArray() {
>
>             data = new ConnectData[12];
>
>             index = 0;
>
>       }
>
>
>
>       @Override
>
>       public ConnectData[] getConnectData() {
>
>             return data;
>
>       }
>
>
>
>       public void add(String id, int bs, int br) {
>
>             data[index] = new ConnectData(id, bs, br);
>
>             index++;
>
>       }
>
>
>
>       public void register() {
>
>
>
>             if (server == null)
>
>                   server = new MBServer();
>
>
>
>             try {
>
>                   ObjName = new ObjectName(
>
>
> "com.joe.sample.RESTService:type=ConnectArray");
>
>                   server.register(this, ObjName);
>
>             } catch (Exception e) {
>
>                   e.printStackTrace();
>
>             }
>
>       }
>
>
>
>       // To allow the webapp to be reloaded
>
>       //
>
>       public void unregister() {
>
>             if (server != null) {
>
>                   server.unregister(ObjName);
>
>                   ObjName = null;
>
>             }
>
>       }
>
> }
>
>
>
> The class that is being returned (an array of these from getConnectData):
>
>
>
> package com.joe.sample.RESTService;
>
>
>
> import java.beans.ConstructorProperties;
>
>
>
> public class ConnectData {
>
>       private final String socketId;
>
>       private final int bytesSent;
>
>       private final int bytesRecv;
>
>
>
>       @ConstructorProperties( { "socketId", "bytesSent", "bytesRecv" })
>
>       public ConnectData(String socketId, int bytesSent, int bytesRecv) {
>
>             this.socketId = socketId;
>
>             this.bytesSent = bytesSent;
>
>             this.bytesRecv = bytesRecv;
>
>       }
>
>
>
>       public String getSocketId() {
>
>             return socketId;
>
>       }
>
>
>
>       public int getBytesSent() {
>
>             return bytesSent;
>
>       }
>
>
>
>       public int getBytesRecv() {
>
>             return bytesRecv;
>
>       }
>
> }
>
>
>
> Small chunk of code that creates the data on the server-side:
>
>
>
>   ConnectArray Array = new ConnectArray();
>
>               cArray.register();
>
>
>
>               // just garbage data to test things
>
>               cArray.add("Socket1", 1024, 2048);
>
>               cArray.add("Socket2", 12, 24);
>
>               cArray.add("Socket3", 30, 60);
>
>
>
> My collectd.conf (only the MBean portion):
>
>     <MBean "REST_ConnectArray">
>
>       ObjectName "com.joe.sample.RESTService:type=ConnectArray,*"
>
>       InstancePrefix "ConnectArray"
>
>       #InstanceFrom "socketId"
>
>       <Value>
>
>         Type "counter"
>
>         #InstancePrefix ""
>
>         #InstanceFrom "socketId"
>
>         Table true
>
>         Attribute "bytesSent"
>
>       </Value>
>
>     </MBean>
>
>
>
> Other info:
>
>
>
> Jconsole can view the data with no problems.
>
>
>
> The error I get from collectd depends on what collectd.conf contains – I
> have tried a lot of different versions so I won’t waste your time by giving
> you all of the versions that don’t work.  But basically the error always
> complains that the <Value> Attribute member can’t be queried (ex. Querying
> attribute bytesSent failed).
>

collectd will do a recursive loop through an MBean with multiple
attributes, but I think they need to be a special type like
javax.management.openmbean.CompositeData.



More information about the collectd mailing list