7 Replies Latest reply on Oct 9, 2007 5:55 AM by dimitris

    How do I remotely access an mbean attribute value?

    rcolaco

      Hi there:

      I have two mbeans that are deployed on my JBoss 4.0.5 GA server.
      One is Tomcat's HttpRequest mbean (THM) and one is my Application mbean (AM).

      For AM, I am able to remotely access an mbean attribute value using the following code snippet:

      final Hashtable<String, String> env = new Hashtable<String, String>();
      final String factory = "org.jnp.interfaces.NamingContextFactory";
      env.put(Context.INITIAL_CONTEXT_FACTORY, factory);
      
      ObjectName on = new ObjectName("jboss:service=MyAppMbean");
      final String url = "jnp://myserver:1099";
      env.put(Context.PROVIDER_URL, url);
      Context ctx = new InitialContext(env);
      MBeanServerConnection connection = (MBeanServerConnection) ctx.lookup("jmx/invoker/RMIAdaptor");
      System.out.println(connection.getAttribute(on, "Summary"));
      ctx.close();


      However, when I attempt to connect to the Tomcat Mbean...
      e.g.
      ObjectName = jboss.web:name=HttpRequest0,type=RequestProcessor,worker=http-0.0.0.0-8080

      I am trying to retrieve attribute values for attributes...
      - requestProcessingTime
      - remoteAddr
      - maxRequestUri

      However, my call using...

      connection.getAttribute(on, "requestProcessingTime")


      ... fails with the following error:

      Exception in thread "Main Thread" javax.management.AttributeNotFoundException: not found: requestProcessingTime
      at org.jboss.mx.server.AbstractMBeanInvoker.getAttribute(AbstractMBeanInvoker.java:335)
      at org.jboss.mx.server.MBeanServerImpl.getAttribute(MBeanServerImpl.java:556)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

      Any recommendations on how I can get the value of a specific attribute for the HttpRequest mbeans?

      Also note that I include jbossall-client.jar in my remote client application's runtime classpath that I use to connect to my server.

      Thanks in advance.

      - Rohit

        • 1. Re: How do I remotely access an mbean attribute value?
          genman

          Query the MBean and get back the list of all attributes. Probably you need to use "RequestProcessingTime" (big "R") instead.

          • 2. Re: How do I remotely access an mbean attribute value?
            rcolaco

            Tried that already; didn't work.

            Tried several variations...
            a] accessing via attribute: requestProcessingTime
            b] accessing via attribute: RequestProcessingTime
            c] accessing as operation: getRequestProcessingTime

            None of these worked.

            - Rohit

            • 3. Re: How do I remotely access an mbean attribute value?
              dimitris

              For the mbean you are interested in, check out the exported attributes operations, e.g.:

              cd jboss-x.y.z\bin
              twiddle info "jboss.web:type=GlobalRequestProcessor,name=http-127.0.0.1-8080"
              
              Description: null
              +++ Attributes:
               Name: modelerType
               Type: java.lang.String
               Access: r-
               Name: errorCount
               Type: int
               Access: rw
               Name: bytesReceived
               Type: long
               Access: rw
               Name: bytesSent
               Type: long
               Access: rw
               Name: processingTime
               Type: long
               Access: rw
               Name: requestCount
               Type: int
               Access: rw
               Name: maxTime
               Type: long
               Access: rw
              +++ Operations:
               void resetCounters()
              


              • 4. Re: How do I remotely access an mbean attribute value?
                rcolaco

                As confirmed, I am already aware of the attributes available for this mbean. This can be retrieved using ...

                MBeanInfo mbi = connection.getMBeanInfo(name);
                MBeanAttributeInfo[] mbaia = mbi.getAttributes();
                


                Anyways, I invoked a twiddle info on this mbean and here's the output:

                [root@machine bin]# ./twiddle.sh info "jboss.web:name=HttpRequest0,type=RequestP
                rocessor,worker=http-0.0.0.0-8080"
                
                Description: null
                +++ Attributes:
                 Name: modelerType
                 Type: java.lang.String
                 Access: rw
                 Name: virtualHost
                 Type: java.lang.String
                 Access: r-
                 Name: bytesSent
                 Type: long
                 Access: rw
                 Name: method
                 Type: java.lang.String
                 Access: r-
                 Name: remoteAddr
                 Type: java.lang.String
                 Access: r-
                 Name: requestBytesSent
                 Type: long
                 Access: r-
                 Name: contentLength
                 Type: int
                 Access: r-
                 Name: bytesReceived
                 Type: long
                 Access: rw
                 Name: requestProcessingTime
                 Type: long
                 Access: r-
                 Name: globalProcessor
                 Type: org.apache.coyote.RequestGroupInfo
                 Access: rw
                 Name: protocol
                 Type: java.lang.String
                 Access: r-
                 Name: currentQueryString
                 Type: java.lang.String
                 Access: r-
                 Name: maxRequestUri
                 Type: java.lang.String
                 Access: rw
                 Name: requestBytesReceived
                 Type: long
                 Access: r-
                 Name: serverPort
                 Type: int
                 Access: r-
                 Name: stage
                 Type: int
                 Access: rw
                 Name: requestCount
                 Type: int
                 Access: rw
                 Name: maxTime
                 Type: long
                 Access: rw
                 Name: processingTime
                 Type: long
                 Access: rw
                 Name: currentUri
                 Type: java.lang.String
                 Access: r-
                 Name: errorCount
                 Type: int
                 Access: rw
                +++ Operations:


                I still have a problem retrieving the VALUE of the mbean attribute using Java code as initially posted. Any suggestions on how this can be retrieved? i.e. specifically for the requestProcessingTime attribute.

                Thanks

                - Rohit

                • 5. Re: How do I remotely access an mbean attribute value?
                  dimitris

                  I just tried this very simple twiddle command on 4.0.5 and got:

                  X:\jboss\jboss-4.0.5.GA\bin>twiddle get "jboss.web:type=RequestProcessor,worker=
                  http-0.0.0.0-8080,name=HttpRequest0" requestProcessingTime remoteAddr maxRequestUri
                  requestProcessingTime=1191832947562
                  remoteAddr=null
                  maxRequestUri=null
                  


                  • 6. Re: How do I remotely access an mbean attribute value?
                    rcolaco

                    So if twiddle gets the requestProcessingTime, how do I get it from the Java code snippet that I posted? If my Java code is incorrect, could you suggest a piece of code that could retrieve this?

                    Thanks

                    - Rohit

                    • 7. Re: How do I remotely access an mbean attribute value?
                      dimitris

                      There is nothing special with the code to read the mbean attribute. The code you showed should work. Maybe you don't get to the right mbean or mbean server?

                      Whatever results you get, make sure it's the same with what you would see with jmx-console. Try to hit the attributes of another mbean, e.g. jboss.system:type=ServerInfo