org.jmonit
Class Monitoring

java.lang.Object
  extended by org.jmonit.Monitoring

public final class Monitoring
extends java.lang.Object

Monitoring is a convenience entry point in the jMonit API. It handles a default Repository and defines static methods for accessing monitors.

The add(String, long) method is designed to easily add any numeric value to the specified monitor.

 public String callMySaopService( Sring message )
 {
     long bytes = message.getBytes().length;
     Monitoring.add( "mySaopService.sent", bytes );
 
     String reply = service.call( message );
 
     bytes = reply.getBytes().length;
     Monitoring.add( "mySaopService.received", bytes );
 
     return reply;
 }
 

The start(..) methods can be used to quickly create a Probe and monitor time consumed in a block of code. Never forget to stop the returned Probe ! A try / finally block is the safer way to ensure this with fiew impact on performances :

 public void myBusinessMethod()
 {
     Probe probe = Monitoring.start( "myBusinessMethod" );
     try
     {
         // Some bunsiness code you want to monitor here...
     }
     finally
     {
         probe.stop();
     }
 }
 

Author:
Nicolas De Loof

Method Summary
static void add(java.lang.String name, long value)
          Add data to a monitor.
static Monitor getMonitor(java.lang.String name)
          Get an existing monitor or creates it.
static Repository getRepository()
           
static void setRepository(Repository repository)
          Replace the repository by a custom one.
static Stopwatch start(java.lang.String name)
          Start a new Stopwatch for the monitor 'name'.
static Stopwatch start(java.lang.String name, java.lang.String... tags)
          Start a new Stopwatch for the monitor 'name', and apply the tags to the monitor.
static Monitor tag(java.lang.String name, java.lang.String tag)
          Apply the specified tag to the specified monitor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

add

public static void add(java.lang.String name,
                       long value)
Add data to a monitor.

Parameters:
name - The monitor name
value - The value to be added (positive or negative)

getMonitor

public static Monitor getMonitor(java.lang.String name)
Get an existing monitor or creates it.

Parameters:
name - The monitor name
Returns:
the monitor

getRepository

public static Repository getRepository()
Returns:
the repository

setRepository

public static void setRepository(Repository repository)
Replace the repository by a custom one.

Parameters:
repository - the repository to set

start

public static Stopwatch start(java.lang.String name)
Start a new Stopwatch for the monitor 'name'.

Parameters:
name - The monitor name
Returns:
a Monitoring instance

start

public static Stopwatch start(java.lang.String name,
                              java.lang.String... tags)
Start a new Stopwatch for the monitor 'name', and apply the tags to the monitor.

Parameters:
name - The monitor name
tags - The tags to apply on the monitor
Returns:
a Monitoring instance

tag

public static Monitor tag(java.lang.String name,
                          java.lang.String tag)
Apply the specified tag to the specified monitor

Parameters:
name - monitor name
tag - tag
Returns:
the tagged monitor


Copyright © 2007 Nicolas De Loof. All Rights Reserved.