org.apache.hadoop.metrics.file
Class FileContext

java.lang.Object
  extended by org.apache.hadoop.metrics.spi.AbstractMetricsContext
      extended by org.apache.hadoop.metrics.file.FileContext
All Implemented Interfaces:
MetricsContext

public class FileContext
extends AbstractMetricsContext

Metrics context for writing metrics to a file.

This class is configured by setting ContextFactory attributes which in turn are usually configured through a properties file. All the attributes are prefixed by the contextName. For example, the properties file might contain:

 myContextName.fileName=/tmp/metrics.log
 myContextName.period=5
 


Field Summary
protected static String FILE_NAME_PROPERTY
           
protected static String PERIOD_PROPERTY
           
 
Fields inherited from interface org.apache.hadoop.metrics.MetricsContext
DEFAULT_PERIOD
 
Constructor Summary
FileContext()
          Creates a new instance of FileContext
 
Method Summary
 void emitRecord(String contextName, String recordName, OutputRecord outRec)
          Emits a metrics record to a file.
 void flush()
          Flushes the output writer, forcing updates to disk.
 String getFileName()
          Returns the configured file name, or null.
 void init(String contextName, ContextFactory factory)
          Initializes the context.
 void startMonitoring()
          Starts or restarts monitoring, by opening in append-mode, the file specified by the fileName attribute, if specified.
 void stopMonitoring()
          Stops monitoring, closing the file.
 
Methods inherited from class org.apache.hadoop.metrics.spi.AbstractMetricsContext
close, createRecord, getAttribute, getAttributeTable, getContextFactory, getContextName, getPeriod, isMonitoring, newRecord, registerUpdater, remove, setPeriod, unregisterUpdater, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILE_NAME_PROPERTY

protected static final String FILE_NAME_PROPERTY
See Also:
Constant Field Values

PERIOD_PROPERTY

protected static final String PERIOD_PROPERTY
See Also:
Constant Field Values
Constructor Detail

FileContext

public FileContext()
Creates a new instance of FileContext

Method Detail

init

public void init(String contextName,
                 ContextFactory factory)
Description copied from class: AbstractMetricsContext
Initializes the context.

Overrides:
init in class AbstractMetricsContext

getFileName

public String getFileName()
Returns the configured file name, or null.


startMonitoring

public void startMonitoring()
                     throws IOException
Starts or restarts monitoring, by opening in append-mode, the file specified by the fileName attribute, if specified. Otherwise the data will be written to standard output.

Specified by:
startMonitoring in interface MetricsContext
Overrides:
startMonitoring in class AbstractMetricsContext
Throws:
IOException

stopMonitoring

public void stopMonitoring()
Stops monitoring, closing the file.

Specified by:
stopMonitoring in interface MetricsContext
Overrides:
stopMonitoring in class AbstractMetricsContext
See Also:
AbstractMetricsContext.close()

emitRecord

public void emitRecord(String contextName,
                       String recordName,
                       OutputRecord outRec)
Emits a metrics record to a file.

Specified by:
emitRecord in class AbstractMetricsContext

flush

public void flush()
Flushes the output writer, forcing updates to disk.

Overrides:
flush in class AbstractMetricsContext


Copyright © 2008 The Apache Software Foundation