Simple tool to monitor a Tomcat server using JMX

Deadly 提交于 2019-11-29 15:43:39

问题


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?


回答1:


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.




回答2:


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!