com.twitter.common.stats
Class RequestStats

java.lang.Object
  extended by com.twitter.common.stats.RequestStats
All Implemented Interfaces:
StatsProvider.RequestTimer

public class RequestStats
extends Object
implements StatsProvider.RequestTimer

A class to represent the statistics associated with a client connection to an external service. Tracks request latency/rate, and error rate.


Constructor Summary
RequestStats(String name)
          Creates a new request statistics object, using the default percentiles and sampling rate.
RequestStats(String name, Percentile<Long> percentile)
          Creates a new request statistics object using a custom percentile tracker.
 
Method Summary
 long getErrorCount()
           
 AtomicLong getErrorCounter()
           
 Percentile<Long> getPercentile()
           
 long getReconnectCount()
           
 AtomicLong getReconnectCounter()
           
 SlidingStats getSlidingStats()
           
 long getTimeoutCount()
           
 AtomicLong getTimeoutCounter()
           
 void incErrors()
          Accumulates the error counter and the request counter.
 void incErrors(long latencyMicros)
          Accumulates the error counter, the request counter and the request latency.
 void incReconnects()
          Accumulates the reconnect counter.
 void incTimeouts()
          Accumulates the timtout counter.
 void requestComplete(long latencyMicros)
          Accumulates a request and its latency.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RequestStats

public RequestStats(String name)
Creates a new request statistics object, using the default percentiles and sampling rate.

Parameters:
name - The unique name for this request type.

RequestStats

public RequestStats(String name,
                    @Nullable
                    Percentile<Long> percentile)
Creates a new request statistics object using a custom percentile tracker.

Parameters:
name - The unique name for this request type.
percentile - The percentile tracker, or null to disable percentile tracking.
Method Detail

getSlidingStats

public SlidingStats getSlidingStats()

getErrorCounter

public AtomicLong getErrorCounter()

getReconnectCounter

public AtomicLong getReconnectCounter()

getTimeoutCounter

public AtomicLong getTimeoutCounter()

getPercentile

public Percentile<Long> getPercentile()

requestComplete

public void requestComplete(long latencyMicros)
Accumulates a request and its latency.

Specified by:
requestComplete in interface StatsProvider.RequestTimer
Parameters:
latencyMicros - The elapsed time required to complete the request.

incErrors

public void incErrors()
Accumulates the error counter and the request counter.

Specified by:
incErrors in interface StatsProvider.RequestTimer

incErrors

public void incErrors(long latencyMicros)
Accumulates the error counter, the request counter and the request latency.

Parameters:
latencyMicros - The elapsed time before the error occurred.

incReconnects

public void incReconnects()
Accumulates the reconnect counter.

Specified by:
incReconnects in interface StatsProvider.RequestTimer

incTimeouts

public void incTimeouts()
Accumulates the timtout counter.

Specified by:
incTimeouts in interface StatsProvider.RequestTimer

getErrorCount

public long getErrorCount()

getReconnectCount

public long getReconnectCount()

getTimeoutCount

public long getTimeoutCount()