Which Tomcat Mbean can be used to access web app information - java

I am trying to write a client tool which monitors an application running in Tomcat 5.5. I know there are quite a few already available but the majority of them are web based and dont provide a lot of support for automating the monitoring process.
The tool i am writing now is very simple. Its a client java process that connects to the Tomcat instance remotely. I have managed to connect to it but now i am stuck as to how to use the MBeans that are already available in Tomcat.
My question really is which Mbeans within Tomcat do i query to find out the following information
Whether a specific application running under a specific context is running
The health of the environment in general (tomcat, OS etc)
Whether a JNDI datasource is available and if possible how many active database connections there are and how many free.
Are there any MBeans that provide this info? if so how do i access it?
it would be very usefull to see a full list of all mbeans available in Tomcat and how to access them. I have seen this list http://tomcat.apache.org/tomcat-5.5-doc/catalina/funcspecs/mbean-names.html but it is quite confusing.
Thanks

You can use jConsole utility of Java to see the MBeans available in remote Tomcat server. It will connect to remote server with jmx port. All the MBeans available are listed in MBean tab. This can help you finding the MBeans you wants and exact name of the MBean attribute.
Thanks.

You could use the check_jmx4perl configuration with pre-defined Tomcat checks as a starting point. It references the names of quite some MBeans which can be found on a standard Tomcat installation.
I.e. the following metrics are pre-defined:
Nr. of servlet requests for a certain servlet
Processing CPU time for a webmodule
Check whether a webmodule is active
Active sessions
Max. number of active sessions
Number of rejected sessions
Average lifetime of a session
Max. lifetime of the longest session
Data received rate for a connector
Data sent rate for a connector
Processing time for a connector
Number of active datasource connections
You can find this sample tomcat.cfg configuration here: https://github.com/rhuss/jmx4perl/blob/master/config/tomcat.cfg

Related

Use Jolokia to monitor JMX endpoint of webapp on same Tomcat server

Jolokia is uncharted territory for me, and after having read the documentation, I'm still not sure if it'll work with the scenario I have in mind.
Setup:
Tomcat application server (version ranges from 6.x to 7.x), usually on a Windows platform, occasionally a flavour of Linux.
Deployed third-party Java web application (SAP BusinessObjects) with JMX monitoring enabled (accessible through RMI).
Possible gotcha's:
The Java web application to be monitored is commercial and closed source, so modifications are not possible. The only thing that can be changed is the JMX port number
The JMX endpoint is a custom one, thus not the default jmxrmi endpoint.
The JMX connection requires authentication.
Goal:
What I'd like to do is to deploy the Jolokia WAR file onto the Tomcat server and then configure it so that I can read the MBean attributes from the other web application.
I would code the client myself using Python (version 3) and the Requests HTTP library.
I've been reading through the Jolokia documentation (again, I'm a complete newbie at this point), but can't figure out if this would be possible or not (as I can't seem to find where to enter the JMX/RMI url or the authentication information).
Questions:
Can I use the WAR agent for this setup?
If not, can you please explain why (so I can understand, not because I don't believe you). Also, is there another agent that's more suited for this scenario?
If yes, can you point me in the right direction how to configure the Jolokia to the web application to connect to?
First of all, Jolokia by passes the JSR-160 connector stuff completely, so there is no need for any JMX/RMI authentication. The whole purpose of Jolokia is to provide a bridge over HTTP/JSON to the internal JMX subsystem. Depending on the agent, you can secure Jolokia quite easily. For the WAR agent, securing is the same as for any Java EE web app: Setup some roles and users for tomcat (e.g. in tomcat-users.xml) and reference the role in the security contstraints within the jolokia.war's /WEB-INF/web.xml.
To your questions:
Yes, you can. If you don't have any specific authentication needs, simply drop the jolokia.war into tomcat's /webapps directory. I suggest to try this first before adding security. For deinstalling the agent, simply remove the war.
As an alternative, you could also use the JVM agent, which opens an own HTTP server on an extra port (default: 8778). More on this in the reference manual
There is no need for a dedicated connection to the web app since MBeans are registered globally and are accesible from anywhere in the JVM. A webapp should of course select carefully the management information it exposes. So, there is no extra step needed and you can access the MBeans for the WEB app directly (except when it does something unusual with Java security, but I don't think so).
To test the installation, simply connect to the Tomcat with your browser and the context /jolokia (e.g. "http://localhost:8080/jolokia"). You should see the version information about the agent itself.
The next step would be to explore the JMX namespace, either with the browser (and operation "list" like in http://localhost:8080/jolokia/list , but that's tedious) or with a client like j4psh or hawt.io. Hopefully you will find the MBeans of your webapp you are looking for.

convert weblogic admin server into managed server

I'm currently having 2 Weblogic admin servers in 2 different domains created on the same machine.
I want to convert one of the admin server to a managed server and then use them together to deploy a Java application. Is this feasible? If yes, how?
I'm currently using Weblogic Server 10.3.
PS: I'm quite new to Weblogic domain creation and administration. Please revert for any more details needed.
The simple answer is no, however, adding a managed server to a domain is extremely simple. See the documentation here. When deploying your application you'll need to target both servers or create a cluster (also very easy), add both machines to it and give the cluster name as the target.
Note, it is generally not concidered best practice to target applications to the Admin server (although it's fine when you're developing on your local machine). If you have the resources available on your environment, you could create two managed servers and put them in a cluster. Depending on the configuration of your Admin server, you may be able to reduce it's size if memory is tight.

Spring 3 Web MVC with JMX client and remote service not running

The problem is relatively simple:
I have a web based application, that, among other things, needs to check for status of a remote service. This remote service has JMX based mbeans exposed. However, the remote service might be not running all the time. What I need is:
Setup Spring to connect to remote JMX server
When the remote is not running, present this information in the web ui
The problem with this is that if I setup the JMX client bean in springContext.xml and the service is not running, the webapp won't even start with exceptions like ConnectionRefused and so on.
So the question is: is there a way I can tell spring to ignore the fact that it cannot connect to remote mbean server and try it later?
I am assuming you are using the MBeanServerConnectionFactoryBean? Set the connectOnStartup property to false.

Missing Websphere NodeAgent JMX MBean

I am trying to run the sample code from IBM (sample code link) to connect to Websphere Application Server v7.0 through a JMX client.
I could successfully connect to the Websphere MBeanServer by jconsole, and could see two domains exist (JMImplementation and WebSphere). However, I found that there is no NodeAgent MBean as specified in the sample code with ObjectName pattern WebSphere:type=NodeAgent,node=<some node>,*.
Does anybody know why the NodeAgent MBean is not there?
You can run such query "WebSphere:*" - so you will get all mbeans you have in time of query evaluated. Just print it out to get expression what you actually have. For example i have only server and portal mbeans in my configuration and no nodeAgent. So this sample will not work in my environment too.
Which edition of WebSphere are you running? WebSphere Express does not include node agents or a deployment manager. WebSphere Network Deployment includes these components to support a variety of features. It's filled with marketing speak, but IBM has a PDF listing high-level differences between the various editions.

Connect visualvm to websphere 7

I am trying to get visualvm and websphere 7 to work together on my local windows desktop. I try to connect through JMX but no luck. Has anybody managed to get visialvm and websphere 7 to work and ow did you do it?
Regards
FF
I got it to work with the help of the VisualVM team in Praha (Thanks Tomas!):
1) On the admin console (Click on Servers -> Server types -> WebSphere application servers -> server1 -> Java and Process Management -> Process definition -> Java Virtual Machine), add the following line into the field of
Generic JVM Argument (note that the first system property is equal to
nothing and no equal sign for the second system property):
-Djavax.management.builder.initial= -Dcom.sun.management.jmxremote
2) Add or uncomment the following three lines in file /opt/IBM/
WebSphere/AppServer/java/jre/lib/management/management.properties
(or / lib/management/management.properties):
com.sun.management.jmxremote.port=3333
com.sun.management.jmxremote.authenticate=false
com.sun.management.jmxremote.ssl=false
com.sun.management.jmxremote.local.only=false
3) Connect VisualVM!
It is possible to set these parameters port, authenticate and ssl as JVM Arguments like -Dcom.sun.management.jmxremote.port=1300
I have another issue: by using the mbean visualvm plugin I can not see any relevant Websphere mbean.
It depends on what you want to achieve and the constraints you have. What you need to know is that there are two MBean servers in WebSphere: in addition to the platform MBean server created automatically by the JRE, WebSphere also creates its own MBean server. Here are the two options you have:
Configure your WebSphere server as described in the answer given by user271858. This will allow you to connect to the platform MBean server. You will get access to the standard platform MBeans that provide process information (RAM, CPU, threads, etc.). On the other hand, you won't be able to access WebSphere's MBeans (implementing certain administrative actions, providing application metrics, etc.). You also need to be aware that by changing the configuration of the WebSphere server, you bypass WebSphere's security.
Connect to WebSphere's MBean server. WebSphere supports several protocols to do that (mainly SOAP and RMI), but none of them is completely standard. This means that you will need to add some of the WebSphere libraries (namely the admin thin client) to VisualVM. It is probably possible to do that (It works with JConsole, so in principle it should be possible with VisualVM as well), but it's tricky, especially it you need to connect to a WebSphere server that has security enabled.
A simpler option is to install the VisualWAS plugin into VisualVM. It relies on an Open Source implementation of one of the proprietary WebSphere protocols and therefore doesn't require any additional WebSphere library.
This will give you access to MBeans registered in WebSphere's MBean server, but not to the standard platform MBeans, i.e. the relevant parts (related to memory, CPU and threads) in VisualVM will be disabled. You can however cross-register the platform MBeans in WebSphere's MBean server, and the VisualWAS project provides a solution for this as well (in the form of a plugin to be installed into WebSphere). You will then have access to all features in VisualVM, and you don't need to bypass WebSphere's security.

Categories