public interface StatisticsFactory extends StatisticsTypeFactory
Statistics.
It can also be used to create instances of StatisticDescriptor
and StatisticsType because it implements StatisticsTypeFactory.
DistributedSystem is the only
instance of this interface.
A StatisticsFactory can create a statistic of three numeric types:
int, long, and double. A
statistic (StatisticDescriptor) can either be a
gauge meaning that its value can increase and decrease or a
counter meaning that its value is strictly increasing.
Marking a statistic as a counter allows statistic display tools
to properly display a statistics whose value "wraps around" (that
is, exceeds its maximum value).
The following code is an example of how to create a type using the api. In this example the type has two stats whose values always increase:
StatisticsFactory f = ...;
StatisticsType t = f.createType(
"StatSampler",
"Stats on the statistic sampler.",
new StatisticDescriptor[] {
f.createIntCounter("sampleCount",
"Total number of samples taken by this sampler.",
"samples"),
f.createLongCounter("sampleTime",
"Total amount of time spent taking samples.",
"milliseconds"),
}
);
this.samplerStats = f.createStatistics(t, "statSampler");
this.sampleCountId = this.samplerStats.nameToId("sampleCount");
this.sampleTimeId = this.samplerStats.nameToId("sampleTime");
Later on the stat ids can be used to increment the stats:
this.samplerStats.incInt(this.sampleCountId, 1);
this.samplerStats.incLong(this.sampleTimeId, nanosSpentWorking / 1000000);
The following is an example of how to create the same type using XML. The XML data:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE statistics PUBLIC
"-//GemStone Systems, Inc.//GemFire Statistics Type//EN"
"http://www.gemstone.com/dtd/statisticsType.dtd">
<statistics>
<type name="StatSampler">
<description>Stats on the statistic sampler.</description>
<stat name="sampleCount" storage="int" counter="true">
<description>Total number of samples taken by this sampler.</description>
<unit>samples</unit>
</stat>
<stat name="sampleTime" storage="long" counter="true">
<description>Total amount of time spent taking samples.</description>
<unit>milliseconds</unit>
</stat>
</type>
</statistics>
The code to create the type:
StatisticsFactory f = ...;
Reader r = new InputStreamReader("fileContainingXmlData"));
StatisticsType type = f.createTypesFromXml(r)[0];
MAX_DESCRIPTORS_PER_TYPE| Modifier and Type | Method and Description |
|---|---|
Statistics |
createAtomicStatistics(StatisticsType type)
Creates and returns a
Statistics instance of the given type with default ids. |
Statistics |
createAtomicStatistics(StatisticsType type,
java.lang.String textId)
|
Statistics |
createAtomicStatistics(StatisticsType type,
java.lang.String textId,
long numericId)
|
Statistics |
createStatistics(StatisticsType type)
Creates and returns a
Statistics instance of the given type with default ids. |
Statistics |
createStatistics(StatisticsType type,
java.lang.String textId)
|
Statistics |
createStatistics(StatisticsType type,
java.lang.String textId,
long numericId)
|
Statistics[] |
findStatisticsByNumericId(long numericId)
Returns an array of all the existing statistics with the given numericId.
|
Statistics[] |
findStatisticsByTextId(java.lang.String textId)
Returns an array of all the existing statistics with the given textId.
|
Statistics[] |
findStatisticsByType(StatisticsType type)
Returns an array of all the existing statistics of the given type.
|
createDoubleCounter, createDoubleCounter, createDoubleGauge, createDoubleGauge, createIntCounter, createIntCounter, createIntGauge, createIntGauge, createLongCounter, createLongCounter, createLongGauge, createLongGauge, createType, createTypesFromXml, findTypeStatistics createStatistics(StatisticsType type)
Statistics instance of the given type with default ids.
The created instance may not be atomic.
Statistics createStatistics(StatisticsType type, java.lang.String textId)
Statistics instance of the given type, textId, and with a default numeric id.
The created instance may not be atomic.
Statistics createStatistics(StatisticsType type, java.lang.String textId, long numericId)
Statistics instance of the given type, textId, and numericId.
The created instance may not be atomic.
Statistics createAtomicStatistics(StatisticsType type)
Statistics instance of the given type with default ids.
The created instance will be atomic.
Statistics createAtomicStatistics(StatisticsType type, java.lang.String textId)
Statistics instance of the given type, textId, and with a default numeric id.
The created instance will be atomic.
Statistics createAtomicStatistics(StatisticsType type, java.lang.String textId, long numericId)
Statistics instance of the given type, textId, and numericId.
The created instance will be atomic.
Statistics[] findStatisticsByType(StatisticsType type)
Statistics[] findStatisticsByTextId(java.lang.String textId)
Statistics[] findStatisticsByNumericId(long numericId)