com.twitter.common.stats
Class Stats

java.lang.Object
  extended by com.twitter.common.stats.Stats

public class Stats
extends Object

Manages Stats that should be exported for monitoring. Statistic names may only contain [A-Za-z0-9_], all other chars will be logged as a warning and replaced with underscore on export.


Field Summary
static StatRegistry STAT_REGISTRY
          A StatRegistry that provides stats registered with the global Stats repository.
static StatsProvider STATS_PROVIDER
          A StatsProvider that exports gauge-style stats to the global Stats repository for time series tracking.
 
Constructor Summary
Stats()
           
 
Method Summary
static
<T extends Number>
Stat<T>
export(Stat<T> var)
          Exports a stat for tracking.
static AtomicInteger export(String name, AtomicInteger intVar)
          Exports an AtomicInteger, which will be included in time series tracking.
static AtomicLong export(String name, AtomicLong longVar)
          Exports an AtomicLong, which will be included in time series tracking.
static void exportAll(Iterable<Stat<? extends Number>> vars)
          Adds a collection of stats for export.
static AtomicInteger exportInt(String name)
          Creates and exports an AtomicInteger.
static AtomicInteger exportInt(String name, int initialValue)
          Creates and exports an AtomicInteger with initial value.
static AtomicLong exportLong(String name)
          Creates and exports an AtomicLong.
static AtomicLong exportLong(String name, long initialValue)
          Creates and exports an AtomicLong with initial value.
static void exportSize(String name, Cache<?,?> cache)
          Exports a metric that tracks the size of a cache.
static void exportSize(String name, Collection<?> collection)
          Exports a metric that tracks the size of a collection.
static void exportSize(String name, Map<?,?> map)
          Exports a metric that tracks the size of a map.
static
<T> Stat<T>
exportStatic(Stat<T> var)
          Exports a 'static' statistic, which will not be registered for time series tracking.
static Stat<String> exportString(Stat<String> var)
          Exports a string stat.
static void flush()
           
static
<T> Stat<T>
getVariable(String name)
           
static Iterable<Stat<?>> getVariables()
          Fetches all registered stat.
static String normalizeName(String name)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATS_PROVIDER

public static final StatsProvider STATS_PROVIDER
A StatsProvider that exports gauge-style stats to the global Stats repository for time series tracking.


STAT_REGISTRY

public static final StatRegistry STAT_REGISTRY
A StatRegistry that provides stats registered with the global Stats repository.

Constructor Detail

Stats

public Stats()
Method Detail

normalizeName

public static String normalizeName(String name)

export

public static <T extends Number> Stat<T> export(Stat<T> var)
Exports a stat for tracking. if the stat provided implements the internal RecordingStat interface, it will be registered for time series collection and returned. If a RecordingStat with the same name as the provided stat has already been exported, the previously-exported stat will be returned and no additional registration will be performed.

Type Parameters:
T - The value exported by the variable.
Parameters:
var - The variable to export.
Returns:
A reference to the stat that was stored. The stat returned may not be equal to the stat provided. If a variable was already returned with the same

exportString

public static Stat<String> exportString(Stat<String> var)
Exports a string stat. String-based statistics will not be registered for time series collection.

Parameters:
var - Stat to export.
Returns:
A reference back to var, or the variable that was already registered under the same name as var.

exportAll

public static void exportAll(Iterable<Stat<? extends Number>> vars)
Adds a collection of stats for export.

Parameters:
vars - The variables to add.

export

public static AtomicInteger export(String name,
                                   AtomicInteger intVar)
Exports an AtomicInteger, which will be included in time series tracking.

Parameters:
name - The name to export the stat with.
intVar - The variable to export.
Returns:
A reference to the AtomicInteger provided.

exportInt

public static AtomicInteger exportInt(String name)
Creates and exports an AtomicInteger.

Parameters:
name - The name to export the stat with.
Returns:
A reference to the AtomicInteger created.

exportInt

public static AtomicInteger exportInt(String name,
                                      int initialValue)
Creates and exports an AtomicInteger with initial value.

Parameters:
name - The name to export the stat with.
initialValue - The initial stat value.
Returns:
A reference to the AtomicInteger created.

export

public static AtomicLong export(String name,
                                AtomicLong longVar)
Exports an AtomicLong, which will be included in time series tracking.

Parameters:
name - The name to export the stat with.
longVar - The variable to export.
Returns:
A reference to the AtomicLong provided.

exportLong

public static AtomicLong exportLong(String name)
Creates and exports an AtomicLong.

Parameters:
name - The name to export the stat with.
Returns:
A reference to the AtomicLong created.

exportLong

public static AtomicLong exportLong(String name,
                                    long initialValue)
Creates and exports an AtomicLong with initial value.

Parameters:
name - The name to export the stat with.
initialValue - The initial stat value.
Returns:
A reference to the AtomicLong created.

exportSize

public static void exportSize(String name,
                              Collection<?> collection)
Exports a metric that tracks the size of a collection.

Parameters:
name - Name of the stat to export.
collection - Collection whose size should be tracked.

exportSize

public static void exportSize(String name,
                              Map<?,?> map)
Exports a metric that tracks the size of a map.

Parameters:
name - Name of the stat to export.
map - Map whose size should be tracked.

exportSize

public static void exportSize(String name,
                              Cache<?,?> cache)
Exports a metric that tracks the size of a cache.

Parameters:
name - Name of the stat to export.
cache - Cache whose size should be tracked.

exportStatic

public static <T> Stat<T> exportStatic(Stat<T> var)
Exports a 'static' statistic, which will not be registered for time series tracking.

Parameters:
var - Variable to statically export.
Returns:
A reference back to the provided Stat.

getVariables

public static Iterable<Stat<?>> getVariables()
Fetches all registered stat.

Returns:
An iterable of all registered stats.

flush

public static void flush()

getVariable

public static <T> Stat<T> getVariable(String name)