Search in sources :

Example 31 with StatisticsType

use of org.apache.geode.StatisticsType in project geode by apache.

the class StatArchiveWriterReaderIntegrationTest method testDestroyUnallocatedStatistics.

/**
   * Control which helps verify fix for bug #45377.
   */
@Test
public void testDestroyUnallocatedStatistics() throws Exception {
    final StatArchiveDescriptor archiveDescriptor = new StatArchiveDescriptor.Builder().setArchiveName(this.archiveFileName).setSystemId(1).setSystemStartTime(WRITER_INITIAL_DATE_MILLIS - 2000).setSystemDirectoryPath(this.testName.getMethodName()).setProductDescription(getClass().getSimpleName()).build();
    final StatArchiveWriter writer = new TestStatArchiveWriter(archiveDescriptor);
    final StatisticsType statsType = createDummyStatisticsType();
    final ResourceType rt = new ResourceType(0, statsType);
    final Statistics statistics = mock(Statistics.class);
    final ResourceInstance ri = new ResourceInstance(0, statistics, rt);
    writer.sampled(WRITER_INITIAL_DATE_MILLIS + 1000, Collections.singletonList(ri));
    writer.destroyedResourceInstance(ri);
    writer.close();
    // Verify StatArchiveReader.update returns cleanly, without throwing an exception
    final StatArchiveReader reader = new StatArchiveReader(new File[] { new File(this.archiveFileName) }, null, false);
    reader.update();
    reader.close();
}
Also used : TestStatArchiveWriter(org.apache.geode.internal.statistics.TestStatArchiveWriter) StatisticsType(org.apache.geode.StatisticsType) TestStatArchiveWriter(org.apache.geode.internal.statistics.TestStatArchiveWriter) Statistics(org.apache.geode.Statistics) File(java.io.File) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 32 with StatisticsType

use of org.apache.geode.StatisticsType 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);
}
Also used : StatisticsType(org.apache.geode.StatisticsType) TestStatArchiveWriter(org.apache.geode.internal.statistics.TestStatArchiveWriter) Statistics(org.apache.geode.Statistics) StatValue(org.apache.geode.internal.statistics.StatArchiveReader.StatValue) StatisticDescriptor(org.apache.geode.StatisticDescriptor) TestStatArchiveWriter(org.apache.geode.internal.statistics.TestStatArchiveWriter) List(java.util.List) File(java.io.File) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 33 with StatisticsType

use of org.apache.geode.StatisticsType 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);
}
Also used : StatisticsType(org.apache.geode.StatisticsType) StatisticDescriptor(org.apache.geode.StatisticDescriptor)

Example 34 with StatisticsType

use of org.apache.geode.StatisticsType in project geode by apache.

the class MemberMBeanBridge method addVMStats.

public void addVMStats() {
    VMStatsContract vmStatsContract = system.getStatSampler().getVMStats();
    if (vmStatsContract != null && vmStatsContract instanceof VMStats50) {
        VMStats50 vmStats50 = (VMStats50) vmStatsContract;
        Statistics vmStats = vmStats50.getVMStats();
        if (vmStats != null) {
            vmStatsMonitor.addStatisticsToMonitor(vmStats);
        }
        Statistics vmHeapStats = vmStats50.getVMHeapStats();
        if (vmHeapStats != null) {
            vmStatsMonitor.addStatisticsToMonitor(vmHeapStats);
        }
        StatisticsType gcType = VMStats50.getGCType();
        if (gcType != null) {
            Statistics[] gcStats = system.findStatisticsByType(gcType);
            if (gcStats != null && gcStats.length > 0) {
                for (Statistics gcStat : gcStats) {
                    if (gcStat != null) {
                        gcMonitor.addStatisticsToMonitor(gcStat);
                    }
                }
            }
        }
    }
}
Also used : StatisticsType(org.apache.geode.StatisticsType) VMStatsContract(org.apache.geode.internal.statistics.VMStatsContract) Statistics(org.apache.geode.Statistics) LRUStatistics(org.apache.geode.internal.cache.lru.LRUStatistics) VMStats50(org.apache.geode.internal.stats50.VMStats50)

Example 35 with StatisticsType

use of org.apache.geode.StatisticsType in project geode by apache.

the class SampleCollector method getResourceType.

private ResourceType getResourceType(List<MarkableSampleHandler> handlers, Statistics statistics) throws IgnoreResourceException {
    final boolean isDebugEnabled_STATISTICS = logger.isTraceEnabled(LogMarker.STATISTICS);
    if (isDebugEnabled_STATISTICS) {
        logger.trace(LogMarker.STATISTICS, "SampleCollector#getResourceType statistics={}", statistics);
    }
    StatisticsType type = statistics.getType();
    if (type == null) {
        // bug 30707
        if (isDebugEnabled_STATISTICS) {
            logger.trace(LogMarker.STATISTICS, "SampleCollector#getResourceType type={}, throwing IgnoreResourceException", type);
        }
        throw new IgnoreResourceException();
    }
    ResourceType resourceType = null;
    try {
        resourceType = (ResourceType) this.resourceTypeMap.get(type);
    } catch (NullPointerException ex) {
        // bug 30716
        if (isDebugEnabled_STATISTICS) {
            logger.trace(LogMarker.STATISTICS, "SampleCollector#getResourceType resourceTypeMap.get threw NPE, throwing NullPointerException");
        }
        throw new IgnoreResourceException();
    }
    if (resourceType == null) {
        resourceType = allocateResourceType(handlers, type);
        notifyOldHandlersOfResourceType(handlers, resourceType);
    }
    return resourceType;
}
Also used : StatisticsType(org.apache.geode.StatisticsType)

Aggregations

StatisticsType (org.apache.geode.StatisticsType)36 Statistics (org.apache.geode.Statistics)34 Test (org.junit.Test)24 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)20 StatisticDescriptor (org.apache.geode.StatisticDescriptor)18 File (java.io.File)13 List (java.util.List)11 StatValue (org.apache.geode.internal.statistics.StatArchiveReader.StatValue)11 TestStatArchiveWriter (org.apache.geode.internal.statistics.TestStatArchiveWriter)10 Iterator (java.util.Iterator)4 ArrayList (java.util.ArrayList)3 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)3 Properties (java.util.Properties)2 StatisticsFactory (org.apache.geode.StatisticsFactory)2 Connection (org.apache.geode.cache.client.internal.Connection)2 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)2 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)2 ResourceInst (org.apache.geode.internal.statistics.StatArchiveReader.ResourceInst)2 Info (org.apache.geode.internal.statistics.TestSampleHandler.Info)2 ResourceInstanceInfo (org.apache.geode.internal.statistics.TestSampleHandler.ResourceInstanceInfo)2