本文整理汇总了Java中oshi.software.os.OperatingSystem类的典型用法代码示例。如果您正苦于以下问题:Java OperatingSystem类的具体用法?Java OperatingSystem怎么用?Java OperatingSystem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OperatingSystem类属于oshi.software.os包,在下文中一共展示了OperatingSystem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ProcessesPanel
import oshi.software.os.OperatingSystem; //导入依赖的package包/类
public ProcessesPanel(ServiceHolder services) {
super(new BorderLayout());
sort = OperatingSystem.ProcessSort.MEMORY;
dateFormat = new SimpleDateFormat("HH 'hours,' mm 'minutes and' ss 'seconds'");
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
this.services = services;
isWindows = System.getProperty("os.name").toLowerCase().contains("win");
buttonPanel = new JPanel(new FlowLayout());
dataPanel = new JPanel();
setupPanel();
if(isWindows) {
setupDataWin(sort);
} else {
setupDataUnix(sort);
}
}
示例2: getProcessRecentCpuUsage
import oshi.software.os.OperatingSystem; //导入依赖的package包/类
private double getProcessRecentCpuUsage() {
double output = 0d;
HardwareAbstractionLayer hal = si.getHardware();
OperatingSystem os = si.getOperatingSystem();
OSProcess p = os.getProcess(os.getProcessId());
if (cpuTime != 0) {
double uptimeDiff = p.getUpTime() - uptime;
double cpuDiff = (p.getKernelTime() + p.getUserTime()) - cpuTime;
output = cpuDiff / uptimeDiff;
} else {
output = ((double) (p.getKernelTime() + p.getUserTime())) / (double) p.getUserTime();
}
// Record for next invocation
uptime = p.getUpTime();
cpuTime = p.getKernelTime() + p.getUserTime();
return output / hal.getProcessor().getLogicalProcessorCount();
}
示例3: getRoot
import oshi.software.os.OperatingSystem; //导入依赖的package包/类
@GET
@RolesAllowed(BasicAuthorizer.AUTHENTICATED_ROLE)
public ProcessInfo getRoot(@Auth UserConfiguration user, @QueryParam("sortBy") Optional<String> processSort, @QueryParam("limit") Optional<Integer> limit) {
OperatingSystem.ProcessSort sortBy = OperatingSystem.ProcessSort.NAME;
if (processSort.isPresent()) {
String method = processSort.get().toUpperCase();
try {
sortBy = OperatingSystem.ProcessSort.valueOf(method);
} catch (IllegalArgumentException e) {
String validOptions = Arrays.stream(OperatingSystem.ProcessSort.values()).map(Enum::name).collect(Collectors.joining(", ", "Valid options are: ", "."));
LOGGER.error("No process sort method of type {} was found. {}", method, validOptions);
throw new WebApplicationException(String.format("No process sort method of type %s was found. %s", method, validOptions),
Response.Status.BAD_REQUEST);
}
}
Integer theLimit = limit.orElse(0);
if(theLimit < 0){
String message = String.format("limit cannot be negative (%d)", theLimit);
LOGGER.error(message);
throw new WebApplicationException(message, Response.Status.BAD_REQUEST);
}
ProcessesInfo value = provider.processesInfo(sortBy, theLimit);
return ProcessInfoMapper.INSTANCE.map(value);
}
示例4: getSystemHappyPath
import oshi.software.os.OperatingSystem; //导入依赖的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);
}
示例5: getProcessesCorrectLimit
import oshi.software.os.OperatingSystem; //导入依赖的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())));
}
示例6: getProcessesCorrectSortingMethod
import oshi.software.os.OperatingSystem; //导入依赖的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())));
}
示例7: printProcesses
import oshi.software.os.OperatingSystem; //导入依赖的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()));
}
}
示例8: update
import oshi.software.os.OperatingSystem; //导入依赖的package包/类
private void update() {
List<OSProcess> procs = Arrays.asList(os.getProcesses(10, OperatingSystem.ProcessSort.CPU));
for (OSProcess process : procs) {
ProcessBean bean = null;
if(processList.getItems().size() <= procs.indexOf(process)) {
bean = beanManager.create(ProcessBean.class);
processList.getItems().add(bean);
} else {
bean = processList.getItems().get(procs.indexOf(process));
}
bean.setProcessID(new Integer(process.getProcessID()).toString());
bean.setCpuPercentage(format.format(100d * (process.getKernelTime() + process.getUserTime()) / process.getUpTime()));
bean.setMemoryPercentage(format.format(100d * process.getResidentSetSize() / memory.getTotal()));
bean.setName(process.getName());
}
asyncServerRunner.execute(new Runnable() {
@Override
public void run() {
sessionExecutor.runLaterInClientSession(() -> update());
}
});
}
示例9: getOperatingSystemInfo
import oshi.software.os.OperatingSystem; //导入依赖的package包/类
@Test
public void getOperatingSystemInfo() {
OshiPlatformCache oshi = newOshiPlatformCache();
OperatingSystem os = oshi.getOperatingSystem();
Assert.assertNotNull(os);
String family = os.getFamily();
String manu = os.getManufacturer();
OperatingSystemVersion version = os.getVersion();
Assert.assertNotNull(family);
Assert.assertNotNull(manu);
Assert.assertNotNull(version);
print("===OPERATION SYSTEM==");
print(" Family=[%s]", family);
print(" Manufacturer=[%s]", manu);
print(" Version=[%s](%s)", version, version.getClass());
print(" toString=[%s]", os.toString());
}
示例10: setupDataUnix
import oshi.software.os.OperatingSystem; //导入依赖的package包/类
private void setupDataUnix(OperatingSystem.ProcessSort sort) {
OSProcess[] processes = services.processorService.getProcessesList(sort);
data = new String[processes.length][5];
for(int i = 0; i < processes.length; i++) {
// path, uptime, pid, name
data[i][0] = processes[i].getName();
data[i][1] = Integer.toString(processes[i].getProcessID());
data[i][2] = Long.toString(processes[i].getResidentSetSize() / (1024 * 1024)) + " MB";
}
}
示例11: actionPerformed
import oshi.software.os.OperatingSystem; //导入依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == sortByMemory) {
sort = OperatingSystem.ProcessSort.MEMORY;
} else if(e.getSource() == sortByName) {
sort = OperatingSystem.ProcessSort.NAME;
} else if(e.getSource() == sortByPID) {
sort = OperatingSystem.ProcessSort.PID;
}
updateStats();
}
示例12: ServiceHolder
import oshi.software.os.OperatingSystem; //导入依赖的package包/类
public ServiceHolder() {
SystemInfo si = new SystemInfo();
HardwareAbstractionLayer hal = si.getHardware();
OperatingSystem os = si.getOperatingSystem();
batteryService = new BatteryService(si, hal, os);
processorService = new ProcessorService(si, hal, os);
memoryService = new MemoryService(si, hal, os);
diskService = new DiskService();
}
示例13: connectToDataSource
import oshi.software.os.OperatingSystem; //导入依赖的package包/类
@Override
public void connectToDataSource() throws EqIOException {
IEquipmentMessageSender sender = getEquipmentMessageSender();
sender.confirmEquipmentStateOK();
SystemInfo si = new SystemInfo();
HardwareAbstractionLayer hal = si.getHardware();
OperatingSystem os = si.getOperatingSystem();
String hostName = System.getProperty("c2mon.daq.hostname");
Executors.newScheduledThreadPool(1).scheduleAtFixedRate(() -> {
try {
sender.update(hostName + "/mem.avail", new ValueUpdate(hal.getMemory().getAvailable()));
sender.update(hostName + "/mem.swap.used", new ValueUpdate(hal.getMemory().getSwapUsed()));
sender.update(hostName + "/cpu.loadavg", new ValueUpdate(hal.getProcessor().getSystemLoadAverage()));
sender.update(hostName + "/cpu.temp", new ValueUpdate(hal.getSensors().getCpuTemperature()));
sender.update(hostName + "/cpu.voltage", new ValueUpdate(hal.getSensors().getCpuVoltage()));
sender.update(hostName + "/os.numprocs", new ValueUpdate(os.getProcessCount()));
sender.update(hostName + "/os.numthreads", new ValueUpdate(os.getThreadCount()));
sender.update(hostName + "/os.fds", new ValueUpdate(os.getFileSystem().getOpenFileDescriptors()));
} catch (Exception e) {
log.error("Error sending tag update", e);
}
}, 0, 1, SECONDS);
Executors.newScheduledThreadPool(1).scheduleAtFixedRate(() -> {
sender.sendSupervisionAlive();
}, 0, 30, SECONDS);
}
示例14: getSystemParameters
import oshi.software.os.OperatingSystem; //导入依赖的package包/类
private static String getSystemParameters() {
try {
SystemInfo si = new SystemInfo();
OperatingSystem os = si.getOperatingSystem();
HardwareAbstractionLayer hal = si.getHardware();
int megabyte = 1024 * 1024;
return "\n==========================System=========================" + "\r\n" +
"System:" + "\r\n" +
"\tOS: " + os.getManufacturer() + " " + os.getFamily() + " " +
os.getVersion() + " x" + getRealSystemArch() + "\r\n" +
"Hardware:" + "\r\n" +
"\tProcessors: " + Runtime.getRuntime().availableProcessors() + "\r\n" +
"\tTotal JVM memory: " + Runtime.getRuntime().maxMemory() / megabyte + " MB " +
"free:" + Runtime.getRuntime().freeMemory() / megabyte + " MB \r\n" +
"Java:" + "\r\n" +
"\tJava version: " + System.getProperty("java.specification.version") + "(" +
System.getProperty("java.version") + ")" + "\r\n" +
"\t" + System.getProperty("java.runtime.name") + " v" +
System.getProperty("java.vm.version") + "\r\n" +
"=========================================================" + "\r\n";
} catch (Exception e) {
log.warn("Could not show system parameters, proceeding", e);
return "";
}
}
示例15: run
import oshi.software.os.OperatingSystem; //导入依赖的package包/类
@Override
public void run(SystemApiConfiguration config, Environment environment) throws Exception {
this.environment = environment;
if (config.forwardHttps()) {
addHttpsForward(environment.getApplicationContext());
}
environment.jersey().register(RolesAllowedDynamicFeature.class);
final BasicCredentialAuthFilter<UserConfiguration> userBasicCredentialAuthFilter =
new BasicCredentialAuthFilter.Builder<UserConfiguration>()
.setAuthenticator(new BasicAuthenticator(config.getUser()))
.setRealm("System-Api")
.setAuthorizer(new BasicAuthorizer(config.getUser()))
.buildAuthFilter();
SystemInfo systemInfo = new SystemInfo();
HardwareAbstractionLayer hal = systemInfo.getHardware();
OperatingSystem os = systemInfo.getOperatingSystem();
environment.jersey().register(new AuthDynamicFeature(userBasicCredentialAuthFilter));
environment.jersey().register(new AuthValueFactoryProvider.Binder(UserConfiguration.class));
SpeedMeasurementManager speedMeasurementManager = new SpeedMeasurementManager(Executors.newScheduledThreadPool(5), Clock.systemUTC(), 5);
InfoProvider provider = new InfoProviderFactory(hal, os, SystemInfo.getCurrentPlatformEnum(), config, speedMeasurementManager).provide();
environment.lifecycle().manage(speedMeasurementManager);
environment.jersey().register(new SystemResource(provider));
environment.jersey().register(new DiskStoresResource(provider));
environment.jersey().register(new GpuResource(provider));
environment.jersey().register(new MemoryResource(provider));
environment.jersey().register(new NetworkInterfacesResource(provider));
environment.jersey().register(new PowerSourcesResource(provider));
environment.jersey().register(new ProcessesResource(provider));
environment.jersey().register(new CpuResource(provider));
environment.jersey().register(new SensorsResource(provider));
environment.jersey().register(new MotherboardResource(provider));
environment.jersey().register(new MetaInfoResource(getVersionFromManifest(), getEndpoints(environment), os.getProcessId()));
}