Java monitoring: JMX and servlets

In the past few years, I have learned a lot about JMX and built some very beautiful MBeans for my web applications But I'm not sure I have a good answer to a very basic question:

Why use JMX on a simple HTTP servlet?

My current web application provides redundant monitoring options: I can access the data that needs to be monitored through JMX through clients such as JMX, or I can access the same data in XML format through servlet I don't see a strong reason to use one method instead of another, but the servlet method does have the main advantage of being readable through a simple HTTP client / Web browser

I can see how JMX can be very useful for Java applications that are not web applications, but I don't think there is any advantage in using JMX for web applications

Solution

From my point of view, JMX is better for three reasons:

>It requires less code to enable monitoring points. > It handles end-to-end Java serialized objects, so it has better data consistency. > It applies to non servlet based programs (as you described)

JMX provides a simpler interface for specific data items You can certainly write the same functionality in many servlets, but it's easier for me to expose them using JMX

For example, if you are using spring, you can use org springframework. jmx. Export comments (@ managedresource, @ managedattribute, etc.) to mark your class I also released my simplejmx framework, so you can easily expose properties and operations through several spring independent annotations For example:

@JmxResource(domainName = "j256",objectName = "lookupCache")
public class LookupCache {

    // this can also be done as @JmxAttributeMethod on the getter/setters
    @JmxAttributeField(description = "Number of hits in the cache")
    private int hitCount;
    ...

    @JmxOperation(description = "Flush the cache")
    public void flushCache() {
       ...
    }
}

I have a fully working example program to see how it works Therefore, all you need to do to present values or operations is annotate the class and each property and / or method The code to publish it using simplejmx is as follows Although spring is similar to beans, it is similar:

// create a new server listening on port 8000
JmxServer jmxServer = new JmxServer(8000);
jmxServer.start();
// register our lookupCache object defined above
jmxServer.register(lookupCache);

To achieve similar functionality in servlets, you need more than just comments In other words, there may be some frameworks that provide similar functions in servlets, I don't know

There are also some notes:

>There may be better monitoring tools that can use HTTP / HTML, but there are also a large number of distributed JMX monitoring applications It could be a toss. > Being able to programmatically retrieve objects from JMX servers is an advantage, not just strings from servlet pages Simplejmx also supports simple JMX clients, although there are better JMX clients. > Obviously, the JVM publishes many other valuable data by default: VM settings, thread details, memory information, etc

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>