Skip to content

Commit

Permalink
GEODE-6660: Remove non-Linux OS statistics classes (apache#3574)
Browse files Browse the repository at this point in the history
  • Loading branch information
alb3rtobr authored and dschneider-pivotal committed Jun 17, 2019
1 parent 5b6bcbf commit c31bfd7
Show file tree
Hide file tree
Showing 15 changed files with 250 additions and 1,733 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

import org.apache.geode.admin.GemFireHealth;
import org.apache.geode.admin.GemFireHealthConfig;
import org.apache.geode.internal.PureJavaMode;
import org.apache.geode.internal.statistics.GemFireStatSampler;
import org.apache.geode.internal.statistics.OsStatisticsProvider;
import org.apache.geode.internal.statistics.platform.ProcessStats;

/**
Expand All @@ -46,7 +46,7 @@ public class MemberHealthEvaluatorJUnitTest extends HealthEvaluatorTestCase {
*/
@Test
public void testCheckVMProcessSize() throws InterruptedException {
if (PureJavaMode.osStatsAreAvailable()) {
if (OsStatisticsProvider.build().osStatsSupported()) {
GemFireStatSampler sampler = system.getStatSampler();
assertNotNull(sampler);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import static org.apache.geode.internal.GemFireVersion.getBuildId;
import static org.apache.geode.internal.GemFireVersion.getGemFireVersion;
import static org.apache.geode.internal.GemFireVersion.getSourceDate;
import static org.apache.geode.internal.PureJavaMode.osStatsAreAvailable;
import static org.apache.geode.internal.cache.control.HeapMemoryMonitor.getTenuredMemoryPoolMXBean;
import static org.apache.geode.internal.cache.control.HeapMemoryMonitor.getTenuredPoolStatistics;
import static org.apache.geode.internal.net.SocketCreator.getHostName;
Expand Down Expand Up @@ -169,38 +168,11 @@ public void testBasicProcessStats() throws Exception {
ProcessStats processStats = statSampler.getProcessStats();
AllStatistics allStats = new AllStatistics(statSampler);

if (osName.equals("SunOS")) {
if (osName.startsWith("Linux")) {
assertThat(processStats)
.withFailMessage("ProcessStats were not created on" + osName)
.isNotNull();
assertThat(osStatsAreAvailable())
.as("os stats are available on SunOS")
.isTrue();
assertThat(allStats.containsStatisticsType("SolarisProcessStats"))
.as("SunOS stats include statistics type named SolarisProcessStats")
.isTrue();
assertThat(allStats.containsStatisticsType("SolarisSystemStats"))
.as("SunOS stats include statistics type named SolarisSystemStats")
.isTrue();
} else if (osName.startsWith("Windows")) {
// fails on Windows 7: 45395 "ProcessStats are not created on Windows 7"
assertThat(processStats)
.withFailMessage("ProcessStats were not created on" + osName)
.isNotNull();
assertThat(osStatsAreAvailable())
.as("os stats are available on Windows")
.isTrue();
assertThat(allStats.containsStatisticsType("WindowsProcessStats"))
.as("Windows stats include statistics type named WindowsProcessStats")
.isTrue();
assertThat(allStats.containsStatisticsType("WindowsSystemStats"))
.as("Windows stats include statistics type named WindowsSystemStats")
.isTrue();
} else if (osName.startsWith("Linux")) {
assertThat(processStats)
.withFailMessage("ProcessStats were not created on" + osName)
.isNotNull();
assertThat(osStatsAreAvailable())
assertThat(OsStatisticsProvider.build().osStatsSupported())
.as("os stats are available on Linux")
.isTrue();
assertThat(allStats.containsStatisticsType("LinuxProcessStats"))
Expand All @@ -209,19 +181,6 @@ public void testBasicProcessStats() throws Exception {
assertThat(allStats.containsStatisticsType("LinuxSystemStats"))
.as("Linux stats include statistics type named LinuxSystemStats")
.isTrue();
} else if (osName.equals("Mac OS X")) {
assertThat(processStats)
.withFailMessage("ProcessStats were created on" + osName)
.isNull();
assertThat(osStatsAreAvailable())
.as("os stats are available on Mac OS X")
.isFalse();
assertThat(allStats.containsStatisticsType("OSXProcessStats"))
.as("Mac OS X stats include statistics type named OSXProcessStats")
.isFalse();
assertThat(allStats.containsStatisticsType("OSXSystemStats"))
.as("Mac OS X stats include statistics type named OSXSystemStats")
.isFalse();
} else {
assertThat(processStats)
.withFailMessage("ProcessStats were created on" + osName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public class PureJavaMode {

private static final boolean isPure;
private static final boolean is64Bit;
private static final boolean osStatsAreAvailable;
static {
boolean tmpIsPure = false;
if (Boolean.getBoolean(PURE_MODE_PROPERTY)) {
Expand All @@ -63,8 +62,6 @@ public class PureJavaMode {
}
isPure = tmpIsPure;
is64Bit = SharedLibrary.is64Bit();
String osName = System.getProperty("os.name", "unknown");
osStatsAreAvailable = osName.startsWith("Linux") || !isPure;
}

public static boolean isPure() {
Expand All @@ -74,12 +71,4 @@ public static boolean isPure() {
public static boolean is64Bit() {
return is64Bit;
}

/**
* Linux has OsStats even in PureJava mode but other platforms require the native code to provide
* OS Statistics. return true if OSStatistics are available
*/
public static boolean osStatsAreAvailable() {
return osStatsAreAvailable;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.apache.geode.distributed.internal.InternalDistributedSystem;
import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
import org.apache.geode.internal.GemFireVersion;
import org.apache.geode.internal.PureJavaMode;
import org.apache.geode.internal.admin.ListenerIdMap;
import org.apache.geode.internal.admin.remote.StatListenerMessage;
import org.apache.geode.internal.logging.LogFile;
Expand Down Expand Up @@ -66,6 +65,8 @@ public class GemFireStatSampler extends HostStatSampler {
private int nextListenerId = 1;
private ProcessStats processStats;

private OsStatisticsProvider osStatisticsProvider = OsStatisticsProvider.build();

public GemFireStatSampler(InternalDistributedSystem internalDistributedSystem) {
this(internalDistributedSystem, null);
}
Expand Down Expand Up @@ -266,31 +267,31 @@ protected OsStatisticsFactory getOsStatisticsFactory() {

@Override
protected void initProcessStats(long id) {
if (PureJavaMode.osStatsAreAvailable()) {
if (osStatisticsProvider.osStatsSupported()) {
if (osStatsDisabled()) {
logger.info(LogMarker.STATISTICS_MARKER,
"OS statistic collection disabled by setting the osStatsDisabled system property to true.");
} else {
int retVal = HostStatHelper.initOSStats();
int retVal = osStatisticsProvider.initOSStats();
if (retVal != 0) {
logger.error(LogMarker.STATISTICS_MARKER,
"OS statistics failed to initialize properly, some stats may be missing. See bugnote #37160.");
}
HostStatHelper.newSystem(getOsStatisticsFactory(), id);
osStatisticsProvider.newSystem(getOsStatisticsFactory(), id);
String statName = getStatisticsManager().getName();
if (statName == null || statName.length() == 0) {
statName = "javaApp" + getSystemId();
}
Statistics stats =
HostStatHelper.newProcess(getOsStatisticsFactory(), id, statName + "-proc");
processStats = HostStatHelper.newProcessStats(stats);
osStatisticsProvider.newProcess(getOsStatisticsFactory(), id, statName + "-proc");
processStats = osStatisticsProvider.newProcessStats(stats);
}
}
}

@Override
protected void sampleProcessStats(boolean prepareOnly) {
if (prepareOnly || osStatsDisabled() || !PureJavaMode.osStatsAreAvailable()) {
if (prepareOnly || osStatsDisabled() || !osStatisticsProvider.osStatsSupported()) {
return;
}
List<Statistics> statisticsList = getStatisticsManager().getStatsList();
Expand All @@ -300,26 +301,26 @@ protected void sampleProcessStats(boolean prepareOnly) {
if (stopRequested()) {
return;
}
HostStatHelper.readyRefreshOSStats();
osStatisticsProvider.readyRefreshOSStats();
for (Statistics statistics : statisticsList) {
if (stopRequested()) {
return;
}
StatisticsImpl statisticsImpl = (StatisticsImpl) statistics;
if (statisticsImpl.usesSystemCalls()) {
HostStatHelper.refresh((LocalStatisticsImpl) statisticsImpl);
osStatisticsProvider.refresh((LocalStatisticsImpl) statisticsImpl);
}
}
}

@Override
protected void closeProcessStats() {
if (PureJavaMode.osStatsAreAvailable()) {
if (osStatisticsProvider.osStatsSupported()) {
if (!osStatsDisabled()) {
if (processStats != null) {
processStats.close();
}
HostStatHelper.closeOSStats();
osStatisticsProvider.closeOSStats();
}
}
}
Expand Down
Loading

0 comments on commit c31bfd7

Please sign in to comment.