This is an automated email from the ASF dual-hosted git repository. jbarrett pushed a commit to branch wip/oshi-multios-stats-module in repository https://gitbox.apache.org/repos/asf/geode.git
commit a8dca191b4f3eed02714a39efe976914c8ffb079 Author: Jacob Barrett <jbarr...@pivotal.io> AuthorDate: Sat Jun 12 20:14:39 2021 -0700 spotless --- .../platform/OshiStatisticsBenchmark.java | 46 +++---- .../internal/statistics/GemFireStatSampler.java | 56 ++++---- .../statistics/oshi/NetworkInterfaceStats.java | 2 +- .../statistics/oshi/OperatingSystemStats.java | 2 +- .../statistics/oshi/OshiStatisticsProvider.java | 2 +- .../oshi/OshiStatisticsProviderImpl.java | 89 +++++++----- .../internal/statistics/oshi/ProcessStats.java | 2 +- .../internal/statistics/oshi/ProcessorStats.java | 2 +- .../statistics/oshi/OshiStatisticsTest.java | 151 ++++++++++----------- 9 files changed, 182 insertions(+), 170 deletions(-) diff --git a/geode-core/src/jmh/java/org/apache/geode/internal/statistics/platform/OshiStatisticsBenchmark.java b/geode-core/src/jmh/java/org/apache/geode/internal/statistics/platform/OshiStatisticsBenchmark.java index 6bfb079..ddf9fcf 100644 --- a/geode-core/src/jmh/java/org/apache/geode/internal/statistics/platform/OshiStatisticsBenchmark.java +++ b/geode-core/src/jmh/java/org/apache/geode/internal/statistics/platform/OshiStatisticsBenchmark.java @@ -20,12 +20,10 @@ import java.util.function.DoubleSupplier; import java.util.function.IntSupplier; import java.util.function.LongSupplier; -import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.OutputTimeUnit; import org.openjdk.jmh.annotations.Scope; -import org.openjdk.jmh.annotations.Setup; import org.openjdk.jmh.annotations.State; import oshi.SystemInfo; @@ -41,25 +39,25 @@ public class OshiStatisticsBenchmark { private final int pid = new SystemInfo().getOperatingSystem().getProcessId(); private final SuppliableStatistics noopStatistics = new NoopStatistics(); -// @Setup -// public void setup() { -// OshiStatistics.init(); -// } -// -// @Benchmark -// public void noop() { -// -// } -// -// @Benchmark -// public void refreshProcess() { -// OshiStatistics.refreshProcess(pid, noopStatistics); -// } -// -// @Benchmark -// public void refreshSystem() { -// OshiStatistics.refreshSystem(noopStatistics); -// } + // @Setup + // public void setup() { + // OshiStatistics.init(); + // } + // + // @Benchmark + // public void noop() { + // + // } + // + // @Benchmark + // public void refreshProcess() { + // OshiStatistics.refreshProcess(pid, noopStatistics); + // } + // + // @Benchmark + // public void refreshSystem() { + // OshiStatistics.refreshSystem(noopStatistics); + // } private static class NoopStatistics implements SuppliableStatistics { @Override @@ -279,7 +277,7 @@ public class OshiStatisticsBenchmark { @Override public IntSupplier setIntSupplier(final StatisticDescriptor descriptor, - final IntSupplier supplier) { + final IntSupplier supplier) { return null; } @@ -295,7 +293,7 @@ public class OshiStatisticsBenchmark { @Override public LongSupplier setLongSupplier(final StatisticDescriptor descriptor, - final LongSupplier supplier) { + final LongSupplier supplier) { return null; } @@ -311,7 +309,7 @@ public class OshiStatisticsBenchmark { @Override public DoubleSupplier setDoubleSupplier(final StatisticDescriptor descriptor, - final DoubleSupplier supplier) { + final DoubleSupplier supplier) { return null; } } diff --git a/geode-core/src/main/java/org/apache/geode/internal/statistics/GemFireStatSampler.java b/geode-core/src/main/java/org/apache/geode/internal/statistics/GemFireStatSampler.java index a6d8e97..2c3c922 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/statistics/GemFireStatSampler.java +++ b/geode-core/src/main/java/org/apache/geode/internal/statistics/GemFireStatSampler.java @@ -69,7 +69,7 @@ public class GemFireStatSampler extends HostStatSampler { private int nextListenerId = 1; private ProcessStats processStats; -// private OsStatisticsProvider osStatisticsProvider = OsStatisticsProvider.build(); + // private OsStatisticsProvider osStatisticsProvider = OsStatisticsProvider.build(); private OshiStatisticsProvider oshiStatisticsProvider = new OshiStatisticsProviderImpl(); public GemFireStatSampler(InternalDistributedSystem internalDistributedSystem) { @@ -282,17 +282,17 @@ public class GemFireStatSampler extends HostStatSampler { try { oshiStatisticsProvider.init(getOsStatisticsFactory(), pid); } catch (OshiStatisticsProviderException e) { - logger.error(LogMarker.STATISTICS_MARKER,"Failed to initialize OS statistics.", e); + logger.error(LogMarker.STATISTICS_MARKER, "Failed to initialize OS statistics.", e); } -// osStatisticsProvider.newSystem(getOsStatisticsFactory(), pid); -// String statName = getStatisticsManager().getName(); -// if (statName == null || statName.length() == 0) { -// statName = "javaApp" + getSystemId(); -// } -// Statistics stats = -// osStatisticsProvider.newProcess(getOsStatisticsFactory(), id, statName + "-proc"); - processStats = null; //osStatisticsProvider.newProcessStats(stats); + // osStatisticsProvider.newSystem(getOsStatisticsFactory(), pid); + // String statName = getStatisticsManager().getName(); + // if (statName == null || statName.length() == 0) { + // statName = "javaApp" + getSystemId(); + // } + // Statistics stats = + // osStatisticsProvider.newProcess(getOsStatisticsFactory(), id, statName + "-proc"); + processStats = null; // osStatisticsProvider.newProcessStats(stats); } @@ -302,29 +302,29 @@ public class GemFireStatSampler extends HostStatSampler { return; } oshiStatisticsProvider.sample(); -// List<Statistics> statisticsList = getStatisticsManager().getStatsList(); -// for (Statistics statistics : statisticsList) { -// if (stopRequested()) { -// return; -// } -// StatisticsImpl statisticsImpl = (StatisticsImpl) statistics; -// if (statisticsImpl.usesSystemCalls()) { -// osStatisticsProvider.refresh((LocalStatisticsImpl) statisticsImpl); -// } -// } + // List<Statistics> statisticsList = getStatisticsManager().getStatsList(); + // for (Statistics statistics : statisticsList) { + // if (stopRequested()) { + // return; + // } + // StatisticsImpl statisticsImpl = (StatisticsImpl) statistics; + // if (statisticsImpl.usesSystemCalls()) { + // osStatisticsProvider.refresh((LocalStatisticsImpl) statisticsImpl); + // } + // } } @Override protected void closeProcessStats() { oshiStatisticsProvider.destroy(); -// if (osStatisticsProvider.osStatsSupported()) { -// if (!osStatsDisabled()) { -// if (processStats != null) { -// processStats.close(); -// } -// osStatisticsProvider.closeOSStats(); -// } -// } + // if (osStatisticsProvider.osStatsSupported()) { + // if (!osStatsDisabled()) { + // if (processStats != null) { + // processStats.close(); + // } + // osStatisticsProvider.closeOSStats(); + // } + // } } private void checkLocalListeners() { diff --git a/geode-core/src/main/java/org/apache/geode/internal/statistics/oshi/NetworkInterfaceStats.java b/geode-core/src/main/java/org/apache/geode/internal/statistics/oshi/NetworkInterfaceStats.java index 95d4528..dd1bd75 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/statistics/oshi/NetworkInterfaceStats.java +++ b/geode-core/src/main/java/org/apache/geode/internal/statistics/oshi/NetworkInterfaceStats.java @@ -42,7 +42,7 @@ public class NetworkInterfaceStats { final StatisticsTypeFactory f = StatisticsTypeFactoryImpl.singleton(); statisticsType = f.createType("NetworkInterfaceStats", "Stats for a network interface.", - new StatisticDescriptor[]{ + new StatisticDescriptor[] { f.createLongGauge("mtu", "The interface Maximum Transmission Unit (MTU).", "bytes"), diff --git a/geode-core/src/main/java/org/apache/geode/internal/statistics/oshi/OperatingSystemStats.java b/geode-core/src/main/java/org/apache/geode/internal/statistics/oshi/OperatingSystemStats.java index 1d4bba0..85b386f 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/statistics/oshi/OperatingSystemStats.java +++ b/geode-core/src/main/java/org/apache/geode/internal/statistics/oshi/OperatingSystemStats.java @@ -264,7 +264,7 @@ public class OperatingSystemStats { f.createLongGauge("maxFileDescriptors", "The maximum number of open file descriptors.", "files"), - }); + }); processCount = statisticsType.nameToId("processCount"); threadCount = statisticsType.nameToId("threadCount"); diff --git a/geode-core/src/main/java/org/apache/geode/internal/statistics/oshi/OshiStatisticsProvider.java b/geode-core/src/main/java/org/apache/geode/internal/statistics/oshi/OshiStatisticsProvider.java index d60be5c..b1ec885 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/statistics/oshi/OshiStatisticsProvider.java +++ b/geode-core/src/main/java/org/apache/geode/internal/statistics/oshi/OshiStatisticsProvider.java @@ -6,7 +6,7 @@ import org.apache.geode.internal.statistics.platform.OsStatisticsFactory; public interface OshiStatisticsProvider { void init(final @NotNull OsStatisticsFactory osStatisticsFactory, - final long pid) throws OshiStatisticsProviderException; + final long pid) throws OshiStatisticsProviderException; void sample(); diff --git a/geode-core/src/main/java/org/apache/geode/internal/statistics/oshi/OshiStatisticsProviderImpl.java b/geode-core/src/main/java/org/apache/geode/internal/statistics/oshi/OshiStatisticsProviderImpl.java index 44fc546..b79a038 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/statistics/oshi/OshiStatisticsProviderImpl.java +++ b/geode-core/src/main/java/org/apache/geode/internal/statistics/oshi/OshiStatisticsProviderImpl.java @@ -27,7 +27,7 @@ public class OshiStatisticsProviderImpl implements OshiStatisticsProvider { private static final Logger log = LogService.getLogger(); final SystemInfo systemInfo = new SystemInfo(); - + private int processId; private CentralProcessor processor; private OperatingSystem operatingSystem; @@ -45,7 +45,7 @@ public class OshiStatisticsProviderImpl implements OshiStatisticsProvider { @Override public void init(final @NotNull OsStatisticsFactory osStatisticsFactory, - final long id) throws OshiStatisticsProviderException { + final long id) throws OshiStatisticsProviderException { operatingSystem = systemInfo.getOperatingSystem(); processId = operatingSystem.getProcessId(); @@ -60,7 +60,7 @@ public class OshiStatisticsProviderImpl implements OshiStatisticsProvider { final String systemIdentity = operatingSystem.toString(); systemCpuLoadTicks = new long[TickType.values().length]; systemStats = osStatisticsFactory.createOsStatistics(OperatingSystemStats.getType(), - systemIdentity, id, 0); + systemIdentity, id, 0); final List<LogicalProcessor> logicalProcessors = processor.getLogicalProcessors(); @@ -78,8 +78,9 @@ public class OshiStatisticsProviderImpl implements OshiStatisticsProvider { for (int i = 0, size = networkIFs.size(); i < size; i++) { final NetworkIF networkIF = networkIFs.get(i); log.info("Creating network interfaces stats for {}", networkIF.getDisplayName()); - networkInterfaceStats[i] = osStatisticsFactory.createOsStatistics(NetworkInterfaceStats.getType(), - networkIF.getDisplayName(), id, 0); + networkInterfaceStats[i] = + osStatisticsFactory.createOsStatistics(NetworkInterfaceStats.getType(), + networkIF.getDisplayName(), id, 0); } } @@ -92,8 +93,7 @@ public class OshiStatisticsProviderImpl implements OshiStatisticsProvider { } @Override - public void destroy() { - } + public void destroy() {} private void sampleProcess() { final OSProcess process = operatingSystem.getProcess(processId); @@ -123,8 +123,10 @@ public class OshiStatisticsProviderImpl implements OshiStatisticsProvider { final CentralProcessor processor = hardware.getProcessor(); systemStats.setLong(OperatingSystemStats.contextSwitches, processor.getContextSwitches()); systemStats.setLong(OperatingSystemStats.interrupts, processor.getInterrupts()); - systemStats.setLong(OperatingSystemStats.physicalProcessorCount, processor.getPhysicalProcessorCount()); - systemStats.setLong(OperatingSystemStats.logicalProcessorCount, processor.getLogicalProcessorCount()); + systemStats.setLong(OperatingSystemStats.physicalProcessorCount, + processor.getPhysicalProcessorCount()); + systemStats.setLong(OperatingSystemStats.logicalProcessorCount, + processor.getLogicalProcessorCount()); systemStats.setLong(OperatingSystemStats.maxFreq, processor.getMaxFreq()); final double[] systemLoadAverage = processor.getSystemLoadAverage(3); @@ -132,7 +134,8 @@ public class OshiStatisticsProviderImpl implements OshiStatisticsProvider { systemStats.setDouble(OperatingSystemStats.systemLoadAverage5, systemLoadAverage[1]); systemStats.setDouble(OperatingSystemStats.systemLoadAverage15, systemLoadAverage[2]); - final double systemCpuLoadBetweenTicks = processor.getSystemCpuLoadBetweenTicks(systemCpuLoadTicks); + final double systemCpuLoadBetweenTicks = + processor.getSystemCpuLoadBetweenTicks(systemCpuLoadTicks); systemStats.setDouble(OperatingSystemStats.systemCpuLoad, systemCpuLoadBetweenTicks); systemCpuLoadTicks = processor.getSystemCpuLoadTicks(); @@ -168,50 +171,71 @@ public class OshiStatisticsProviderImpl implements OshiStatisticsProvider { final InternetProtocolStats internetProtocolStats = operatingSystem.getInternetProtocolStats(); final TcpStats tcPv4Stats = internetProtocolStats.getTCPv4Stats(); - systemStats.setLong(OperatingSystemStats.tcpv4ConnectionsEstablished, tcPv4Stats.getConnectionsEstablished()); - systemStats.setLong(OperatingSystemStats.tcpv4ConnectionsActive, tcPv4Stats.getConnectionsActive()); - systemStats.setLong(OperatingSystemStats.tcpv4ConnectionsPassive, tcPv4Stats.getConnectionsPassive()); - systemStats.setLong(OperatingSystemStats.tcpv4ConnectionFailures, tcPv4Stats.getConnectionFailures()); - systemStats.setLong(OperatingSystemStats.tcpv4ConnectionsReset, tcPv4Stats.getConnectionsReset()); + systemStats.setLong(OperatingSystemStats.tcpv4ConnectionsEstablished, + tcPv4Stats.getConnectionsEstablished()); + systemStats.setLong(OperatingSystemStats.tcpv4ConnectionsActive, + tcPv4Stats.getConnectionsActive()); + systemStats.setLong(OperatingSystemStats.tcpv4ConnectionsPassive, + tcPv4Stats.getConnectionsPassive()); + systemStats.setLong(OperatingSystemStats.tcpv4ConnectionFailures, + tcPv4Stats.getConnectionFailures()); + systemStats.setLong(OperatingSystemStats.tcpv4ConnectionsReset, + tcPv4Stats.getConnectionsReset()); systemStats.setLong(OperatingSystemStats.tcpv4SegmentsSent, tcPv4Stats.getSegmentsSent()); - systemStats.setLong(OperatingSystemStats.tcpv4SegmentsReceived, tcPv4Stats.getSegmentsReceived()); - systemStats.setLong(OperatingSystemStats.tcpv4SegmentsRetransmitted, tcPv4Stats.getSegmentsRetransmitted()); + systemStats.setLong(OperatingSystemStats.tcpv4SegmentsReceived, + tcPv4Stats.getSegmentsReceived()); + systemStats.setLong(OperatingSystemStats.tcpv4SegmentsRetransmitted, + tcPv4Stats.getSegmentsRetransmitted()); systemStats.setLong(OperatingSystemStats.tcpv4InErrors, tcPv4Stats.getInErrors()); systemStats.setLong(OperatingSystemStats.tcpv4OutResets, tcPv4Stats.getOutResets()); final UdpStats udPv4Stats = internetProtocolStats.getUDPv4Stats(); systemStats.setLong(OperatingSystemStats.udpv4DatagramsSent, udPv4Stats.getDatagramsSent()); - systemStats.setLong(OperatingSystemStats.udpv4DatagramsReceived, udPv4Stats.getDatagramsReceived()); + systemStats.setLong(OperatingSystemStats.udpv4DatagramsReceived, + udPv4Stats.getDatagramsReceived()); systemStats.setLong(OperatingSystemStats.udpv4DatagramsNoPort, udPv4Stats.getDatagramsNoPort()); - systemStats.setLong(OperatingSystemStats.udpv4DatagramsReceivedErrors, udPv4Stats.getDatagramsReceivedErrors()); + systemStats.setLong(OperatingSystemStats.udpv4DatagramsReceivedErrors, + udPv4Stats.getDatagramsReceivedErrors()); final TcpStats tcPv6Stats = internetProtocolStats.getTCPv6Stats(); - systemStats.setLong(OperatingSystemStats.tcpv6ConnectionsEstablished, tcPv6Stats.getConnectionsEstablished()); - systemStats.setLong(OperatingSystemStats.tcpv6ConnectionsActive, tcPv6Stats.getConnectionsActive()); - systemStats.setLong(OperatingSystemStats.tcpv6ConnectionsPassive, tcPv6Stats.getConnectionsPassive()); - systemStats.setLong(OperatingSystemStats.tcpv6ConnectionFailures, tcPv6Stats.getConnectionFailures()); - systemStats.setLong(OperatingSystemStats.tcpv6ConnectionsReset, tcPv6Stats.getConnectionsReset()); + systemStats.setLong(OperatingSystemStats.tcpv6ConnectionsEstablished, + tcPv6Stats.getConnectionsEstablished()); + systemStats.setLong(OperatingSystemStats.tcpv6ConnectionsActive, + tcPv6Stats.getConnectionsActive()); + systemStats.setLong(OperatingSystemStats.tcpv6ConnectionsPassive, + tcPv6Stats.getConnectionsPassive()); + systemStats.setLong(OperatingSystemStats.tcpv6ConnectionFailures, + tcPv6Stats.getConnectionFailures()); + systemStats.setLong(OperatingSystemStats.tcpv6ConnectionsReset, + tcPv6Stats.getConnectionsReset()); systemStats.setLong(OperatingSystemStats.tcpv6SegmentsSent, tcPv6Stats.getSegmentsSent()); - systemStats.setLong(OperatingSystemStats.tcpv6SegmentsReceived, tcPv6Stats.getSegmentsReceived()); - systemStats.setLong(OperatingSystemStats.tcpv6SegmentsRetransmitted, tcPv6Stats.getSegmentsRetransmitted()); + systemStats.setLong(OperatingSystemStats.tcpv6SegmentsReceived, + tcPv6Stats.getSegmentsReceived()); + systemStats.setLong(OperatingSystemStats.tcpv6SegmentsRetransmitted, + tcPv6Stats.getSegmentsRetransmitted()); systemStats.setLong(OperatingSystemStats.tcpv6InErrors, tcPv6Stats.getInErrors()); systemStats.setLong(OperatingSystemStats.tcpv6OutResets, tcPv6Stats.getOutResets()); final UdpStats udPv6Stats = internetProtocolStats.getUDPv6Stats(); systemStats.setLong(OperatingSystemStats.udpv6DatagramsSent, udPv6Stats.getDatagramsSent()); - systemStats.setLong(OperatingSystemStats.udpv6DatagramsReceived, udPv6Stats.getDatagramsReceived()); + systemStats.setLong(OperatingSystemStats.udpv6DatagramsReceived, + udPv6Stats.getDatagramsReceived()); systemStats.setLong(OperatingSystemStats.udpv6DatagramsNoPort, udPv6Stats.getDatagramsNoPort()); - systemStats.setLong(OperatingSystemStats.udpv6DatagramsReceivedErrors, udPv6Stats.getDatagramsReceivedErrors()); + systemStats.setLong(OperatingSystemStats.udpv6DatagramsReceivedErrors, + udPv6Stats.getDatagramsReceivedErrors()); final FileSystem fileSystem = operatingSystem.getFileSystem(); - systemStats.setLong(OperatingSystemStats.openFileDescriptors, fileSystem.getOpenFileDescriptors()); - systemStats.setLong(OperatingSystemStats.openFileDescriptors, fileSystem.getMaxFileDescriptors()); + systemStats.setLong(OperatingSystemStats.openFileDescriptors, + fileSystem.getOpenFileDescriptors()); + systemStats.setLong(OperatingSystemStats.openFileDescriptors, + fileSystem.getMaxFileDescriptors()); } private void sampleProcessors() { final long[] currentFreq = processor.getCurrentFreq(); - final double[] processorCpuLoad = processor.getProcessorCpuLoadBetweenTicks(processorCpuLoadTicks); + final double[] processorCpuLoad = + processor.getProcessorCpuLoadBetweenTicks(processorCpuLoadTicks); processorCpuLoadTicks = processor.getProcessorCpuLoadTicks(); for (int i = 0; i < processorStats.length; i++) { @@ -250,7 +274,8 @@ public class OshiStatisticsProviderImpl implements OshiStatisticsProvider { networkInterfaceStat.setLong(NetworkInterfaceStats.mtu, networkIF.getMTU()); networkInterfaceStat.setLong(NetworkInterfaceStats.bytesReceived, networkIF.getBytesRecv()); networkInterfaceStat.setLong(NetworkInterfaceStats.bytesSent, networkIF.getBytesSent()); - networkInterfaceStat.setLong(NetworkInterfaceStats.packetsReceived, networkIF.getPacketsRecv()); + networkInterfaceStat.setLong(NetworkInterfaceStats.packetsReceived, + networkIF.getPacketsRecv()); networkInterfaceStat.setLong(NetworkInterfaceStats.packetsSent, networkIF.getPacketsSent()); networkInterfaceStat.setLong(NetworkInterfaceStats.inErrors, networkIF.getInErrors()); networkInterfaceStat.setLong(NetworkInterfaceStats.outErrors, networkIF.getOutErrors()); diff --git a/geode-core/src/main/java/org/apache/geode/internal/statistics/oshi/ProcessStats.java b/geode-core/src/main/java/org/apache/geode/internal/statistics/oshi/ProcessStats.java index 1e6199e..2fddd0c 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/statistics/oshi/ProcessStats.java +++ b/geode-core/src/main/java/org/apache/geode/internal/statistics/oshi/ProcessStats.java @@ -45,7 +45,7 @@ public class ProcessStats { final StatisticsTypeFactory f = StatisticsTypeFactoryImpl.singleton(); statisticsType = f.createType("ProcessStats", "Statistics on a process.", - new StatisticDescriptor[]{ + new StatisticDescriptor[] { f.createLongGauge("virtualSize", "Gets the Virtual Memory Size (VSZ). Includes all memory that the process can access, including memory that is swapped out and memory that is from shared libraries.", "bytes"), diff --git a/geode-core/src/main/java/org/apache/geode/internal/statistics/oshi/ProcessorStats.java b/geode-core/src/main/java/org/apache/geode/internal/statistics/oshi/ProcessorStats.java index 1303901..be69378 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/statistics/oshi/ProcessorStats.java +++ b/geode-core/src/main/java/org/apache/geode/internal/statistics/oshi/ProcessorStats.java @@ -73,7 +73,7 @@ public class ProcessorStats { f.createDoubleGauge("processorCpuLoad", "CPU usage", "percent"), - }); + }); currentFreq = statisticsType.nameToId("currentFreq"); processorCpuLoadTicksUSER = statisticsType.nameToId("processorCpuLoadTicksUSER"); diff --git a/geode-core/src/test/java/org/apache/geode/internal/statistics/oshi/OshiStatisticsTest.java b/geode-core/src/test/java/org/apache/geode/internal/statistics/oshi/OshiStatisticsTest.java index 2837d1c..e87ae72 100644 --- a/geode-core/src/test/java/org/apache/geode/internal/statistics/oshi/OshiStatisticsTest.java +++ b/geode-core/src/test/java/org/apache/geode/internal/statistics/oshi/OshiStatisticsTest.java @@ -15,89 +15,78 @@ package org.apache.geode.internal.statistics.oshi; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import org.junit.Test; -import oshi.hardware.CentralProcessor; -import oshi.hardware.HardwareAbstractionLayer; -import oshi.software.os.OSProcess; -import oshi.software.os.OperatingSystem; - -import org.apache.geode.internal.statistics.SuppliableStatistics; public class OshiStatisticsTest { -// private final OSProcess process = mock(OSProcess.class); -// private final OperatingSystem operatingSystem = mock(OperatingSystem.class); -// private final HardwareAbstractionLayer hardwareAbstractionLayer = mock(HardwareAbstractionLayer.class); -// private final OshiStatistics -// oshiStatistics = new OshiStatistics(operatingSystem, hardwareAbstractionLayer); -// -// -// private final SuppliableStatistics stats = mock(SuppliableStatistics.class); -// -// public OshiStatisticsTest() { -// when(operatingSystem.getProcess(eq(1))).thenReturn(process); -// } -// -// @Test -// public void testInit() { -// assertThat(OshiStatistics.init()).isEqualTo(0); -// } -// -// @Test -// public void updateProcessStats() { -// when(process.getVirtualSize()).thenReturn(42L); -// when(process.getResidentSetSize()).thenReturn(420L); -// when(process.getThreadCount()).thenReturn(4200); -// when(process.getKernelTime()).thenReturn(42000L); -// when(process.getUserTime()).thenReturn(420000L); -// -// oshiStatistics.updateProcessStats(1, stats); -// -// verify(stats).setLong(eq(ProcessStats.virtualSize), eq(42L)); -// verify(stats).setLong(eq(ProcessStats.residentSetSize), eq(420L)); -// verify(stats).setLong(eq(ProcessStats.threadCount), eq(4200L)); -// verify(stats).setLong(eq(ProcessStats.kernelTime), eq(42000L)); -// verify(stats).setLong(eq(ProcessStats.userTime), eq(420000L)); -// } -// -// @Test -// public void updateSystemStats() { -// when(operatingSystem.getProcessCount()).thenReturn(1); -// when(operatingSystem.getThreadCount()).thenReturn(2); -// final CentralProcessor centralProcessor = mock(CentralProcessor.class); -// when(centralProcessor.getContextSwitches()).thenReturn(3L); -// when(centralProcessor.getInterrupts()).thenReturn(4L); -// when(centralProcessor.getPhysicalProcessorCount()).thenReturn(5); -// when(centralProcessor.getLogicalProcessorCount()).thenReturn(6); -// when(centralProcessor.getSystemLoadAverage(eq(3))).thenReturn(new double[]{1.0, 2.0, 3.0}); -// when(centralProcessor.getSystemCpuLoadTicks()).thenReturn(new long[]{1, 2, 3, 4, 5, 6, 7, 8}); -// when(hardwareAbstractionLayer.getProcessor()).thenReturn(centralProcessor); -// -// oshiStatistics.updateSystemStats(stats); -// -// verify(stats).setLong(eq(OperatingSystemStats.processCount), eq(1L)); -// verify(stats).setLong(eq(OperatingSystemStats.threadCount), eq(2L)); -// verify(stats).setLong(eq(OperatingSystemStats.contextSwitches), eq(3L)); -// verify(stats).setLong(eq(OperatingSystemStats.interrupts), eq(4L)); -// verify(stats).setLong(eq(OperatingSystemStats.physicalProcessorCount), eq(5L)); -// verify(stats).setLong(eq(OperatingSystemStats.logicalProcessorCount), eq(6L)); -// verify(stats).setDouble(eq(OperatingSystemStats.systemLoadAverage1), eq(1.0)); -// verify(stats).setDouble(eq(OperatingSystemStats.systemLoadAverage5), eq(2.0)); -// verify(stats).setDouble(eq(OperatingSystemStats.systemLoadAverage15), eq(3.0)); -// verify(stats).setLong(eq(OperatingSystemStats.systemCpuLoadTicksUSER), eq(1L)); -// verify(stats).setLong(eq(OperatingSystemStats.systemCpuLoadTicksNICE), eq(2L)); -// verify(stats).setLong(eq(OperatingSystemStats.systemCpuLoadTicksSYSTEM), eq(3L)); -// verify(stats).setLong(eq(OperatingSystemStats.systemCpuLoadTicksIDLE), eq(4L)); -// verify(stats).setLong(eq(OperatingSystemStats.systemCpuLoadTicksIOWAIT), eq(5L)); -// verify(stats).setLong(eq(OperatingSystemStats.systemCpuLoadTicksIRQ), eq(6L)); -// verify(stats).setLong(eq(OperatingSystemStats.systemCpuLoadTicksSOFTIRQ), eq(7L)); -// verify(stats).setLong(eq(OperatingSystemStats.systemCpuLoadTicksSTEAL), eq(8L)); -// } + // private final OSProcess process = mock(OSProcess.class); + // private final OperatingSystem operatingSystem = mock(OperatingSystem.class); + // private final HardwareAbstractionLayer hardwareAbstractionLayer = + // mock(HardwareAbstractionLayer.class); + // private final OshiStatistics + // oshiStatistics = new OshiStatistics(operatingSystem, hardwareAbstractionLayer); + // + // + // private final SuppliableStatistics stats = mock(SuppliableStatistics.class); + // + // public OshiStatisticsTest() { + // when(operatingSystem.getProcess(eq(1))).thenReturn(process); + // } + // + // @Test + // public void testInit() { + // assertThat(OshiStatistics.init()).isEqualTo(0); + // } + // + // @Test + // public void updateProcessStats() { + // when(process.getVirtualSize()).thenReturn(42L); + // when(process.getResidentSetSize()).thenReturn(420L); + // when(process.getThreadCount()).thenReturn(4200); + // when(process.getKernelTime()).thenReturn(42000L); + // when(process.getUserTime()).thenReturn(420000L); + // + // oshiStatistics.updateProcessStats(1, stats); + // + // verify(stats).setLong(eq(ProcessStats.virtualSize), eq(42L)); + // verify(stats).setLong(eq(ProcessStats.residentSetSize), eq(420L)); + // verify(stats).setLong(eq(ProcessStats.threadCount), eq(4200L)); + // verify(stats).setLong(eq(ProcessStats.kernelTime), eq(42000L)); + // verify(stats).setLong(eq(ProcessStats.userTime), eq(420000L)); + // } + // + // @Test + // public void updateSystemStats() { + // when(operatingSystem.getProcessCount()).thenReturn(1); + // when(operatingSystem.getThreadCount()).thenReturn(2); + // final CentralProcessor centralProcessor = mock(CentralProcessor.class); + // when(centralProcessor.getContextSwitches()).thenReturn(3L); + // when(centralProcessor.getInterrupts()).thenReturn(4L); + // when(centralProcessor.getPhysicalProcessorCount()).thenReturn(5); + // when(centralProcessor.getLogicalProcessorCount()).thenReturn(6); + // when(centralProcessor.getSystemLoadAverage(eq(3))).thenReturn(new double[]{1.0, 2.0, 3.0}); + // when(centralProcessor.getSystemCpuLoadTicks()).thenReturn(new long[]{1, 2, 3, 4, 5, 6, 7, 8}); + // when(hardwareAbstractionLayer.getProcessor()).thenReturn(centralProcessor); + // + // oshiStatistics.updateSystemStats(stats); + // + // verify(stats).setLong(eq(OperatingSystemStats.processCount), eq(1L)); + // verify(stats).setLong(eq(OperatingSystemStats.threadCount), eq(2L)); + // verify(stats).setLong(eq(OperatingSystemStats.contextSwitches), eq(3L)); + // verify(stats).setLong(eq(OperatingSystemStats.interrupts), eq(4L)); + // verify(stats).setLong(eq(OperatingSystemStats.physicalProcessorCount), eq(5L)); + // verify(stats).setLong(eq(OperatingSystemStats.logicalProcessorCount), eq(6L)); + // verify(stats).setDouble(eq(OperatingSystemStats.systemLoadAverage1), eq(1.0)); + // verify(stats).setDouble(eq(OperatingSystemStats.systemLoadAverage5), eq(2.0)); + // verify(stats).setDouble(eq(OperatingSystemStats.systemLoadAverage15), eq(3.0)); + // verify(stats).setLong(eq(OperatingSystemStats.systemCpuLoadTicksUSER), eq(1L)); + // verify(stats).setLong(eq(OperatingSystemStats.systemCpuLoadTicksNICE), eq(2L)); + // verify(stats).setLong(eq(OperatingSystemStats.systemCpuLoadTicksSYSTEM), eq(3L)); + // verify(stats).setLong(eq(OperatingSystemStats.systemCpuLoadTicksIDLE), eq(4L)); + // verify(stats).setLong(eq(OperatingSystemStats.systemCpuLoadTicksIOWAIT), eq(5L)); + // verify(stats).setLong(eq(OperatingSystemStats.systemCpuLoadTicksIRQ), eq(6L)); + // verify(stats).setLong(eq(OperatingSystemStats.systemCpuLoadTicksSOFTIRQ), eq(7L)); + // verify(stats).setLong(eq(OperatingSystemStats.systemCpuLoadTicksSTEAL), eq(8L)); + // } -} \ No newline at end of file +}