use of org.apache.geode.StatisticDescriptor in project geode by apache.
the class StatArchiveWriterReaderIntegrationTest method testDoubleCounterOneSample.
@Test
public void testDoubleCounterOneSample() throws Exception {
final TestStatisticsManager manager = new TestStatisticsManager(1, getUniqueName(), WRITER_INITIAL_DATE_MILLIS);
final TestStatisticsSampler sampler = new TestStatisticsSampler(manager);
final SampleCollector sampleCollector = new SampleCollector(sampler);
final StatArchiveDescriptor archiveDescriptor = new StatArchiveDescriptor.Builder().setArchiveName(this.archiveFileName).setSystemId(1).setSystemStartTime(WRITER_INITIAL_DATE_MILLIS).setSystemDirectoryPath(this.testName.getMethodName()).setProductDescription(getClass().getSimpleName()).build();
final StatArchiveWriter writer = new TestStatArchiveWriter(archiveDescriptor);
sampleCollector.addSampleHandler(writer);
final StatisticDescriptor[] statsST1 = new StatisticDescriptor[] { manager.createDoubleCounter("long_double_1", "d1", "u1") };
final StatisticsType ST1 = manager.createType("ST1", "ST1", statsST1);
final Statistics st1_1 = manager.createAtomicStatistics(ST1, "st1_1", 1);
final double value = 32317.716467;
incDouble(st1_1, "long_double_1", value);
final long sampleIncNanos = NANOS_PER_MILLI * 1000;
final long sampleTimeNanos = WRITER_PREVIOUS_TIMESTAMP_NANOS + sampleIncNanos;
sampleCollector.sample(sampleTimeNanos);
writer.close();
final StatisticDescriptor[] sds = ST1.getStatistics();
for (int i = 0; i < sds.length; i++) {
assertEquals(value, st1_1.get(sds[i].getName()));
}
final StatArchiveReader reader = new StatArchiveReader(new File[] { new File(this.archiveFileName) }, null, false);
// compare all resourceInst values against what was printed above
final List resources = reader.getResourceInstList();
assertNotNull(resources);
assertEquals(1, resources.size());
final StatArchiveReader.ResourceInst ri = (StatArchiveReader.ResourceInst) resources.get(0);
assertNotNull(ri);
final String statsName = ri.getName();
assertNotNull(statsName);
assertEquals("st1_1", statsName);
assertEquals("ST1", ri.getType().getName());
final StatValue[] statValues = ri.getStatValues();
assertNotNull(statValues);
assertEquals(1, statValues.length);
final String statName = ri.getType().getStats()[0].getName();
assertNotNull(statName);
assertEquals("long_double_1", statName);
assertEquals(statName, statValues[0].getDescriptor().getName());
assertEquals(1, statValues[0].getSnapshotsSize());
assertEquals(value, statValues[0].getSnapshotsMostRecent(), 0.01);
final long[] timeStampsMillis = statValues[0].getRawAbsoluteTimeStamps();
assertNotNull(timeStampsMillis);
assertEquals(1, timeStampsMillis.length);
final long initPreviousTimeStampMillis = NanoTimer.nanosToMillis(WRITER_PREVIOUS_TIMESTAMP_NANOS);
final long timeStampMillis = NanoTimer.nanosToMillis(sampleTimeNanos);
final long deltaMillis = timeStampMillis - initPreviousTimeStampMillis;
assertEquals(NanoTimer.nanosToMillis(sampleIncNanos), deltaMillis);
final long expectedTimeStampMillis = deltaMillis + WRITER_INITIAL_DATE_MILLIS;
assertEquals(expectedTimeStampMillis, timeStampsMillis[0]);
final double[] snapshots = statValues[0].getRawSnapshots();
assertNotNull(snapshots);
assertEquals(1, snapshots.length);
assertEquals(value, snapshots[0], 0.01);
}
use of org.apache.geode.StatisticDescriptor in project geode by apache.
the class GCStatsMonitor method handleNotification.
@Override
public void handleNotification(StatisticsNotification notification) {
decreasePrevValues(statsMap);
for (StatisticId statId : notification) {
StatisticDescriptor descriptor = statId.getStatisticDescriptor();
String name = descriptor.getName();
Number value;
try {
value = notification.getValue(statId);
} catch (StatisticNotFoundException e) {
value = 0;
}
log(name, value);
increaseStats(name, value);
statsMap.put(name, value);
}
}
use of org.apache.geode.StatisticDescriptor in project geode by apache.
the class MBeanStatsMonitor method addStatisticsToMonitor.
public void addStatisticsToMonitor(final Statistics stats) {
// if already listener is added this will be a no-op
monitor.addListener(this);
// Initialize the stats with the current values.
StatisticsType type = stats.getType();
StatisticDescriptor[] descriptors = type.getStatistics();
for (StatisticDescriptor d : descriptors) {
statsMap.put(d.getName(), stats.get(d));
}
monitor.addStatistics(stats);
}
use of org.apache.geode.StatisticDescriptor in project geode by apache.
the class StatArchiveWriter method allocatedResourceType.
public void allocatedResourceType(ResourceType resourceType) {
if (logger.isTraceEnabled(LogMarker.STATISTICS)) {
logger.trace(LogMarker.STATISTICS, "StatArchiveWriter#allocatedResourceType resourceType={}", resourceType);
}
if (resourceType.getStatisticDescriptors().length >= ILLEGAL_STAT_OFFSET) {
throw new InternalGemFireException(LocalizedStrings.StatArchiveWriter_COULD_NOT_ARCHIVE_TYPE_0_BECAUSE_IT_HAD_MORE_THAN_1_STATISTICS.toLocalizedString(new Object[] { resourceType.getStatisticsType().getName(), Integer.valueOf(ILLEGAL_STAT_OFFSET - 1) }));
}
// write the type to the archive
try {
this.dataOut.writeByte(RESOURCE_TYPE_TOKEN);
this.dataOut.writeInt(resourceType.getId());
this.dataOut.writeUTF(resourceType.getStatisticsType().getName());
this.dataOut.writeUTF(resourceType.getStatisticsType().getDescription());
StatisticDescriptor[] stats = resourceType.getStatisticDescriptors();
this.dataOut.writeShort(stats.length);
if (this.trace && (traceStatisticsTypeName == null || traceStatisticsTypeName.equals(resourceType.getStatisticsType().getName()))) {
this.traceDataOut.println("allocatedResourceType#writeByte RESOURCE_TYPE_TOKEN: " + RESOURCE_TYPE_TOKEN);
this.traceDataOut.println("allocatedResourceType#writeInt resourceType.getId(): " + resourceType.getId());
this.traceDataOut.println("allocatedResourceType#writeUTF resourceType.getStatisticsType().getName(): " + resourceType.getStatisticsType().getName());
this.traceDataOut.println("allocatedResourceType#writeUTF resourceType.getStatisticsType().getDescription(): " + resourceType.getStatisticsType().getDescription());
this.traceDataOut.println("allocatedResourceType#writeShort stats.length: " + stats.length);
}
for (int i = 0; i < stats.length; i++) {
this.dataOut.writeUTF(stats[i].getName());
this.dataOut.writeByte(((StatisticDescriptorImpl) stats[i]).getTypeCode());
this.dataOut.writeBoolean(stats[i].isCounter());
this.dataOut.writeBoolean(stats[i].isLargerBetter());
this.dataOut.writeUTF(stats[i].getUnit());
this.dataOut.writeUTF(stats[i].getDescription());
if (this.trace && (traceStatisticsTypeName == null || traceStatisticsTypeName.equals(resourceType.getStatisticsType().getName()))) {
this.traceDataOut.println("allocatedResourceType#writeUTF stats[i].getName(): " + stats[i].getName());
this.traceDataOut.println("allocatedResourceType#writeByte ((StatisticDescriptorImpl)stats[i]).getTypeCode(): " + ((StatisticDescriptorImpl) stats[i]).getTypeCode());
this.traceDataOut.println("allocatedResourceType#writeBoolean stats[i].isCounter(): " + stats[i].isCounter());
this.traceDataOut.println("allocatedResourceType#writeBoolean stats[i].isLargerBetter(): " + stats[i].isLargerBetter());
this.traceDataOut.println("allocatedResourceType#writeUTF stats[i].getUnit(): " + stats[i].getUnit());
this.traceDataOut.println("allocatedResourceType#writeUTF stats[i].getDescription(): " + stats[i].getDescription());
}
}
} catch (IOException ex) {
throw new GemFireIOException(LocalizedStrings.StatArchiveWriter_FAILED_WRITING_NEW_RESOURCE_TYPE_TO_STATISTIC_ARCHIVE.toLocalizedString(), ex);
}
}
use of org.apache.geode.StatisticDescriptor in project geode by apache.
the class GatewayReceiverStats method createGatewayReceiverStats.
// ///////////////////// Constructors ///////////////////////
public static GatewayReceiverStats createGatewayReceiverStats(String ownerName) {
StatisticsFactory f = InternalDistributedSystem.getAnyInstance();
StatisticDescriptor[] descriptors = new StatisticDescriptor[] { f.createIntCounter(DUPLICATE_BATCHES_RECEIVED, "number of batches which have already been seen by this GatewayReceiver", "nanoseconds"), f.createIntCounter(OUT_OF_ORDER_BATCHES_RECEIVED, "number of batches which are out of order on this GatewayReceiver", "operations"), f.createIntCounter(EARLY_ACKS, "number of early acknowledgements sent to gatewaySenders", "operations"), f.createIntCounter(EVENTS_RECEIVED, "total number events across the batched received by this GatewayReceiver", "operations"), f.createIntCounter(CREAT_REQUESTS, "total number of create operations received by this GatewayReceiver", "operations"), f.createIntCounter(UPDATE_REQUESTS, "total number of update operations received by this GatewayReceiver", "operations"), f.createIntCounter(DESTROY_REQUESTS, "total number of destroy operations received by this GatewayReceiver", "operations"), f.createIntCounter(UNKNOWN_OPERATIONS_RECEIVED, "total number of unknown operations received by this GatewayReceiver", "operations"), f.createIntCounter(EXCEPTIONS_OCCURRED, "number of exceptions occurred while porcessing the batches", "operations") };
return new GatewayReceiverStats(f, ownerName, typeName, descriptors);
}
Aggregations