当前位置: 首页>>代码示例>>Java>>正文


Java OperatingSystem类代码示例

本文整理汇总了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);
    }
}
 
开发者ID:ozankaraali,项目名称:SystemMonitor,代码行数:23,代码来源:ProcessesPanel.java

示例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();
}
 
开发者ID:Frederikam,项目名称:Lavalink,代码行数:20,代码来源:StatsTask.java

示例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);
}
 
开发者ID:Krillsson,项目名称:sys-api,代码行数:26,代码来源:ProcessesResource.java

示例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);
}
 
开发者ID:Krillsson,项目名称:sys-api,代码行数:20,代码来源:SystemInfoResourceTest.java

示例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())));
}
 
开发者ID:Krillsson,项目名称:sys-api,代码行数:17,代码来源:ProcessesResourceTest.java

示例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())));
}
 
开发者ID:Krillsson,项目名称:sys-api,代码行数:17,代码来源:ProcessesResourceTest.java

示例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()));
  }
}
 
开发者ID:psi-probe,项目名称:psi-probe,代码行数:22,代码来源:OshiController.java

示例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());
        }
    });
}
 
开发者ID:canoo,项目名称:dolphin-platform,代码行数:23,代码来源:ProcessMonitorController.java

示例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());
}
 
开发者ID:hawkular,项目名称:hawkular-agent,代码行数:22,代码来源:OshiPlatformCacheTest.java

示例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";
    }
}
 
开发者ID:ozankaraali,项目名称:SystemMonitor,代码行数:12,代码来源:ProcessesPanel.java

示例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();
}
 
开发者ID:ozankaraali,项目名称:SystemMonitor,代码行数:13,代码来源:ProcessesPanel.java

示例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();
}
 
开发者ID:ozankaraali,项目名称:SystemMonitor,代码行数:11,代码来源:ServiceHolder.java

示例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);
}
 
开发者ID:c2mon,项目名称:c2mon-daq-hostmetrics,代码行数:31,代码来源:HostMetricsMessageHandler.java

示例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 "";
    }
}
 
开发者ID:benchdoos,项目名称:WeblocOpener,代码行数:28,代码来源:SystemUtils.java

示例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()));
}
 
开发者ID:Krillsson,项目名称:sys-api,代码行数:41,代码来源:SystemApiApplication.java


注:本文中的oshi.software.os.OperatingSystem类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。