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);
}
}
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;
}
}
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;
}
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();
}
Aggregations