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

Joe Armstrong jarmstrong at postpath.com
Wed Oct 13 23:17:19 CEST 2010


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).
 
Thanks for any hints.
 
Joe
 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.verplant.org/pipermail/collectd/attachments/20101013/2f884c3b/attachment-0001.htm>


More information about the collectd mailing list