3 Replies Latest reply on Aug 20, 2018 5:03 AM by xiang2513982

    is there any method can show byteman instance and submitted scripts

    xiang2513982

      for example, in server there are 2 tomcat servers, users may start the byteman or not, may submit some rules and forget to unsubmit,  how can i know the working status of byteman?

        • 1. Re: is there any method can show byteman instance and submitted scripts
          adinn

          Hi Liu Xiang,

          xiang2513982  wrote:

           

          for example, in server there are 2 tomcat servers, users may start the byteman or not, may submit some rules and forget to unsubmit,  how can i know the working status of byteman?

          There are several things you can try but picking the right one depends on how you started Byteman.

           

          1) Byteman installed from the java command line using -javaagent

           

          If the tomcat server was started with -javaagent:${BYTEMAN_HOME}/lib/byteman.jar=listener:true then this means the Byteman agent will be listening on socket 9090. So, you can talk to the Byteman agent using the bmsubmit script (bmsubscript.bat on Windows, bmsubmit.sh on Linux) passing no arguments. This will only work if listener:true was passed in the list of -javaagent  options that follow the '=' sign.

           

          If an agent is installed then bmsubmit will list all the uploaded rules and also tell you if they have been injected into a class and if they have been triggered.

           

          If no agent is installed then the script will print a java.net.ConnectException saying that the connection has been refused.

           

          If the agent was started without option listener:true then you will not be able to talk to it using bmsubmit (so you will need to use method 3).

           

          Note: If there is an agent installed listening on socket 9091 then it will only be in one of the two tomcat servers. It is not possible for two agents to listen on the same socket. Also, bmsubmit will not tell you which tomcat server has byteman installed. If you want to know which process is listening you will need to list all open sockets (on Linux you can run command lsof) and find out the process id for socket 9091.

           

          Note: If the tomcat server might have been told to use a different socket (e.g. with -javaagent:${BYTEMAN_HOME}/lib/byteman.jar=listener:true,port:9999) then you will need to tell bmsubmit to try connecting to that socket (use the -p option: bmsubmit -p 9999).

           

          2) Byteman installed using bminstall

           

          If Byteman was installed after the java process was started using bminstall (script bminstall.bat on Windows and bminstall.sh on Linux) then the listener is always started and by default uses port 9091. So, testing for this will be the same as the first case. Use bmsubmit to talk to the agent and list all the rules and use lsof to find the owner process. If bminstall was passed argument -p 9999 then try running bmsubmit -p 9999.

           

          3) Not sure how Byteman might have been installed

           

          If you know the process id of the Tomcat processes then you should be able to detect the presence of a Byteman agent by querying the System properties of the JVM. If a Byteman agent has been loaded then it will set System property org.jboss.byteman.agent.loaded with value true.

           

          $ jcmd -l

          12345 org.apache.catalina.startup.Bootstrap

          $ jcmd 12345 VM.system_properties | grep org.jboss.byteman.agent.loaded

          . . .

           

          This does not guarantee whether an agent has been loaded because the property could be set or removed by application code (or by another agent). However, if it is set then it is very likely that a Byteman agent is present and if no such property exists then it is very likely that no Byteman agent has been loaded.

           

          regards,

           

           

          Andrew Dinn

          1 of 1 people found this helpful
          • 2. Re: is there any method can show byteman instance and submitted scripts
            xiang2513982

            Thank you for your answer, it's very detailed and useful.  

             

            Do you know more about getting the list of  submitted scripts?

             

            byteman is easy to use when there is only one user, but if many people use it in one environment, it may be little messy.  I am wondering if there any solution to make it more convenient in this case

            • 3. Re: is there any method can show byteman instance and submitted scripts
              adinn

              Hi Liu Xiang,

               

              xiang2513982  wrote:

               

              Thank you for your answer, it's very detailed and useful.  

               

              Do you know more about getting the list of  submitted scripts?

               

              byteman is easy to use when there is only one user, but if many people use it in one environment, it may be little messy.  I am wondering if there any solution to make it more convenient in this case

               

              You are very welcome.

               

              The only information you can get about submitted scripts is by running bmsubmit. It will print the rules, tell you which class they have been injected into and tell you whether the rule has been parsed and type checked (the listing actually says compiled). An example of how to list installed rules  is shown in the first Byteman tutorial.

               

              If you want to use Byteman in a multi-user of multi-JVM runtime then you need to specify a different listener port when you start up each JVM. Byteman does not provide any scripts or commands to help you manage multiple agents. HOwever, you can build your own using the scripts provided in the bin directory. The best thing to do is to write shell scripts which allocate and keep track of listener ports and ensure that everyone using the same machine starts and stops their JVMS and/or agent using these scripts:

               

                If you use the -javaagent option to start a JVM with Byteman then you can configure the listener port by adding =listener:true,port:NNNN after the path to the agent jar.

               

                Your scripts can call into the bminstall, bmsubmit and bmjava commands to install an agent, submit or unsubmit rules or run a Java progarm with the agent in place. They all accept argument -p NNNNN to tell them which port to use. I suggest you read the first Byteman tutorial for an example of how these commands work. Details are also available in the Byteman Programmers' Guide.

               

              regards,

               

               

              Andrew Dinn