I am a computer science student currently doing an internship. My boss has asked me to write a simple tool to monitor a Tomcat server. I am just starting this project so I'm basically just playing around to see how things work. I would like to create a simple jsp page that displays the results of some basic JMX queries. I am using the Eclipse IDE. Can someone give me some tips to get started?
You definitely don't have to re-invent the wheel, here. You can start with jconsole
, which ships with your JDK: just run jconsole [pid]
and jconsole
will connect to the (locally) running process and let you observe everything via JMX.
If you want remote access to JMX-exposed information, you can use Tomcat's manager
webapp along with the included jmxproxy
servlet which allows you to remotely perform simple queries to get (and set) JMX properties.
There are other more fully-featured projects such as Jolokia ( http://www.jolokia.org/) that do similar kinds of things.
Assuming that you are using something like Nagios to automatically observe your Tomcat instance, something you definitely don't want to do it spin-up a JVM and make a remote (or even local) JMX connection to inspect a single JMX property (and then do that 5 times to observe 5 different properties, then do those 5 samples every 5 minutes, or 1 minute, or whatever). Instead, you probably want to use a proxy like one described above.
We've had great success coupling Nagios with the Tomcat manager's jmxproxy
servlet. It will likely meet your needs for quite a while.
In terms of programmatically using JMX, there are a number of client classes out there. Here's my SimpleJMX project. With it you can use the JmxClient
object to connect to and interrogate remote JVMs:
JmxClient client = new JmxClient("remote.sever.name", remotePortNumber);
Set<ObjectName> objectNameSet = client.getBeanNames();
...
Here are the javadocs for JmxClient.
来源:https://stackoverflow.com/questions/11057213/simple-tool-to-monitor-a-tomcat-server-using-jmx