本文整理汇总了Java中oshi.hardware.GlobalMemory类的典型用法代码示例。如果您正苦于以下问题:Java GlobalMemory类的具体用法?Java GlobalMemory怎么用?Java GlobalMemory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GlobalMemory类属于oshi.hardware包,在下文中一共展示了GlobalMemory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import oshi.hardware.GlobalMemory; //导入依赖的package包/类
public static Process create(OSProcess process, GlobalMemory memory) {
return new Process(process.getName(),
process.getPath(),
process.getCommandLine(),
process.getUser(),
process.getUserID(),
process.getGroup(),
process.getGroupID(),
process.getState(),
process.getProcessID(),
process.getParentProcessID(),
process.getThreadCount(),
process.getPriority(),
process.getVirtualSize(),
process.getResidentSetSize(),
100d * process.getResidentSetSize() / memory.getTotal(),
process.getKernelTime(), process.getUserTime(),
process.getUpTime(),
100d * (process.getKernelTime() + process.getUserTime()) / process.getUpTime(),
process.getStartTime(),
process.getBytesRead(),
process.getBytesWritten());
}
示例2: getSystemHappyPath
import oshi.hardware.GlobalMemory; //导入依赖的package包/类
@Test
public void getSystemHappyPath() throws Exception {
OperatingSystem operatingSystem = mock(OperatingSystem.class);
CentralProcessor centralProcessor = mock(CentralProcessor.class);
GlobalMemory globalMemory = mock(GlobalMemory.class);
when(provider.systemInfo()).thenReturn(
new com.krillsson.sysapi.core.domain.system.SystemInfo("theHost", PlatformEnum.LINUX, operatingSystem,
new CpuInfo(centralProcessor, 4, 80,
new CpuLoad(100, 0, 0, 0, 0, 0, 0, 0, 0),
new CpuHealth(new double[0], 120, 1000, 10)),
globalMemory,
new PowerSource[0]));
final SystemInfo response = RESOURCES.getJerseyTest().target("/system")
.request(MediaType.APPLICATION_JSON_TYPE)
.get(SystemInfo.class);
assertNotNull(response);
assertEquals(response.getCpuInfo().getCpuLoad().getCpuLoadCountingTicks(), 100, 0);
}
示例3: getProcessesCorrectLimit
import oshi.hardware.GlobalMemory; //导入依赖的package包/类
@Test
public void getProcessesCorrectLimit() throws Exception {
ArgumentCaptor<Integer> captor = ArgumentCaptor.forClass(Integer.class);
when(provider.processesInfo(any(OperatingSystem.ProcessSort.class), captor.capture()))
.thenReturn(new ProcessesInfo(mock(GlobalMemory.class), 0, 0, 0,
new Process[]{process}));
ProcessInfo processInfo = RESOURCES.getJerseyTest().target("/processes")
.queryParam("limit", "10")
.request(MediaType.APPLICATION_JSON_TYPE)
.get(ProcessInfo.class);
assertEquals(captor.getValue(), new Integer(10));
assertThat(processInfo.getProcesses()[0].getName(), is(equalToIgnoringCase("name")));
assertThat(processInfo.getProcesses()[0].getState(), is(equalToIgnoringCase(process.getState().name())));
}
示例4: getProcessesCorrectSortingMethod
import oshi.hardware.GlobalMemory; //导入依赖的package包/类
@Test
public void getProcessesCorrectSortingMethod() throws Exception {
ArgumentCaptor<OperatingSystem.ProcessSort> captor = ArgumentCaptor.forClass(OperatingSystem.ProcessSort.class);
when(provider.processesInfo(captor.capture(), anyInt()))
.thenReturn(new ProcessesInfo(mock(GlobalMemory.class), 0, 0, 0,
new Process[]{process}));
ProcessInfo processInfo = RESOURCES.getJerseyTest().target("/processes")
.queryParam("sortBy", "MEMORY")
.request(MediaType.APPLICATION_JSON_TYPE)
.get(ProcessInfo.class);
assertEquals(captor.getValue(), OperatingSystem.ProcessSort.MEMORY);
assertThat(processInfo.getProcesses()[0].getName(), is(equalToIgnoringCase("name")));
assertThat(processInfo.getProcesses()[0].getState(), is(equalToIgnoringCase(process.getState().name())));
}
示例5: printProcesses
import oshi.hardware.GlobalMemory; //导入依赖的package包/类
/**
* Prints the processes.
*
* @param os the os
* @param memory the memory
*/
private static void printProcesses(OperatingSystem os, GlobalMemory memory) {
oshi.add("Processes: " + os.getProcessCount() + ", Threads: " + os.getThreadCount());
// Sort by highest CPU
List<OSProcess> procs = Arrays.asList(os.getProcesses(5, ProcessSort.CPU));
oshi.add(" PID %CPU %MEM VSZ RSS Name");
for (int i = 0; i < procs.size() && i < 5; i++) {
OSProcess p = procs.get(i);
oshi.add(String.format(" %5d %5.1f %4.1f %9s %9s %s%n", p.getProcessID(),
100d * (p.getKernelTime() + p.getUserTime()) / p.getUpTime(),
100d * p.getResidentSetSize() / memory.getTotal(),
FormatUtil.formatBytes(p.getVirtualSize()),
FormatUtil.formatBytes(p.getResidentSetSize()), p.getName()));
}
}
示例6: getMemory
import oshi.hardware.GlobalMemory; //导入依赖的package包/类
@Test
public void getMemory() {
OshiPlatformCache oshi = newOshiPlatformCache();
GlobalMemory memory = oshi.getMemory();
Assert.assertNotNull(memory);
long avail = memory.getAvailable();
long total = memory.getTotal();
Assert.assertTrue(avail > -1L);
Assert.assertTrue(total > -1L);
print("===MEMORY ===");
print(" Available=[%s] (%d)", FormatUtil.formatBytes(avail), avail);
print(" Total=[%s] (%d)", FormatUtil.formatBytes(total), total);
print(" toString=[%s]", memory.toString());
}
示例7: recordStats
import oshi.hardware.GlobalMemory; //导入依赖的package包/类
private void recordStats() {
SystemInfo si = new SystemInfo();
HardwareAbstractionLayer hal = si.getHardware();
GlobalMemory mem = hal.getMemory();
long total = 0;
long free = 0;
File[] roots = File.listRoots();
for (File root : roots) {
total += root.getTotalSpace();
free += root.getFreeSpace();
}
// Stuff accessing sponge needs to be run on the server main thread
WebAPI.runOnMain(() -> {
averageTps.add(new ServerStat<>(Sponge.getServer().getTicksPerSecond()));
onlinePlayers.add(new ServerStat<>(Sponge.getServer().getOnlinePlayers().size()));
});
cpuLoad.add(new ServerStat<>(hal.getProcessor().getSystemCpuLoadBetweenTicks()));
memoryLoad.add(new ServerStat<>((mem.getTotal() - mem.getAvailable()) / (double)mem.getTotal()));
diskUsage.add(new ServerStat<>((total - free) / (double)total));
while (averageTps.size() > MAX_STATS_ENTRIES)
averageTps.poll();
while (onlinePlayers.size() > MAX_STATS_ENTRIES)
onlinePlayers.poll();
while (cpuLoad.size() > MAX_STATS_ENTRIES)
cpuLoad.poll();
while (memoryLoad.size() > MAX_STATS_ENTRIES)
memoryLoad.poll();
while (diskUsage.size() > MAX_STATS_ENTRIES)
diskUsage.poll();
}
示例8: ProcessesInfo
import oshi.hardware.GlobalMemory; //导入依赖的package包/类
public ProcessesInfo(GlobalMemory memory, long processId, long threadCount, long processCount, Process[] processes) {
this.memory = memory;
this.processId = processId;
this.threadCount = threadCount;
this.processCount = processCount;
this.processes = processes;
}
示例9: SystemInfo
import oshi.hardware.GlobalMemory; //导入依赖的package包/类
public SystemInfo(String hostName, PlatformEnum platformEnum, OperatingSystem operatingSystem, CpuInfo cpuInfo, GlobalMemory memory, PowerSource[] powerSources) {
this.hostName = hostName;
this.platformEnum = platformEnum;
this.operatingSystem = operatingSystem;
this.cpuInfo = cpuInfo;
this.memory = memory;
this.powerSources = powerSources;
}
示例10: getProcessesHappyPath
import oshi.hardware.GlobalMemory; //导入依赖的package包/类
@Test
public void getProcessesHappyPath() throws Exception {
when(provider.processesInfo(any(OperatingSystem.ProcessSort.class), anyInt()))
.thenReturn(new ProcessesInfo(mock(GlobalMemory.class), 0, 0, 0,
new Process[]{process}));
final ProcessInfo response = RESOURCES.getJerseyTest().target("/processes")
.request(MediaType.APPLICATION_JSON_TYPE)
.get(ProcessInfo.class);
assertNotNull(response);
assertEquals(response.getProcesses().length, 1);
assertThat(response.getProcesses()[0].getName(), is(equalToIgnoringCase("name")));
assertThat(response.getProcesses()[0].getState(), is(equalToIgnoringCase(process.getState().name())));
}
示例11: getMemoryHappyPath
import oshi.hardware.GlobalMemory; //导入依赖的package包/类
@Test
public void getMemoryHappyPath() throws Exception {
GlobalMemory memory = mock(GlobalMemory.class);
when(memory.getAvailable()).thenReturn(100L);
when(memory.getSwapTotal()).thenReturn(100L);
when(memory.getTotal()).thenReturn(100L);
when(provider.globalMemory()).thenReturn(memory);
final com.krillsson.sysapi.dto.memory.GlobalMemory response = RESOURCES.getJerseyTest().target("/memory")
.request(MediaType.APPLICATION_JSON_TYPE)
.get(com.krillsson.sysapi.dto.memory.GlobalMemory.class);
assertNotNull(response);
assertEquals(response.getAvailable(), 100, 0);
}
示例12: printMemory
import oshi.hardware.GlobalMemory; //导入依赖的package包/类
/**
* Prints the memory.
*
* @param memory the memory
*/
private static void printMemory(GlobalMemory memory) {
oshi.add("Memory: " + FormatUtil.formatBytes(memory.getAvailable()) + "/"
+ FormatUtil.formatBytes(memory.getTotal()));
oshi.add("Swap used: " + FormatUtil.formatBytes(memory.getSwapUsed()) + "/"
+ FormatUtil.formatBytes(memory.getSwapTotal()));
}
示例13: getMemoryMetric
import oshi.hardware.GlobalMemory; //导入依赖的package包/类
/**
* Returns the given memory metric's value.
*
* @param metricToCollect the metric to collect
* @return the value of the metric
*/
public Double getMemoryMetric(ID metricToCollect) {
GlobalMemory mem = getMemory();
if (PlatformMetricType.MEMORY_AVAILABLE.getMetricTypeId().equals(metricToCollect)) {
return Double.valueOf(mem.getAvailable());
} else if (PlatformMetricType.MEMORY_TOTAL.getMetricTypeId().equals(metricToCollect)) {
return Double.valueOf(mem.getTotal());
} else {
throw new UnsupportedOperationException("Invalid memory metric to collect: " + metricToCollect);
}
}
示例14: getSystemInfo
import oshi.hardware.GlobalMemory; //导入依赖的package包/类
/**
* Collects and returns system information.
*
* @return A {@link List} of {@link String}s containing the collected system
* information.
*/
public static List<String> getSystemInfo() {
List<String> result = new ArrayList<>();
StringBuilder sb = new StringBuilder();
long jvmMemory = Runtime.getRuntime().maxMemory();
OperatingSystem os = null;
CentralProcessor processor = null;
GlobalMemory memory = null;
try {
SystemInfo systemInfo = new SystemInfo();
HardwareAbstractionLayer hardware = systemInfo.getHardware();
os = systemInfo.getOperatingSystem();
processor = hardware.getProcessor();
memory = hardware.getMemory();
} catch (Error e) {
LOGGER.debug("Could not retrieve system information: {}", e.getMessage());
LOGGER.trace("", e);
}
sb.append("JVM: ").append(System.getProperty("java.vm.name")).append(" ")
.append(System.getProperty("java.version")).append(" (")
.append(System.getProperty("sun.arch.data.model")).append("-bit) by ")
.append(System.getProperty("java.vendor"));
result.add(sb.toString());
sb.setLength(0);
sb.append("OS: ");
if (os != null && isNotBlank(os.toString())) {
sb.append(os.toString()).append(" ").append(getOSBitness()).append("-bit");
} else {
sb.append(System.getProperty("os.name")).append(" ").append(getOSBitness()).append("-bit ");
sb.append(System.getProperty("os.version"));
}
result.add(sb.toString());
sb.setLength(0);
if (processor != null) {
sb.append("CPU: ").append(processor.getName()).append(" with ")
.append(processor.getPhysicalProcessorCount());
if (processor.getPhysicalProcessorCount() > 1) {
sb.append(" cores");
} else {
sb.append(" core");
}
if (processor.getLogicalProcessorCount() != processor.getPhysicalProcessorCount()) {
sb.append(" (").append(processor.getLogicalProcessorCount());
if (processor.getLogicalProcessorCount() > 1) {
sb.append(" virtual cores)");
} else {
sb.append(" virtual core)");
}
}
result.add(sb.toString());
sb.setLength(0);
}
if (memory != null) {
sb.append("Physical Memory: ").append(StringUtil.formatBytes(memory.getTotal(), true));
result.add(sb.toString());
sb.setLength(0);
sb.append("Free Memory: ").append(StringUtil.formatBytes(memory.getAvailable(), true));
result.add(sb.toString());
sb.setLength(0);
}
sb.append("Maximum JVM Memory: ");
if (jvmMemory == Long.MAX_VALUE) {
sb.append("Unlimited");
} else {
sb.append(StringUtil.formatBytes(jvmMemory, true));
}
result.add(sb.toString());
return result;
}
示例15: getMemory
import oshi.hardware.GlobalMemory; //导入依赖的package包/类
public GlobalMemory getMemory() {
return memory;
}