net.opentsdb.stats
Class StatsCollector

java.lang.Object
  extended by net.opentsdb.stats.StatsCollector

public abstract class StatsCollector
extends Object

Receives various stats/metrics from the current process.

Instances of this class are passed around to other classes to collect their stats/metrics and do something with them (presumably send them to a client).

This class does not do any synchronization and is not thread-safe.


Constructor Summary
StatsCollector(String prefix)
          Constructor.
 
Method Summary
 void addExtraTag(String name, String value)
          Adds a tag to all the subsequent data points recorded.
 void addHostTag()
          Adds a host=hostname tag.
 void clearExtraTag(String name)
          Clears a tag added using addExtraTag.
abstract  void emit(String datapoint)
          Method to override to actually emit a data point.
 void record(String name, Histogram histo, String xtratag)
          Records a number of data points from a Histogram.
 void record(String name, long value)
          Records a data point.
 void record(String name, long value, String xtratag)
          Records a data point.
 void record(String name, Number value)
          Records a data point.
 void record(String name, Number value, String xtratag)
          Records a data point.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StatsCollector

public StatsCollector(String prefix)
Constructor.

Parameters:
prefix - A prefix to add to every metric name, for example `tsd'.
Method Detail

emit

public abstract void emit(String datapoint)
Method to override to actually emit a data point.

Parameters:
datapoint - A data point in a format suitable for a text import.

record

public final void record(String name,
                         long value)
Records a data point.

Parameters:
name - The name of the metric.
value - The current value for that metric.

record

public final void record(String name,
                         Number value)
Records a data point.

Parameters:
name - The name of the metric.
value - The current value for that metric.

record

public final void record(String name,
                         Number value,
                         String xtratag)
Records a data point.

Parameters:
name - The name of the metric.
value - The current value for that metric.
xtratag - An extra tag (name=value) to add to those data points (ignored if null).
Throws:
IllegalArgumentException - if xtratag != null and it doesn't follow the name=value format.

record

public final void record(String name,
                         Histogram histo,
                         String xtratag)
Records a number of data points from a Histogram.

Parameters:
name - The name of the metric.
histo - The histogram to collect data points from.
xtratag - An extra tag (name=value) to add to those data points (ignored if null).
Throws:
IllegalArgumentException - if xtratag != null and it doesn't follow the name=value format.

record

public final void record(String name,
                         long value,
                         String xtratag)
Records a data point.

Parameters:
name - The name of the metric.
value - The current value for that metric.
xtratag - An extra tag (name=value) to add to this data point (ignored if null).
Throws:
IllegalArgumentException - if xtratag != null and it doesn't follow the name=value format.

addExtraTag

public final void addExtraTag(String name,
                              String value)
Adds a tag to all the subsequent data points recorded.

All subsequent calls to one of the record methods will associate the tag given to this method with the data point.

This method can be called multiple times to associate multiple tags with all the subsequent data points.

Parameters:
name - The name of the tag.
value - The value of the tag.
Throws:
IllegalArgumentException - if the name or the value are empty or otherwise invalid.
See Also:
clearExtraTag(java.lang.String)

addHostTag

public final void addHostTag()
Adds a host=hostname tag.

This uses InetAddress.getLocalHost() to find the hostname of the current host. If the hostname cannot be looked up, (unknown) is used instead.


clearExtraTag

public final void clearExtraTag(String name)
Clears a tag added using addExtraTag.

Parameters:
name - The name of the tag to remove from the set of extra tags.
Throws:
IllegalStateException - if there's no extra tag currently recorded.
IllegalArgumentException - if the given name isn't in the set of extra tags currently recorded.
See Also:
addExtraTag(java.lang.String, java.lang.String)