Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicLongHow many per-rateRate.coalesce()calls have thrown.private final StringDescribes the stat.private ThrowableWhat first failed to write the stats file.private StringIdentity of the first rate that failed to coalesce, and its cause, so the log names which period of which stat is broken instead of only counting.private final StringGrouping under which the stat is kept.protected final Rate[]Actual rate objects for this statistic.private final StringUnique name of the statistic.private static final StringRule drawn between report sectionsprivate static final StringLine separator of the report file.Constructor Summary
Method Summary
Public MethodsModifier and TypeMethodDescriptionvoidaddData(long value) Update all of the rates for the various periods with the given value.voidaddData(long value, long eventDuration) Update all of the rates for the various periods with the given value.voidCoalesce every period's rate, isolating each one.booleancontainsRate(long period) Tests if a rate with the provided period exists within this RateStat.booleanObject to compare.(package private) longSum of the per-rate backlog collapse counts; seeRate.getCoalesceBacklogCollapses().longSum of the per-rate successful coalesce counts; seeRate.getCoalesceCount().(package private) longNumber of per-rate coalesce calls that have thrown since construction.(package private) longSum of the per-rate coalesce skip counts; seeRate.getCoalesceSkips().Description of what this rate stat measures.(package private) ThrowableThe cause of the first coalesce failure, for the log line.(package private) StringThe period of the first rate that failed to coalesce, or null if none has.Grouping name for this rate stat.doubleLifetime average from the shortest period.longLifetime event count from the shortest period.getName()Unique name for this rate stat.long[]Tracked periods for this rate.getRate(long period) Returns rate with requested period if it exists, otherwise null.getRecentSamples(int max) Retained coalesced samples for backfill, oldest first.inthashCode()voidload(Properties props, String prefix, boolean treatAsCurrent) Load this rate stat from the properties, populating all of the rates contained underneath it.(package private) booleanWhether the other stat shares name, group, and description.(package private) voidsetSampleDelivery(RateSampleDelivery delivery) Route coalesced samples for every rate in this stat throughdeliveryinstead of calling the summary listener inline.voidstore(OutputStream out, String prefix) Includes comment lines.voidstore(OutputStream out, String prefix, boolean addComments) Stores the rate statistics to an output stream.toString()
Field Details
_statName
Unique name of the statistic._groupName
Grouping under which the stat is kept._description
Describes the stat._rates
Actual rate objects for this statistic._coalesceFailures
How many per-rateRate.coalesce()calls have thrown. A rate that throws is skipped, never propagated: seecoalesceStats()._firstFailurePeriod
Identity of the first rate that failed to coalesce, and its cause, so the log names which period of which stat is broken instead of only counting._firstFailureCause
What first failed to write the stats file.NL
Line separator of the report file.HR
Constructor Details
RateStat
Unique name of the statistic.- Parameters:
name- unique name of the statisticdescription- simple description of the statisticgroup- used to group statistics togetherperiods- array of period lengths (in milliseconds), must not be empty- Throws:
IllegalArgumentException- if periods is empty
RateStat
Constructor taking pre-built rates, for tests that need a rate which throws.The public constructor cannot express this because it always builds working rates, and a
Ratecannot be made to fail without a fault injected into it. The isolation incoalesceStats()is only worth anything if it can be shown to hold when a rate really does throw.- Parameters:
name- unique name of the statisticdescription- simple description of the statisticgroup- used to group statistics togetherrates- the rates to coalesce, must not be empty- Throws:
IllegalArgumentException- if rates is empty
Method Details
setSampleDelivery
Route coalesced samples for every rate in this stat throughdeliveryinstead of calling the summary listener inline.Set by
StatManagerimmediately after construction. A setter rather than a constructor argument so the public constructor signature — and its callers — are unaffected.- Parameters:
delivery- the shared delivery queue, or null for inline delivery
getCoalesceSkips
long getCoalesceSkips()Sum of the per-rate coalesce skip counts; seeRate.getCoalesceSkips().- Returns:
- total coalesce skips across this stat's rates
getCoalesceCount
public long getCoalesceCount()Sum of the per-rate successful coalesce counts; seeRate.getCoalesceCount().- Returns:
- total coalesces across this stat's rates
getCoalesceBacklogCollapses
long getCoalesceBacklogCollapses()Sum of the per-rate backlog collapse counts; seeRate.getCoalesceBacklogCollapses().- Returns:
- total backlog collapses across this stat's rates
getRecentSamples
Retained coalesced samples for backfill, oldest first.Read from the shortest-period rate (
_rates[0], periods being held in ascending order) because that is the rate whose steps its RRD stores, and therefore the one a listener writing history has to replay.- Parameters:
max- the most samples to return, clamped by the rate's ring- Returns:
- an immutable list of at most
maxsamples, oldest first, never null
addData
public void addData(long value, long eventDuration) Update all of the rates for the various periods with the given value.- Parameters:
value- the sample value added to every period's rateeventDuration- the event duration
addData
public void addData(long value) Update all of the rates for the various periods with the given value. Zero duration.- Parameters:
value- the sample value added to every period's rate
coalesceStats
public void coalesceStats()Coalesce every period's rate, isolating each one.A rate that throws must not stop its siblings.
StatManagerwalks every stat in one pass on the coalesce timer, so an exception escaping here would abandon every stat later in that pass: their rates would silently stop coalescing, their listeners would stop receiving samples, and their graphs would freeze with nothing logged anywhere - which is exactly the failure this method exists to make impossible.The first failure is remembered with the period that produced it, so
StatManagercan name the offending stat rather than only counting anonymous failures.getCoalesceFailures
long getCoalesceFailures()Number of per-rate coalesce calls that have thrown since construction.- Returns:
- the running failure count
getFirstCoalesceFailurePeriod
String getFirstCoalesceFailurePeriod()The period of the first rate that failed to coalesce, or null if none has.- Returns:
- the failing rate's period in ms, or null
getFirstCoalesceFailureCause
Throwable getFirstCoalesceFailureCause()The cause of the first coalesce failure, for the log line.- Returns:
- the first failure's throwable, or null
getName
getGroupName
Grouping name for this rate stat.- Returns:
- the grouping name under which this statistic is kept
getDescription
Description of what this rate stat measures.- Returns:
- a simple description of this statistic
getPeriods
public long[] getPeriods()Tracked periods for this rate.- Returns:
- the periods this rate is tracked over, in milliseconds
getLifetimeAverageValue
public double getLifetimeAverageValue()Lifetime average from the shortest period.- Returns:
- the lifetime average value from the shortest period's rate
getLifetimeEventCount
public long getLifetimeEventCount()Lifetime event count from the shortest period.- Returns:
- the lifetime event count from the shortest period's rate
getRate
Returns rate with requested period if it exists, otherwise null.- Parameters:
period- the rate period, in milliseconds- Returns:
- the Rate whose period equals this one exactly, or null
containsRate
public boolean containsRate(long period) Tests if a rate with the provided period exists within this RateStat.- Parameters:
period- the rate period, in milliseconds- Returns:
- true if exists
hashCode
toString
equals
nameGroupDescEquals
Whether the other stat shares name, group, and description.- Parameters:
rs- the other RateStat- Returns:
- true if both stats carry the same group name, description and stat name
store
Includes comment lines.- Parameters:
out- the output streamprefix- the property prefix- Throws:
IOException- if an I/O error occurs
store
Stores the rate statistics to an output stream.- Parameters:
out- the output streamprefix- the property prefixaddComments- add comment lines to the output- Throws:
IOException- if an I/O error occurs
load
public void load(Properties props, String prefix, boolean treatAsCurrent) throws IllegalArgumentException Load this rate stat from the properties, populating all of the rates contained underneath it. The comes from the given prefix (e.g. if we are given the prefix "profile.dbIntroduction", a series of rates may be found underneath "profile.dbIntroduction.60s", "profile.dbIntroduction.60m", and "profile.dbIntroduction.24h"). This RateStat must already be created, with the specified rate entries constructed - this merely loads them with data.- Parameters:
props- the properties holding the prefixed rate entries to readprefix- prefix to the property entries (should NOT end with a period)treatAsCurrent- if true, we'll treat the loaded data as if no time has elapsed since it was written out, but if it is false, we'll treat the data with as much freshness (or staleness) as appropriate.- Throws:
IllegalArgumentException- if the data was formatted incorrectly