net.opentsdb.stats
public abstract class StatsCollector extends Object
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.
Modifier and Type | Field and Description |
---|---|
protected HashMap<String,String> |
extratags
Extra tags to add to every data point emitted.
|
protected String |
prefix
Prefix to add to every metric name, for example `tsd'.
|
Constructor and Description |
---|
StatsCollector(String prefix)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addExtraTag(String name,
String value)
Adds a tag to all the subsequent data points recorded.
|
void |
addHostTag(boolean canonical)
Adds a
host=hostname tag. |
void |
clearExtraTag(String name)
Clears a tag added using
addExtraTag . |
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.
|
protected final String prefix
public StatsCollector(String prefix)
prefix
- A prefix to add to every metric name, for example
`tsd'.public void emit(String datapoint)
datapoint
- A data point in a format suitable for a text
import.IllegalStateException
- if the emitter has not been implementedpublic final void record(String name, long value)
name
- The name of the metric.value
- The current value for that metric.public final void record(String name, Number value)
name
- The name of the metric.value
- The current value for that metric.public final void record(String name, Number value, String xtratag)
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
).IllegalArgumentException
- if xtratag != null
and it
doesn't follow the name=value
format.public final void record(String name, Histogram histo, String xtratag)
Histogram
.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
).IllegalArgumentException
- if xtratag != null
and it
doesn't follow the name=value
format.public void record(String name, long value, String xtratag)
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
).IllegalArgumentException
- if xtratag != null
and it
doesn't follow the name=value
format.public final void addExtraTag(String name, String value)
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.
name
- The name of the tag.value
- The value of the tag.IllegalArgumentException
- if the name or the value are empty
or otherwise invalid.clearExtraTag(java.lang.String)
public final void addHostTag(boolean canonical)
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.
canonical
- Whether or not we should try to get the FQDN of the host.
If set to true, the tag changes to "fqdn" instead of "host"public final void clearExtraTag(String name)
addExtraTag
.name
- The name of the tag to remove from the set of extra
tags.IllegalStateException
- if there's no extra tag currently
recorded.IllegalArgumentException
- if the given name isn't in the
set of extra tags currently recorded.addExtraTag(java.lang.String, java.lang.String)