No announcement yet.

Initial support for JMX Operations in Java Proxy

  • Filter
  • Time
  • Show
Clear All
new posts

    Initial support for JMX Operations in Java Proxy

    Hi Guys -
    Our development team implemented some JMX operations in our application which return all types of statistics - (We didn't use MBean Attributes so that the app only generates the stats when requested.)
    Now, I'm not a java programmer, but we needed to support the polling of these JMX operations, so I started hacking.

    The following patch on zabbix_java 1.9.9 (should also apply to 1.9.8) adds that support. It works for me, but I have NOT tested this too deeply. For example, I don't know what will happen if the key is neither an existing Attribute or Operation. Also, Operations have only been tested with zero or one parameters. More than that probably won't work.
    This code needs work, but it's a start.

    ---    2012-02-16 11:22:23.103907700 +0200
    +++ 2012-02-16 11:22:48.930242800 +0200
    @@ -48,6 +48,12 @@
            private String username;
            private String password;
    +       private Object value;
    +       private String operationName;
    +       private String[]  operationSplit;
    +       private String[]  operationParameters;
    +       private String[] operationSignature;
            public JMXItemChecker(JSONObject request) throws ZabbixException
    @@ -134,7 +140,52 @@
                                    attributeName = attributeName.substring(0, dot);
    -                       return getPrimitiveAttributeValue(mbsc.getAttribute(objectName, attributeName), subAttributeNames);
    +                         /**
    +                          * The concept here is to attempt to deal with JMX Operations, not just Attributes.
    +                          * The following solution was good for us: Attempt to poll as an Attribute. If we fail, attempt as an operation.
    +                          * TODO: Hypothetically, we could go and pull the list of JMX objects and figure out what type we're requesting,
    +                          * but that sounds wasteful to pull the whole map on each request. We might be able to do it once for each connection, and store it locally.
    +                          */
    +               try {
    +                       // Attempt to poll getAttribute
    +                       value = mbsc.getAttribute(objectName, attributeName);
    +               } catch ( e) {
    +                       // We got an exception. Let's try to poll it as an operation...
    +                               logger.debug("Attempted to get a non-existant Attribute. Trying as an Operation");
    +                               /**
    +                                *  We got an exception. Let's try to poll it as an operation...
    +                                *  Let's say we got : 'jmx["com.XXXX:group=monitoring,name=ComponentMonitoring,type=server","getCallAccumulatedTime=messages"]'
    +                                *  Split the "attributeName" field ("getCallAccumulatedTime=messages") on '=' to extract the Operation name:
    +                                */
    +                               operationSplit = attributeName.split("=",2);
    +                               operationName = operationSplit[0];
    +                               logger.debug("Operation request: operationName = {} and operationSplit.length = {} ", operationName, operationSplit.length);
    +                               // Clever defaults so "invoke" doesn't croak if there are no parameters:
    +                               operationParameters = null;
    +                               operationSignature = null;
    +                               // If we have parameters...
    +                               if (operationSplit.length > 1)
    +                               {
    +                                       /* This code needs to be rewritten - I don't have any JMX's with more than one parameter to test on...
    +                                        * Basically, it needs to parse the options and set the signature of each.
    +                                        * Unfortunately, I don't know the format for multiple parameters, and seeing that I used ',' to separate betweeen multiple parameters...
    +                                        * There's a good examples of the RIGHT way to do it at:
    +                                        *
    +                                        * (near the end)
    +                                        */
    +                                       operationParameters = operationSplit[1].split(",");
    +                                       logger.debug("Operation request: parameters[0] = {}", operationParameters[0]);
    +                                       operationSignature = new String[]{ "java.lang.String"}; //NOI18N
    +                               }
    +                               value = mbsc.invoke(objectName, operationName, operationParameters, operationSignature);
    +                               subAttributeNames="";
    +               }
    +               return getPrimitiveAttributeValue(value,subAttributeNames);
                    else if (item.getKeyId().equals("jmx.discovery"))

    Any update here?

    Hi Guys -
    Has anyone taken a look? Is there any plan for Zabbix to support JMX Operations?


      Zabbix JAVA Gateway - JMX operations support


      Has there been any development on the support for the JMX operations, even if we implement the hack mentioned below, how can we pass via the WEB Interface?

      A JMX operation is not a value to be displayed it needs an interface to invoke operations like start/stop or reset items etc, or and sometimes we need to pass parameters and receive return values.. have anyone tried that? again any hints would help as well!


      Last edited by nnoori; 24-01-2013, 20:37.


        Here is something I found recently about extending the Zabbix Java Gateway that would help executing JMX operations