com.bigdata.counters
Class AbstractStatisticsCollector

java.lang.Object
  extended by com.bigdata.counters.AbstractStatisticsCollector
All Implemented Interfaces:
ICounterSetAccess, IStatisticsCollector
Direct Known Subclasses:
StatisticsCollectorForLinux, StatisticsCollectorForOSX, StatisticsCollectorForWindows

public abstract class AbstractStatisticsCollector
extends Object
implements IStatisticsCollector

Base class for collecting data on a host. The data are described by a hierarchical collection of ICounterSets and ICounters. A minimum set of counters is defined which SHOULD be available for decision-making. Implementations are free to report any additional data which they can make available. Reporting is assumed to be periodic, e.g., every 60 seconds or so. The purpose of these data is to support decision-making concerning the over- and under-utilization of hosts in support of load balancing of services deployed over those hosts.

An effort has been made to align the core set of counters for both Windows and Un*x platforms so as to support the declared counters on all platforms.

Author:
Bryan Thompson

Nested Class Summary
static interface AbstractStatisticsCollector.Options
          Options for AbstractStatisticsCollector
 
Field Summary
static String fullyQualifiedHostName
          InetAddress.getCanonicalHostName() for this host.
static String hostPathPrefix
          The path prefix under which all counters for this host are found.
protected  int interval
          Reporting interval in seconds.
protected static org.apache.log4j.Logger log
           
protected static String ps
           
 
Constructor Summary
protected AbstractStatisticsCollector(int interval, String processName)
           
 
Method Summary
static void addBasicServiceOrClientCounters(CounterSet serviceRoot, String serviceName, Class serviceIface, Properties properties)
          Adds the Info and Memory counter sets under the serviceRoot.
static void addGarbageCollectorMXBeanCounters(CounterSet counterSet)
          Adds/updates counters relating to JVM Garbage Collection.
static void addServiceProperties(CounterSet serviceInfoSet, Properties properties)
          Lists out all of the properties and then report each property using a OneShotInstrument.
 CounterSet getCounters()
          Return the counter hierarchy.
 int getInterval()
          The interval in seconds at which the counter values are read from the host platform.
static CounterSet getMemoryCounterSet()
          Return the memory counter set.
 String getProcessName()
          The name of the process (or more typically its service UUID) whose per-process performance counters are to be collected.
protected  void installShutdownHook()
          Installs a Runtime.addShutdownHook(Thread) that executes stop().
static Double kb2b(String kb)
          Converts KB to bytes.
static void main(String[] args)
          Utility runs the AbstractStatisticsCollector appropriate for your operating system.
static AbstractStatisticsCollector newInstance(Properties properties)
          Create an instance appropriate for the operating system on which the JVM is running.
 void start()
          Start collecting host performance data -- must be extended by the concrete subclass.
 void stop()
          Stop collecting host performance data -- must be extended by the concrete subclass.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ps

protected static final String ps
See Also:
Constant Field Values

log

protected static final org.apache.log4j.Logger log

fullyQualifiedHostName

public static final String fullyQualifiedHostName
InetAddress.getCanonicalHostName() for this host.


hostPathPrefix

public static final String hostPathPrefix
The path prefix under which all counters for this host are found.


interval

protected final int interval
Reporting interval in seconds.

Constructor Detail

AbstractStatisticsCollector

protected AbstractStatisticsCollector(int interval,
                                      String processName)
Method Detail

getInterval

public int getInterval()
The interval in seconds at which the counter values are read from the host platform.

Specified by:
getInterval in interface IStatisticsCollector

getProcessName

public String getProcessName()
The name of the process (or more typically its service UUID) whose per-process performance counters are to be collected.


getCounters

public CounterSet getCounters()
Return the counter hierarchy. The returned hierarchy only includes those counters whose values are available from the JVM. This collection is normally augmented with platform specific performance counters collected using an AbstractProcessCollector.

Note: Subclasses MUST extend this method to initialize their own counters.

Specified by:
getCounters in interface ICounterSetAccess

addBasicServiceOrClientCounters

public static void addBasicServiceOrClientCounters(CounterSet serviceRoot,
                                                   String serviceName,
                                                   Class serviceIface,
                                                   Properties properties)
Adds the Info and Memory counter sets under the serviceRoot.

Parameters:
serviceRoot - The CounterSet corresponding to the service (or client).
serviceName - The name of the service.
serviceIface - The class or interface that best represents the service or client.
properties - The properties used to configure that service or client.

getMemoryCounterSet

public static CounterSet getMemoryCounterSet()
Return the memory counter set. This should be attached to the service root.


addServiceProperties

public static void addServiceProperties(CounterSet serviceInfoSet,
                                        Properties properties)
Lists out all of the properties and then report each property using a OneShotInstrument.

Parameters:
serviceInfoSet - The ICounterHierarchy.Info CounterSet for the service.
properties - The properties to be reported out.

addGarbageCollectorMXBeanCounters

public static void addGarbageCollectorMXBeanCounters(CounterSet counterSet)
Adds/updates counters relating to JVM Garbage Collection. These counters should be located within a per-service path.

Parameters:
counterSet - The counters set that is the direct parent.

start

public void start()
Start collecting host performance data -- must be extended by the concrete subclass.

Specified by:
start in interface IStatisticsCollector

stop

public void stop()
Stop collecting host performance data -- must be extended by the concrete subclass.

Specified by:
stop in interface IStatisticsCollector

installShutdownHook

protected void installShutdownHook()
Installs a Runtime.addShutdownHook(Thread) that executes stop().

Note: The runtime shutdown hook appears to be a robust way to handle ^C by providing a clean service termination. However, under eclipse (at least when running under Windows) you may find that the shutdown hook does not run when you terminate a Java application and that typedef process build up in the Task Manager as a result. This should not be the case during normal deployment.


newInstance

public static AbstractStatisticsCollector newInstance(Properties properties)
Create an instance appropriate for the operating system on which the JVM is running.

Parameters:
properties - See AbstractStatisticsCollector.Options
Throws:
UnsupportedOperationException - If there is no implementation available on the operating system on which you are running.
See Also:
AbstractStatisticsCollector.Options

main

public static void main(String[] args)
                 throws InterruptedException
Utility runs the AbstractStatisticsCollector appropriate for your operating system. Before performance counter collection starts the static counters will be written on stdout. The appropriate process(es) are then started to collect the dynamic performance counters. Collection will occur every AbstractStatisticsCollector.Options.PERFORMANCE_COUNTERS_SAMPLE_INTERVAL seconds. The program will make 10 collections by default and will write the updated counters on stdout every AbstractStatisticsCollector.Options.PERFORMANCE_COUNTERS_SAMPLE_INTERVAL seconds.

Parameters also may be specified using -D. See AbstractStatisticsCollector.Options.

Parameters:
args - [interval [count]]

interval is the collection interval in seconds and defaults to AbstractStatisticsCollector.Options.DEFAULT_PERFORMANCE_COUNTERS_SAMPLE_INTERVAL.

count is the #of collections to be made and defaults to 10. Specify zero (0) to run until halted.

Throws:
InterruptedException
RuntimeException - if the arguments are not valid.
UnsupportedOperationException - if no implementation is available for your operating system.

kb2b

public static Double kb2b(String kb)
Converts KB to bytes.

Parameters:
kb - The #of kilobytes.
Returns:
The #of bytes.


Copyright © 2006-2011 SYSTAP, LLC. All Rights Reserved.