More action with Struts 2
In a recent review of Struts 2 in Action, JW Blogger Oleg Mikheev notes that Struts 2 is "just a collection of extensions built upon WebWork, which is ultimately the right thing to learn before starting a Struts 2 project." While Struts 2 has some architectural flaws, Oleg calls WebWork well-designed, well-tested, and reliable. What are your experiences using Struts 2 and WebWork?

Also see "Hello World the WebWork way," a JavaWorld excerpt from WebWork in Action, by Patrick Lightbody and Jason Carreira.

Newsletter sign-up

Sign up for our technology specific newsletters.

Enterprise Java
View all newsletters

Email Address:

Access Windows Performance Monitor counters from Java, Part 2

Integrate NSClient4j with Java Management Extensions

NSClient4j is a pure Java API that provides simple and quick access to Windows Performance Monitor (WPM) statistics. These statistics prove invaluable for monitoring your Windows servers and providing a baseline for activities such as capacity planning and trouble shooting. Additionally, access to low-level performance or operating statistics can be useful in your low-level code, such as the current rate of GETS against your IIS (Internet Information Server) Web server.

In this article, the continuation of my series on WPM, I present a brief introduction to Java Management Extensions (JMX) and its benefits. I then explain how to implement JMX-based services for NSClient4j and describe different methods for implementing that technology.

Changes in NSClient4j since Part 1

As a brief aside, I want to enumerate some changes and enhancements that have been made in the NSClient4j package since Part 1 of this series:

  • The main package name has migrated from com.marketwide.nagios to org.nsclient4j.
  • Calls have been added to the NSClient4j class as convenience methods:
    1. getUsedDiskSpace(String diskVol)
    2. getFreeDiskSpace(String diskVol)
    3. getTotalDiskSpace(String diskVol)
    4. getUsedPercentDiskSpace(String diskVol)
    5. getFreePercentDiskSpace(String diskVol)
  • To accommodate NSClient4j implementation in the Oracle 9i internal JVM, the source code is now fully supported under J2SE 1.3.
  • Additional error handling identifies the cause of any errors emerging from the WPM engine (e.g., "Unrecognized pattern," or "Counter not found"), and the NSClient4JException has been extended to differentiate between transport errors and WPM errors.
  • New JMX-based classes provide JMX instrumentation of the WPM engine, which is this article's focus.


Recap of basic NSClient4j functionality

To provide a quick review of the NSClient4j functionality, the code below shows a few lines of Java code connecting to an NSClient server on a Windows host and acquiring the system's context-switch rate per second.

Listing 1. Source for CLStat, a simple NSClient4j example

 public class CLStat {
  public static void main(String[] args) {
    try {
      NSClient4j client = new NSClient4j("192.168.1.4", 1248);
      System.out.println("Result:" + client.getPerfMonCounter("\\System\\Context Switches/sec"));
    } catch (NSClient4JException e) {
      System.err.println("Exception Geting Stat:" + e);
    }
  }
}



Listing 2. Run the CLStat example

 c:\temp>set CLASSPATH=c:\nsclient4j-root\nsclient4j\dist\nsclient4j.jar;%CLASSPATH%

c:\temp>java org.nsclient4j.CLStat Result:4120.66700


Now that we have reviewed the basics of NSClient4j, let's look at JMX and how it can be implemented to support NSClient4j.

NSClient4j and JMX

The Java Management Extensions technology is a Java standard for building management and monitoring components for applications. Though NSClient4j provides a satisfactory low-level API for accessing WPM statistics (see Figure 1), a monitoring layer implemented in JMX provides both a higher standard of integration and compliance while significantly extending NSClient4j's functionality.

Discuss

Start a new discussion or jump into one of the threads below:

Subject Replies Last post
. Access Windows Performance Monitor counters
By JavaWorld
0 10/30/07 12:17 PM
by Anonymous
. deploy nsclient4j.sar to JBoss
By
0 05/24/07 05:09 PM
by Anonymous


Resources