Search in sources :

Example 1 with ProcessStats

use of org.apache.geode.internal.statistics.platform.ProcessStats in project geode by apache.

the class GemFireStatSamplerIntegrationTest method testBasics.

/**
   * Tests the majority of getters and the basic functionality of the sampler.
   * 
   * This test is skipped when running on Windows 7 because ProcessStats is not created for this OS.
   * See #45395.
   */
@Test
public void testBasics() throws Exception {
    final String osName = System.getProperty("os.name", "unknown");
    assumeFalse(osName.equals("Windows 7"));
    connect(createGemFireProperties());
    GemFireStatSampler statSampler = getGemFireStatSampler();
    assertTrue(statSampler.waitForInitialization(5000));
    assertEquals(0, statSampler.getArchiveFileSizeLimit());
    assertEquals(0, statSampler.getArchiveDiskSpaceLimit());
    assertEquals(STAT_SAMPLE_RATE, statSampler.getSampleRate());
    assertEquals(true, statSampler.isSamplingEnabled());
    int statsCount = statSampler.getStatisticsManager().getStatisticsCount();
    assertEquals(statsCount, statSampler.getStatisticsModCount());
    assertEquals(statsCount, statSampler.getStatisticsManager().getStatisticsCount());
    assertEquals(statsCount, statSampler.getStatistics().length);
    Assert.assertEquals(getStatisticsManager().getId(), statSampler.getSystemId());
    assertTrue(statSampler.getSystemStartTime() < System.currentTimeMillis());
    Assert.assertEquals(SocketCreator.getHostName(SocketCreator.getLocalHost()), statSampler.getSystemDirectoryPath());
    AllStatistics allStats = new AllStatistics(statSampler);
    VMStatsContract vmStats = statSampler.getVMStats();
    assertNotNull(vmStats);
    assertTrue(vmStats instanceof VMStats50);
    /*
     * NOTE: VMStats50 is not an instance of Statistics but instead its instance contains 3
     * instances of Statistics: 1) vmStats 2) heapMemStats 3) nonHeapMemStats
     */
    Method getProcessStats = getGemFireStatSampler().getClass().getMethod("getProcessStats");
    assertNotNull(getProcessStats);
    ProcessStats processStats = statSampler.getProcessStats();
    if (osName.equals("SunOS")) {
        assertNotNull(processStats);
        assertTrue(PureJavaMode.osStatsAreAvailable());
        assertTrue(allStats.containsStatisticsType("SolarisProcessStats"));
        assertTrue(allStats.containsStatisticsType("SolarisSystemStats"));
    } else if (osName.startsWith("Windows")) {
        // fails on Windows 7: 45395 "ProcessStats are not created on Windows 7"
        assertNotNull("ProcessStats were not created on " + osName, processStats);
        assertTrue(PureJavaMode.osStatsAreAvailable());
        assertTrue(allStats.containsStatisticsType("WindowsProcessStats"));
        assertTrue(allStats.containsStatisticsType("WindowsSystemStats"));
    } else if (osName.startsWith("Linux")) {
        assertNotNull(processStats);
        assertTrue(PureJavaMode.osStatsAreAvailable());
        assertTrue(allStats.containsStatisticsType("LinuxProcessStats"));
        assertTrue(allStats.containsStatisticsType("LinuxSystemStats"));
    } else if (osName.equals("Mac OS X")) {
        assertNull(processStats);
        assertFalse(PureJavaMode.osStatsAreAvailable());
        assertFalse(allStats.containsStatisticsType("OSXProcessStats"));
        assertFalse(allStats.containsStatisticsType("OSXSystemStats"));
    } else {
        assertNull(processStats);
    }
    String productDesc = statSampler.getProductDescription();
    assertTrue(productDesc.contains(GemFireVersion.getGemFireVersion()));
    assertTrue(productDesc.contains(GemFireVersion.getBuildId()));
    assertTrue(productDesc.contains(GemFireVersion.getSourceDate()));
}
Also used : ProcessStats(org.apache.geode.internal.statistics.platform.ProcessStats) Method(java.lang.reflect.Method) VMStats50(org.apache.geode.internal.stats50.VMStats50) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 2 with ProcessStats

use of org.apache.geode.internal.statistics.platform.ProcessStats in project geode by apache.

the class MemberMBeanBridge method addSystemStats.

public void addSystemStats() {
    GemFireStatSampler sampler = system.getStatSampler();
    ProcessStats processStats = sampler.getProcessStats();
    StatSamplerStats samplerStats = sampler.getStatSamplerStats();
    if (processStats != null) {
        systemStatsMonitor.addStatisticsToMonitor(processStats.getStatistics());
    }
    if (samplerStats != null) {
        systemStatsMonitor.addStatisticsToMonitor(samplerStats.getStats());
    }
}
Also used : GemFireStatSampler(org.apache.geode.internal.statistics.GemFireStatSampler) StatSamplerStats(org.apache.geode.internal.statistics.StatSamplerStats) ProcessStats(org.apache.geode.internal.statistics.platform.ProcessStats)

Example 3 with ProcessStats

use of org.apache.geode.internal.statistics.platform.ProcessStats 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)

Aggregations

ProcessStats (org.apache.geode.internal.statistics.platform.ProcessStats)3 GemFireStatSampler (org.apache.geode.internal.statistics.GemFireStatSampler)2 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2 Test (org.junit.Test)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 GemFireHealthConfig (org.apache.geode.admin.GemFireHealthConfig)1 StatSamplerStats (org.apache.geode.internal.statistics.StatSamplerStats)1 VMStats50 (org.apache.geode.internal.stats50.VMStats50)1 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)1