Re: Use JMX to manage applications
In addition to my questinos below, is mbeans-descriptors.xml a Tomcat-specific file or part of JMX in general? I can't tell - it seems to appear in links like the following: http://commons.apache.org/modeler/apidocs/org/apache/commons/modeler/package-summary.html But its DTD is under commons.apache.org - so is this specific to an Apache JMX implementation, part of JMX, or something else? lightbulb432 wrote: > > The following link describes using JMX with Tomcat. Step #4 talks about > the mbeans-descriptors.xml file, but it seems to make no difference when > using it. If I don't include elements in that file that I do in MBean > interface, it still works in JConsole properly - and the descriptions > entered don't seem to show up in JConsole either. > > http://oss.wxnet.org/mbeans.html > > Also, things like the "writeable" property and the "type" property that > are specified in this file could easily be determined from the MBean > interface, from return types, whether a getter has a corresponding setter, > etc. Then what is the use of this file if updating it to keep in sync with > the MBean interface makes no difference? Is it necessary to begin with? > > Thanks. > > > > > lightbulb432 wrote: >> >> How, from a web application deployed to Tomcat, can you customize the >> behavior of your web application based on attributes specified in an >> MBean? The link http://tomcat.apache.org/tomcat-6.0-doc/monitoring.html >> talks a lot about Ant tasks, but that's not really what I'm looking to >> do. >> >> How can you get programmatic access to MBeans? And how do you deploy >> MBeans to Tomcat? >> >> I'm pretty confused here...hopefully someone can clarify. Thanks. >> > > -- View this message in context: http://www.nabble.com/Use-JMX-to-manage-applications-tf3978363.html#a12319486 Sent from the Tomcat - User mailing list archive at Nabble.com. - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Use JMX to manage applications
The following link describes using JMX with Tomcat. Step #4 talks about the mbeans-descriptors.xml file, but it seems to make no difference when using it. If I don't include elements in that file that I do in MBean interface, it still works in JConsole properly - and the descriptions entered don't seem to show up in JConsole either. http://oss.wxnet.org/mbeans.html Also, things like the "writeable" property and the "type" property that are specified in this file could easily be determined from the MBean interface, from return types, whether a getter has a corresponding setter, etc. Then what is the use of this file if updating it to keep in sync with the MBean interface makes no difference? Is it necessary to begin with? Thanks. lightbulb432 wrote: > > How, from a web application deployed to Tomcat, can you customize the > behavior of your web application based on attributes specified in an > MBean? The link http://tomcat.apache.org/tomcat-6.0-doc/monitoring.html > talks a lot about Ant tasks, but that's not really what I'm looking to do. > > How can you get programmatic access to MBeans? And how do you deploy > MBeans to Tomcat? > > I'm pretty confused here...hopefully someone can clarify. Thanks. > -- View this message in context: http://www.nabble.com/Use-JMX-to-manage-applications-tf3978363.html#a12301485 Sent from the Tomcat - User mailing list archive at Nabble.com. - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Use JMX to manage applications
On 8/23/07, lightbulb432 <[EMAIL PROTECTED]> wrote: > > > What is the preferred API for accessing MBeans from within servlets or > JSPs? > > MBeanServerConnection jmxServerConnection = JMXConnectorFactory.connect > (new > JMXServiceURL(urlForJMX),null).getMBeanServerConnection(); > jmxServerConnection.getAttribute(new > ObjectName("Application:Name=Server,Type=Server"),"myAttribute"); This code can connect to an MBeanServer which need not be in the same JVM as your Servlet and you may need to provide authorization credentials to get connected. OR > > MBeanServer server = (MBeanServer) > MBeanServerFactory.findMBeanServer(null).get(0); > AttributeList list = server.getAttributes(new > ObjectName("Application:Name=Server,Type=Server"),"myAttribute"); This code looks up MBeanServers in the same JVM as your Servlet. They both have roughly the same amount of code and do the same thing, so I'm > wondering which is the preferred way. Unfortunately, you can't really > abstract away the mechanism of getting the MBeanServer because one uses a > MBeanServer while the other way uses the MBeanServerConnection object from > which to perform other methods. > > The only tradeoff I can see is that the first way requires knowing the JMX > connection URL which may need to be changed if, for example, the JXM port > number is changed. However, the second way may return multiple > MBeanServers, > right? > > In the second way, would you ever expect a List with more than one > MBeanServer to be returned? If so, how would that happen, and how would > your > code deal with it? > > Thanks. > > > > lightbulb432 wrote: > > > > How, from a web application deployed to Tomcat, can you customize the > > behavior of your web application based on attributes specified in an > > MBean? The link http://tomcat.apache.org/tomcat-6.0-doc/monitoring.html > > talks a lot about Ant tasks, but that's not really what I'm looking to > do. > > > > How can you get programmatic access to MBeans? And how do you deploy > > MBeans to Tomcat? > > > > I'm pretty confused here...hopefully someone can clarify. Thanks. > > > > -- > View this message in context: > http://www.nabble.com/Use-JMX-to-manage-applications-tf3978363.html#a12297804 > Sent from the Tomcat - User mailing list archive at Nabble.com. > > > - > To start a new topic, e-mail: users@tomcat.apache.org > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > >
Re: Use JMX to manage applications
What is the preferred API for accessing MBeans from within servlets or JSPs? MBeanServerConnection jmxServerConnection = JMXConnectorFactory.connect(new JMXServiceURL(urlForJMX),null).getMBeanServerConnection(); jmxServerConnection.getAttribute(new ObjectName("Application:Name=Server,Type=Server"),"myAttribute"); OR MBeanServer server = (MBeanServer) MBeanServerFactory.findMBeanServer(null).get(0); AttributeList list = server.getAttributes(new ObjectName("Application:Name=Server,Type=Server"),"myAttribute"); They both have roughly the same amount of code and do the same thing, so I'm wondering which is the preferred way. Unfortunately, you can't really abstract away the mechanism of getting the MBeanServer because one uses a MBeanServer while the other way uses the MBeanServerConnection object from which to perform other methods. The only tradeoff I can see is that the first way requires knowing the JMX connection URL which may need to be changed if, for example, the JXM port number is changed. However, the second way may return multiple MBeanServers, right? In the second way, would you ever expect a List with more than one MBeanServer to be returned? If so, how would that happen, and how would your code deal with it? Thanks. lightbulb432 wrote: > > How, from a web application deployed to Tomcat, can you customize the > behavior of your web application based on attributes specified in an > MBean? The link http://tomcat.apache.org/tomcat-6.0-doc/monitoring.html > talks a lot about Ant tasks, but that's not really what I'm looking to do. > > How can you get programmatic access to MBeans? And how do you deploy > MBeans to Tomcat? > > I'm pretty confused here...hopefully someone can clarify. Thanks. > -- View this message in context: http://www.nabble.com/Use-JMX-to-manage-applications-tf3978363.html#a12297804 Sent from the Tomcat - User mailing list archive at Nabble.com. - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Use JMX to manage applications
"Johnny Kewl" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi Again LightBulb, > > In this good article > http://www.javaworld.com/javaworld/jw-08-2005/jw-0801-jmx.html > You will find an example JMX client, in SRC for talking directly to > Tomcats JMXProxy > > One thing I dont see in the JMX interface, maybe it is there, is a way to > start stop webapp through JMX. > In the MBeans tab in Jconsole, under WebModules navigate down to the MBean of the webapp you want to stop, and in the Operations tab, choose "stop". Assuming that you aren't using a SecurityManager (or that you have granted permissions properly), then programatically you can do (assuming the default values for Engine and that Host is "localhost", etc): MBeanServer server=(MBeanServer)MBeanServerFactory.findMBeanServer(null).get(0); ObjectName myApp = new ObjectName("Catalina:j2eeType=WebModule,name=//localhost/myapp,J2EEApplication=none,J2EEServer=none"); server.invoke(myApp, "stop", null, null); Here, "Catalina" is the name of the enclosing Engine, "localhost" is the name of the enclosing Host, and "/myapp" is the path attribute of the webapp. If you are running Tomcat within a J2EE Server (e.g. JBoss), then you will have to find what it uses for the J2EE* values, or use the queryMBeans method on the MBeanServer ("none" is what Tomcat standalone uses by default). Of course, if you are using JMX to embed Tomcat (e.g. JBoss), then you use the same ON that you used to create the Context. > Just want to say, this thread made me have a good look at JMX in Tomcat, > an area I never bothered with before well done!... although I think > making JMX clients is too much hassle, looking at Tomcat through a > professional JMX client like JConsole is pure magic. > You know if there was just a screen shot of Tomcat in the JConsole on the > site, I think it would make people (like me) immediately see what a magic > facility this is. > > The other thought I had was that I think if TC scrapped the logging tools > it has now, in favour of an XML format, and a standard viewer, or any > other format one wanted if they set up a bit of XSL, I think logs would > look damn good in JConsole as well, would be easy to server through JMX, > or just in a web page. >From TC 5.5+, Tomcat doesn't handle logging (and nobody on [EMAIL PROTECTED] >has expressed much interest in changing this :). It is delegated to Juli or log4j to do the actual logging. For log4j, look at http://logging.apache.org, for Juli, look at the documentation from your Java vendor. > The current scheme seems to make them to hard to get at, which is > actually a bit weird considering the things are sitting in a web > server IMHO > > Have fun > > > > - Original Message - > From: "lightbulb432" <[EMAIL PROTECTED]> > To: > Sent: Monday, June 25, 2007 9:04 PM > Subject: Use JMX to manage applications > > >> >> How, from a web application deployed to Tomcat, can you customize the >> behavior of your web application based on attributes specified in an >> MBean? >> The link http://tomcat.apache.org/tomcat-6.0-doc/monitoring.html talks a >> lot >> about Ant tasks, but that's not really what I'm looking to do. >> >> How can you get programmatic access to MBeans? And how do you deploy >> MBeans >> to Tomcat? >> >> I'm pretty confused here...hopefully someone can clarify. Thanks. >> -- >> View this message in context: >> http://www.nabble.com/Use-JMX-to-manage-applications-tf3978363.html#a11293522 >> Sent from the Tomcat - User mailing list archive at Nabble.com. >> >> >> - >> To start a new topic, e-mail: users@tomcat.apache.org >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> For additional commands, e-mail: [EMAIL PROTECTED] >> >> > > > - > To start a new topic, e-mail: users@tomcat.apache.org > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Use JMX to manage applications
Hi Again LightBulb, In this good article http://www.javaworld.com/javaworld/jw-08-2005/jw-0801-jmx.html You will find an example JMX client, in SRC for talking directly to Tomcats JMXProxy One thing I dont see in the JMX interface, maybe it is there, is a way to start stop webapp through JMX. Just want to say, this thread made me have a good look at JMX in Tomcat, an area I never bothered with before well done!... although I think making JMX clients is too much hassle, looking at Tomcat through a professional JMX client like JConsole is pure magic. You know if there was just a screen shot of Tomcat in the JConsole on the site, I think it would make people (like me) immediately see what a magic facility this is. The other thought I had was that I think if TC scrapped the logging tools it has now, in favour of an XML format, and a standard viewer, or any other format one wanted if they set up a bit of XSL, I think logs would look damn good in JConsole as well, would be easy to server through JMX, or just in a web page. The current scheme seems to make them to hard to get at, which is actually a bit weird considering the things are sitting in a web server IMHO Have fun - Original Message - From: "lightbulb432" <[EMAIL PROTECTED]> To: Sent: Monday, June 25, 2007 9:04 PM Subject: Use JMX to manage applications How, from a web application deployed to Tomcat, can you customize the behavior of your web application based on attributes specified in an MBean? The link http://tomcat.apache.org/tomcat-6.0-doc/monitoring.html talks a lot about Ant tasks, but that's not really what I'm looking to do. How can you get programmatic access to MBeans? And how do you deploy MBeans to Tomcat? I'm pretty confused here...hopefully someone can clarify. Thanks. -- View this message in context: http://www.nabble.com/Use-JMX-to-manage-applications-tf3978363.html#a11293522 Sent from the Tomcat - User mailing list archive at Nabble.com. - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Use JMX to manage applications
Hi LightBulb, If you asking this, because of Robert Bowen question "Programmatically stop/start context" from WebApp, I also wait with anticipation for the JMX solution. I have a feeling that making a light weight JMX client that lives in a servlet, may not be that easy, we'll see what he comes up with. Its very quiet, so I'll volunteer an explanation, and get shot down in flames ;) but it gets the conversation going , normal procedure ;) You got this Servlet Management Interface to Tomcat and it calls into its OWN engine, and does stuff (like deploy start/stop) as well as provide other servlets like a JMX Proxy, that grab that JMX call, feeds in down to the MBean Server, and returns the XML to whatever made the call. BUT, there is another important management interface, that is not really talked about much, and its very to use and very powerful, and thats what you seeing in that article. http://tomcat.apache.org/tomcat-6.0-doc/monitoring.html If you start to think about how an IDE works its magic, and starts and stops, and deploys and undeploys you may at first think its talking to the manager servlets directly its not. In Tomcat there is another client Task engine, which acts as a client to the manager servlet. Netbeans in fact uses that, through ant. So in fact what is happening, is it calls into the CLIENT TASKS, they call the Manager Servlets (which can be located on any machine), and the job gets done. So for example if Robert Bowen emulated the management servlet, in his own servlet, he will ONLY be able to control the tomcat his servlet is in, and will end up also having to make these CLIENT TASKS. Now because I think its not that easy to make JMX clients, one of these CLIENT TASKS, is in fact a JMX client. So you or and IDE via ant, calls the JMX CLIENT TASK, the client task then does the JMX stuff for you and calls the SERVLET MANAGER... it does its thing, returns the REMOTE tomcat answer to the LOCAL tomcat, and the ant script gives it back to you. Now if you look at the little bit of code I gave Robert to start a server all I'm actually doing is bypassing ant, and calling the ant task directly, because who wants to use ant from a web-app, and note that I'm hitting the CLIENT TASKS, and that means it can control any server on any machine, not just my own. The guys rekon its kludgy, and they right because calling into Tomcat has versioning issues, but I think its pretty safe, because if they changed that interface, IDE control of tomcat would break... Netbeans wouldnt work with Tomcat. How did I get onto this just by looking at the ant script NB generates for tomcat. This interface you looking at, I think is more geared towards IDE control, than pure JMX, else I think there would be more emphasis on the client side, there isnt, because its in tomcat already. hope that helps - Original Message - From: "lightbulb432" <[EMAIL PROTECTED]> To: Sent: Monday, June 25, 2007 9:04 PM Subject: Use JMX to manage applications How, from a web application deployed to Tomcat, can you customize the behavior of your web application based on attributes specified in an MBean? The link http://tomcat.apache.org/tomcat-6.0-doc/monitoring.html talks a lot about Ant tasks, but that's not really what I'm looking to do. How can you get programmatic access to MBeans? And how do you deploy MBeans to Tomcat? I'm pretty confused here...hopefully someone can clarify. Thanks. -- View this message in context: http://www.nabble.com/Use-JMX-to-manage-applications-tf3978363.html#a11293522 Sent from the Tomcat - User mailing list archive at Nabble.com. - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]