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


Java HardwareAbstractionLayer类代码示例

本文整理汇总了Java中oshi.hardware.HardwareAbstractionLayer的典型用法代码示例。如果您正苦于以下问题:Java HardwareAbstractionLayer类的具体用法?Java HardwareAbstractionLayer怎么用?Java HardwareAbstractionLayer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HardwareAbstractionLayer类属于oshi.hardware包,在下文中一共展示了HardwareAbstractionLayer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getProcessRecentCpuUsage

import oshi.hardware.HardwareAbstractionLayer; //导入依赖的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

示例2: outputSystemCpuLoad

import oshi.hardware.HardwareAbstractionLayer; //导入依赖的package包/类
private void outputSystemCpuLoad(
        final HardwareAbstractionLayer hal,
        final long sleepTime) {

    long[] ticks0 = hal.getProcessors()[0].getSystemCpuLoadTicks();
    m_logger.info("CPU ticks @0: {}", Arrays.toString(ticks0));
    Util.sleep(sleepTime); // Sleep n seconds
    long[] ticks1 = hal.getProcessors()[0].getSystemCpuLoadTicks();
    m_logger.info("CPU ticks @1: {}", Arrays.toString(ticks1));

    long user = ticks1[0] - ticks0[0]; // user ticks
    long nice = ticks1[1] - ticks0[1]; // nice ticks
    long sys = ticks1[2] - ticks0[2]; // sys ticks
    long idle = ticks1[3] - ticks0[3]; // idle ticks
    long total = user + nice + sys + idle;

    m_logger.info("User: {} Nice: {} System: {} Idle: {} (tick period: {})",
            100d * user / total,
            100d * nice / total,
            100d * sys / total,
            100d * idle / total,
            sleepTime);
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:24,代码来源:OshiTest.java

示例3: connectToDataSource

import oshi.hardware.HardwareAbstractionLayer; //导入依赖的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

示例4: ServiceHolder

import oshi.hardware.HardwareAbstractionLayer; //导入依赖的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

示例5: getServiceInfo

import oshi.hardware.HardwareAbstractionLayer; //导入依赖的package包/类
public static ServiceInfo getServiceInfo()
{
	SystemInfo si = new SystemInfo();
	HardwareAbstractionLayer hal = si.getHardware();
	ServiceInfo serviceInfo=ServiceInfo.newBuilder()
							.setHostName(si.getOperatingSystem().getNetworkParams().getHostName())
							.setTotalRam(String.valueOf(si.getHardware().getMemory().getAvailable()))
							.build();
	return serviceInfo;
}
 
开发者ID:laddcn,项目名称:grpcx,代码行数:11,代码来源:GetSysInfoUtil.java

示例6: main

import oshi.hardware.HardwareAbstractionLayer; //导入依赖的package包/类
public static void main(String[] args) {
    SystemInfo systemInfo = new SystemInfo();
    HardwareAbstractionLayer hardware = systemInfo.getHardware();
    Memory memory = hardware.getMemory();
    System.out.println(memory.getAvailable() / 1024. / 1024. / 1024.);
    System.out.println(memory.getTotal() / 1024. / 1024. / 1024.);

}
 
开发者ID:bingoohuang,项目名称:javacode-demo,代码行数:9,代码来源:OshiMain.java

示例7: getSystemParameters

import oshi.hardware.HardwareAbstractionLayer; //导入依赖的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

示例8: recordStats

import oshi.hardware.HardwareAbstractionLayer; //导入依赖的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();
}
 
开发者ID:Valandur,项目名称:Web-API,代码行数:34,代码来源:ServerService.java

示例9: publishFilesystem

import oshi.hardware.HardwareAbstractionLayer; //导入依赖的package包/类
private void publishFilesystem(final Map<String, Object> sharedData) {
    HardwareAbstractionLayer hal = m_systemInfo.getHardware();
    for (OSFileStore fs : hal.getFileStores()) {

        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;

        String instance = fs.getName() + " (" + fs.getDescription() + ")";
        publishMetric(sharedData, FILESYSTEM_USED, used, instance);
        publishMetric(sharedData, FILESYSTEM_FREE, free, instance);
        publishMetric(sharedData, FILESYSTEM_TOTAL, total, instance);
    }
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:15,代码来源:OshiMetrics.java

示例10: outputSysInfo

import oshi.hardware.HardwareAbstractionLayer; //导入依赖的package包/类
private void outputSysInfo(final SystemInfo sysInfo) {
    
    logger().info("======================================================");
    logger().info("{}", sysInfo.getOperatingSystem());
    logger().info("------------------------------------------------------");
    
    HardwareAbstractionLayer hal = sysInfo.getHardware();
    Processor[] cpus = hal.getProcessors();
    logger().info("CPU count: {}", cpus.length);
    int n = 0;
    for (Processor cpu : cpus) {
        logger().info("{}: {}", n++, cpu);
    }
    
    long memTotal = hal.getMemory().getTotal();
    long memAvail = hal.getMemory().getAvailable();
    long memUsed = memTotal - memAvail;
    
    logger().info("Used memory: {}", FormatUtil.formatBytes(memUsed));
    logger().info("Available memory: {}", FormatUtil.formatBytes(memAvail));
    logger().info("Total memory: {}", FormatUtil.formatBytes(memTotal));

    // This can explode in a NullPointerException (at sun.awt.shell.Win32ShellFolder2.access$200(Win32ShellFolder2.java:72))
    try {
        for (OSFileStore fs : hal.getFileStores()) {
            logger().info("{} ({}) Used: {} Free: {} Total: {}",
                    fs.getName(),
                    fs.getDescription(),
                    FormatUtil.formatBytes(fs.getTotalSpace() - fs.getUsableSpace()),
                    FormatUtil.formatBytes(fs.getUsableSpace()),
                    FormatUtil.formatBytes(fs.getTotalSpace()));
        }
    } catch (Exception e) {
        logger().error("Failed to retrieve file store information", e);
    }
    
    logger().info("======================================================");
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:39,代码来源:Activator.java

示例11: run

import oshi.hardware.HardwareAbstractionLayer; //导入依赖的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

示例12: InfoProviderFactory

import oshi.hardware.HardwareAbstractionLayer; //导入依赖的package包/类
public InfoProviderFactory(HardwareAbstractionLayer hal, OperatingSystem operatingSystem, PlatformEnum os, SystemApiConfiguration configuration, SpeedMeasurementManager speedMeasurementManager) {
    this.hal = hal;
    this.operatingSystem = operatingSystem;
    this.os = os;
    this.configuration = configuration;
    this.speedMeasurementManager = speedMeasurementManager;
    this.utils = new Utils();
}
 
开发者ID:Krillsson,项目名称:sys-api,代码行数:9,代码来源:InfoProviderFactory.java

示例13: setUp

import oshi.hardware.HardwareAbstractionLayer; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    hal = mock(HardwareAbstractionLayer.class);
    os = mock(OperatingSystem.class);
    utils = mock(Utils.class);
    diskProvider = mock(DefaultDiskProvider.class);
    networkProvider = mock(DefaultNetworkProvider.class);
    infoProvider = new TestableRaspbianLinuxInfoProvider(hal, os, utils, networkProvider, diskProvider);
}
 
开发者ID:Krillsson,项目名称:sys-api,代码行数:10,代码来源:RaspbianLinuxInfoProviderTest.java

示例14: setUp

import oshi.hardware.HardwareAbstractionLayer; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    hal = mock(HardwareAbstractionLayer.class);
    os = mock(OperatingSystem.class);
    config = mock(SystemApiConfiguration.class);
    measurementManager = mock(SpeedMeasurementManager.class);
    when(hal.getNetworkIFs()).thenReturn(new NetworkIF[0]);
    when(hal.getDiskStores()).thenReturn(new HWDiskStore[0]);
}
 
开发者ID:Krillsson,项目名称:sys-api,代码行数:10,代码来源:InfoProviderFactoryTest.java

示例15: setUp

import oshi.hardware.HardwareAbstractionLayer; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    hal = mock(HardwareAbstractionLayer.class);
    os = mock(OperatingSystem.class);
    utils = mock(Utils.class);
    diskProvider = mock(DefaultDiskProvider.class);
    networkProvider = mock(DefaultNetworkProvider.class);
    centralProcessor = mock(CentralProcessor.class);
    infoProvider = new DefaultInfoProvider(hal, os, utils, networkProvider, diskProvider);

}
 
开发者ID:Krillsson,项目名称:sys-api,代码行数:12,代码来源:DefaultInfoProviderTest.java


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