org.apache.cassandra.analytics
Class AnalyticsContext

java.lang.Object
  extended by org.apache.cassandra.analytics.AnalyticsContext
All Implemented Interfaces:
IComponentShutdown

public class AnalyticsContext
extends java.lang.Object
implements IComponentShutdown

Context for sending metrics to Ganglia. This class drives the entire metric collection process. Author : Avinash Lakshman ( alakshman@facebook.com) & Prashant Malik ( pmalik@facebook.com ) & Karthik Ranganathan ( kranganathan@facebook.com )


Constructor Summary
AnalyticsContext()
          Creates a new instance of AnalyticsReporter
 
Method Summary
 void close()
          Stops monitoring and frees buffered data, returning this object to its initial state.
 void createRecord(java.lang.String recordName)
          Creates a new AbstractMetricsRecord instance with the given recordName.
 void emitRecord(java.lang.String recordName, OutputRecord outRec)
          Sends a record to the metrics system.
protected  void flush()
          Called each period after all records have been emitted, this method does nothing.
 java.lang.String getAttribute(java.lang.String attributeName)
          Returns the value of the named attribute, or null if there is no attribute of that name.
 java.lang.String[] getAttributeNames()
          Returns the names of all the factory's attributes.
protected  java.util.Map<java.lang.String,java.lang.String> getAttributeTable(java.lang.String tableName)
          Returns an attribute-value map derived from the factory attributes by finding all factory attributes that begin with contextName.tableName.
 MetricsRecord getMetricsRecord(java.lang.String recordName)
          Return the MetricsRecord associated with this record name.
 int getPeriod()
          Returns the timer period.
 void init(java.lang.String contextName, java.lang.String serverSpecList)
          Initializes the context.
static AnalyticsContext instance()
          Factory method that gets an instance of the StorageService class.
 boolean isMonitoring()
          Returns true if monitoring is currently in progress.
 void registerUpdater(IAnalyticsSource updater)
          Registers a callback to be called at time intervals determined by the configuration.
protected  void remove(MetricsRecord record)
          Called by MetricsRecordImpl.remove().
 void removeAttribute(java.lang.String attributeName)
          Removes the named attribute if it exists.
 void setAttribute(java.lang.String attributeName, java.lang.Object value)
          Sets the named factory attribute to the specified value, creating it if it did not already exist.
protected  void setPeriod(int period)
          Sets the timer period
 void setPort(int port)
          Sets the default port to listen on
 void shutdown()
          Stops timer if it is running
 void start()
          Starts up the analytics context and registers the VM metrics.
 void startMonitoring()
          Starts or restarts monitoring, the emitting of metrics records.
 void stop()
           
 void stopMonitoring()
          Stops monitoring.
 void unregisterUpdater(IAnalyticsSource updater)
          Removes a callback, if it exists.
protected  void update(MetricsRecord record)
          Called by MetricsRecordImpl.update().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnalyticsContext

public AnalyticsContext()
Creates a new instance of AnalyticsReporter

Method Detail

init

public void init(java.lang.String contextName,
                 java.lang.String serverSpecList)
Initializes the context.


emitRecord

public void emitRecord(java.lang.String recordName,
                       OutputRecord outRec)
                throws java.io.IOException
Sends a record to the metrics system.

Throws:
java.io.IOException

getAttributeNames

public java.lang.String[] getAttributeNames()
Returns the names of all the factory's attributes.

Returns:
the attribute names

setAttribute

public void setAttribute(java.lang.String attributeName,
                         java.lang.Object value)
Sets the named factory attribute to the specified value, creating it if it did not already exist. If the value is null, this is the same as calling removeAttribute.

Parameters:
attributeName - the attribute name
value - the new attribute value

removeAttribute

public void removeAttribute(java.lang.String attributeName)
Removes the named attribute if it exists.

Parameters:
attributeName - the attribute name

getAttribute

public java.lang.String getAttribute(java.lang.String attributeName)
Returns the value of the named attribute, or null if there is no attribute of that name.

Parameters:
attributeName - the attribute name
Returns:
the attribute value

getAttributeTable

protected java.util.Map<java.lang.String,java.lang.String> getAttributeTable(java.lang.String tableName)
Returns an attribute-value map derived from the factory attributes by finding all factory attributes that begin with contextName.tableName. The returned map consists of those attributes with the contextName and tableName stripped off.


startMonitoring

public void startMonitoring()
                     throws java.io.IOException
Starts or restarts monitoring, the emitting of metrics records.

Throws:
java.io.IOException

stopMonitoring

public void stopMonitoring()
Stops monitoring. This does not free buffered data.

See Also:
close()

isMonitoring

public boolean isMonitoring()
Returns true if monitoring is currently in progress.


close

public void close()
Stops monitoring and frees buffered data, returning this object to its initial state.


createRecord

public final void createRecord(java.lang.String recordName)
Creates a new AbstractMetricsRecord instance with the given recordName. Throws an exception if the metrics implementation is configured with a fixed set of record names and recordName is not in that set.

Parameters:
recordName - the name of the record
Throws:
AnalyticsException - if recordName conflicts with configuration data

getMetricsRecord

public MetricsRecord getMetricsRecord(java.lang.String recordName)
Return the MetricsRecord associated with this record name.

Parameters:
recordName - the name of the record
Returns:
newly created instance of MetricsRecordImpl or subclass

registerUpdater

public void registerUpdater(IAnalyticsSource updater)
Registers a callback to be called at time intervals determined by the configuration.

Parameters:
updater - object to be run periodically; it should update some metrics records

unregisterUpdater

public void unregisterUpdater(IAnalyticsSource updater)
Removes a callback, if it exists.

Parameters:
updater - object to be removed from the callback list

shutdown

public void shutdown()
Stops timer if it is running

Specified by:
shutdown in interface IComponentShutdown

flush

protected void flush()
              throws java.io.IOException
Called each period after all records have been emitted, this method does nothing. Subclasses may override it in order to perform some kind of flush.

Throws:
java.io.IOException

update

protected void update(MetricsRecord record)
Called by MetricsRecordImpl.update(). Creates or updates a row in the internal table of metric data.


remove

protected void remove(MetricsRecord record)
Called by MetricsRecordImpl.remove(). Removes any matching row in the internal table of metric data. A row matches if it has the same tag names and tag values.


getPeriod

public int getPeriod()
Returns the timer period.


setPeriod

protected void setPeriod(int period)
Sets the timer period


setPort

public void setPort(int port)
Sets the default port to listen on


start

public void start()
Starts up the analytics context and registers the VM metrics.


stop

public void stop()

instance

public static AnalyticsContext instance()
Factory method that gets an instance of the StorageService class.



Copyright © 2009 The Apache Software Foundation