Search in sources :

Example 6 with GemFireStatSampler

use of org.apache.geode.internal.statistics.GemFireStatSampler in project geode by apache.

the class MemberHealthEvaluatorJUnitTest method testCheckVMProcessSize.

/**
   * Tests that we are in {@link GemFireHealth#OKAY_HEALTH okay} health if the VM's process size is
   * too big.
   *
   * @see MemberHealthEvaluator#checkVMProcessSize
   */
@Test
public void testCheckVMProcessSize() throws InterruptedException {
    if (PureJavaMode.osStatsAreAvailable()) {
        GemFireStatSampler sampler = system.getStatSampler();
        assertNotNull(sampler);
        // fix: remove infinite wait
        sampler.waitForInitialization(10000);
        ProcessStats stats = sampler.getProcessStats();
        assertNotNull(stats);
        List status = new ArrayList();
        long threshold = stats.getProcessSize() * 2;
        if (threshold <= 0) {
            // The process size is zero on some Linux versions
            return;
        }
        GemFireHealthConfig config = new GemFireHealthConfigImpl(null);
        config.setMaxVMProcessSize(threshold);
        MemberHealthEvaluator eval = new MemberHealthEvaluator(config, this.system.getDistributionManager());
        eval.evaluate(status);
        assertTrue(status.isEmpty());
        status = new ArrayList();
        long processSize = stats.getProcessSize();
        threshold = processSize / 2;
        assertTrue("Threshold (" + threshold + ") is > 0.  " + "Process size is " + processSize, threshold > 0);
        config = new GemFireHealthConfigImpl(null);
        config.setMaxVMProcessSize(threshold);
        eval = new MemberHealthEvaluator(config, this.system.getDistributionManager());
        eval.evaluate(status);
        assertEquals(1, status.size());
        AbstractHealthEvaluator.HealthStatus ill = (AbstractHealthEvaluator.HealthStatus) status.get(0);
        assertEquals(GemFireHealth.OKAY_HEALTH, ill.getHealthCode());
        assertTrue(ill.getDiagnosis().indexOf("The size of this VM") != -1);
    }
}
Also used : GemFireStatSampler(org.apache.geode.internal.statistics.GemFireStatSampler) GemFireHealthConfig(org.apache.geode.admin.GemFireHealthConfig) ProcessStats(org.apache.geode.internal.statistics.platform.ProcessStats) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 7 with GemFireStatSampler

use of org.apache.geode.internal.statistics.GemFireStatSampler in project geode by apache.

the class HeapMemoryMonitor method stopMonitoring.

/**
   * Stops all three mechanisms from monitoring heap usage.
   */
@Override
public void stopMonitoring() {
    synchronized (this) {
        if (!this.started) {
            return;
        }
        // Stop the poller
        this.resourceManager.stopExecutor(this.pollerExecutor);
        // Stop the JVM threshold listener
        NotificationEmitter emitter = (NotificationEmitter) ManagementFactory.getMemoryMXBean();
        try {
            emitter.removeNotificationListener(this, null, null);
            this.cache.getLoggerI18n().fine("Removed Memory MXBean notification listener" + this);
        } catch (ListenerNotFoundException ignore) {
            logger.debug("This instance '{}' was not registered as a Memory MXBean listener", this);
        }
        // Stop the stats listener
        final GemFireStatSampler sampler = this.cache.getInternalDistributedSystem().getStatSampler();
        if (sampler != null) {
            sampler.removeLocalStatListener(this.statListener);
        }
        this.started = false;
    }
}
Also used : GemFireStatSampler(org.apache.geode.internal.statistics.GemFireStatSampler) NotificationEmitter(javax.management.NotificationEmitter) ListenerNotFoundException(javax.management.ListenerNotFoundException)

Example 8 with GemFireStatSampler

use of org.apache.geode.internal.statistics.GemFireStatSampler in project geode by apache.

the class CancelStatListenerResponse method create.

// instance variables
/**
   * Returns a <code>CancelStatListenerResponse</code> that will be returned to the specified
   * recipient. The message will contains a copy of the local manager's system config.
   */
public static CancelStatListenerResponse create(DistributionManager dm, InternalDistributedMember recipient, int listenerId) {
    CancelStatListenerResponse m = new CancelStatListenerResponse();
    m.setRecipient(recipient);
    GemFireStatSampler sampler = null;
    sampler = dm.getSystem().getStatSampler();
    if (sampler != null) {
        sampler.removeListener(listenerId);
    }
    return m;
}
Also used : GemFireStatSampler(org.apache.geode.internal.statistics.GemFireStatSampler)

Example 9 with GemFireStatSampler

use of org.apache.geode.internal.statistics.GemFireStatSampler in project geode by apache.

the class MemoryThresholdsDUnitTest method testLocalStatListenerRegistration.

/**
   * putting this test here because junit does not have host stat sampler enabled
   */
@Test
public void testLocalStatListenerRegistration() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    Cache cache = getCache();
    InternalDistributedSystem internalSystem = (InternalDistributedSystem) cache.getDistributedSystem();
    final GemFireStatSampler sampler = internalSystem.getStatSampler();
    // fix: remove infinite wait
    sampler.waitForInitialization(10000);
    final LocalStatListener l = new LocalStatListener() {

        public void statValueChanged(double value) {
            latch.countDown();
        }
    };
    final String tenuredPoolName = HeapMemoryMonitor.getTenuredMemoryPoolMXBean().getName();
    LogWriterUtils.getLogWriter().info("TenuredPoolName:" + tenuredPoolName);
    final List list = internalSystem.getStatsList();
    assertFalse(list.isEmpty());
    // fix: found race condition here...
    WaitCriterion wc = new WaitCriterion() {

        public boolean done() {
            int i = 0;
            synchronized (list) {
                for (Object o : list) {
                    LogWriterUtils.getLogWriter().info("List:" + (++i) + ":" + o);
                    if (o instanceof StatisticsImpl) {
                        StatisticsImpl si = (StatisticsImpl) o;
                        LogWriterUtils.getLogWriter().info("stat:" + si.getTextId());
                        if (si.getTextId().contains(tenuredPoolName)) {
                            sampler.addLocalStatListener(l, si, "currentUsedMemory");
                            return true;
                        }
                    }
                }
            }
            return false;
        }

        public String description() {
            return "Waiting for " + tenuredPoolName + " statistics to be added to create listener for";
        }
    };
    Wait.waitForCriterion(wc, 5000, 10, true);
    assertTrue("expected at least one stat listener, found " + sampler.getLocalListeners().size(), sampler.getLocalListeners().size() > 0);
    long maxTenuredMemory = HeapMemoryMonitor.getTenuredPoolMaxMemory();
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    Region r = createRegion(getUniqueName() + "region", factory.create());
    // keep putting objects (of size 1% of maxTenuredMemory) and wait for stat callback
    // if we don't get a callback after 75 attempts, throw exception
    int count = 0;
    while (true) {
        count++;
        if (count > 75) {
            throw new AssertionError("Did not receive a stat listener callback");
        }
        byte[] value = new byte[(int) (maxTenuredMemory * 0.01)];
        r.put("key-" + count, value);
        if (latch.await(50, TimeUnit.MILLISECONDS)) {
            break;
        } else {
            continue;
        }
    }
    r.close();
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) LocalStatListener(org.apache.geode.internal.statistics.LocalStatListener) GemFireStatSampler(org.apache.geode.internal.statistics.GemFireStatSampler) StatisticsImpl(org.apache.geode.internal.statistics.StatisticsImpl) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) List(java.util.List) ArrayList(java.util.ArrayList) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) Cache(org.apache.geode.cache.Cache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Aggregations

GemFireStatSampler (org.apache.geode.internal.statistics.GemFireStatSampler)9 List (java.util.List)3 ArrayList (java.util.ArrayList)2 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)2 StatisticsImpl (org.apache.geode.internal.statistics.StatisticsImpl)2 ProcessStats (org.apache.geode.internal.statistics.platform.ProcessStats)2 Test (org.junit.Test)2 File (java.io.File)1 IOException (java.io.IOException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ListenerNotFoundException (javax.management.ListenerNotFoundException)1 NotificationEmitter (javax.management.NotificationEmitter)1 CancelException (org.apache.geode.CancelException)1 ForcedDisconnectException (org.apache.geode.ForcedDisconnectException)1 GemFireConfigException (org.apache.geode.GemFireConfigException)1 GemFireIOException (org.apache.geode.GemFireIOException)1 SystemConnectException (org.apache.geode.SystemConnectException)1 GemFireHealthConfig (org.apache.geode.admin.GemFireHealthConfig)1 AttributesFactory (org.apache.geode.cache.AttributesFactory)1 Cache (org.apache.geode.cache.Cache)1