Creating New Statistics
This example provides a programmatic code sample for creating and registering new statistics.
For information about the geode_statistics
API, see Statistics API.
Creating New Statistics Programmatically
//Get StatisticsFactory
StatisticsFactory* factory = StatisticsFactory::getExistingInstance();
//Define each StatisticDescriptor and put each in an array
StatisticDescriptor** statDescriptorArr = new StatisticDescriptor*[6];
statDescriptorArr[0] = statFactory->createIntCounter("IntCounter",
"Test Statistic Descriptor Int Counter.","TestUnit");
statDescriptorArr[1] = statFactory->createIntGauge("IntGauge",
"Test Statistic Descriptor Int Gauge.","TestUnit");
statDescriptorArr[2] = statFactory->createLongCounter("LongCounter",
"Test Statistic Descriptor Long Counter.","TestUnit");
statDescriptorArr[3] = statFactory->createLongGauge("LongGauge",
"Test Statistic Descriptor Long Gauge.","TestUnit");
statDescriptorArr[4] = statFactory->createDoubleCounter("DoubleCounter",
"Test Statistic Descriptor Double Counter.","TestUnit");
statDescriptorArr[5] = statFactory->createDoubleGauge("DoubleGauge",
"Test Statistic Descriptor Double Gauge.","TestUnit");
//Create a StatisticsType
StatisticsType* statsType = statFactory->createType("TestStatsType",
"Statistics for Unit Test.",statDescriptorArr, 6);
//Create Statistics of a given type
Statistics* testStat =
factory->createStatistics(statsType,"TestStatistics");
//Statistics are created and registered. Set and increment individual values
Int statIdIntCounter = statsType->nameToId("IntCounter");
testStat->setInt(statIdIntCounter, 10 );
testStat->incInt(statIdIntCounter, 1 );
int currentValue = testStat->getInt(statIdIntCounter);