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


Java HardwareAbstractionLayer.getFileStores方法代码示例

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


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

示例1: 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

示例2: 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

示例3: testSystemInfo

import oshi.hardware.HardwareAbstractionLayer; //导入方法依赖的package包/类
@Test
public void testSystemInfo() {

    // OSHI supports Windows, OS X and Linux
    if (HostOs.isWindows() || HostOs.isMac() || HostOs.isLinux()) {

        // Operating system
        SystemInfo si = new SystemInfo();
        m_logger.info("{}", si.getOperatingSystem());

        // Hardware: processors
        HardwareAbstractionLayer hal = si.getHardware();
        for (Processor cpu : hal.getProcessors()) {
            m_logger.info("{}", cpu);
        }

        // Hardware: memory
        m_logger.info("Available mem: {}", hal.getMemory().getAvailable());
        m_logger.info("Total mem: {}", hal.getMemory().getTotal());

        // Uptime
        m_logger.info("Uptime: {}", hal.getProcessors()[0].getSystemUptime());

        // Resolve ticks per second
        outputSystemCpuLoad(hal, 1000L);

        // Resolve ticks per 3 seconds
        outputSystemCpuLoad(hal, 3000L);

        // Per CPU load
        outputProcessorLoad(hal, 1000L);
        
        m_logger.info("CPU load: {} (ticks)",
                hal.getProcessors()[0].getSystemCpuLoadBetweenTicks() * 100d);
        m_logger.info("CPU load: {} (OS MXBean)",
                hal.getProcessors()[0].getSystemCpuLoad() * 100d);

        double loadAvg = hal.getProcessors()[0].getSystemLoadAverage();
        m_logger.info("CPU load average: {}", (loadAvg < 0 ? "NA" : loadAvg));

        // Hardware: filesystem
        for (OSFileStore fs : hal.getFileStores()) {
            m_logger.info("{} ({}) - used: {} free: {} total: {}",
                    fs.getName(),
                    fs.getDescription(),
                    FormatUtil.formatBytes(fs.getTotalSpace() - fs.getUsableSpace()),
                    FormatUtil.formatBytes(fs.getUsableSpace()),
                    FormatUtil.formatBytes(fs.getTotalSpace()));
        }
    }

    VertxAssert.testComplete();
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:54,代码来源:OshiTest.java

示例4: printSystemInfo

import oshi.hardware.HardwareAbstractionLayer; //导入方法依赖的package包/类
/**
 * Stalks your computer and prints the information about it using OSHI.
 *
 * <p>Just kidding, you don't need to call this, but it's helpful if you juset want to know.</p>
 */
public void printSystemInfo() {
    // Obtains
    // OS, java version, flags, CPU, disks, RAM, power
    System.out.println("System info:");

    String os = System.getProperty("os.name");
    String osVer = System.getProperty("os.version");
    String osArch = System.getProperty("os.arch");
    System.out.printf("Running %s version %s arch %s\n", os, osVer, osArch);

    String javaVer = System.getProperty("java.version");
    String vmVendor = System.getProperty("java.vendor");
    System.out.printf("Java version %s JVM %s\n", javaVer, vmVendor);

    System.out.print("Java flags: ");
    RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
    List<String> arguments = runtimeMxBean.getInputArguments();
    for (String string : arguments) {
        System.out.print(string + " ");
    }
    for (String arg : args) {
        System.out.print(arg + " ");
    }
    System.out.println();

    SystemInfo info = new SystemInfo();
    HardwareAbstractionLayer layer = info.getHardware();

    Memory memory = layer.getMemory();
    System.out.printf("Memory total %d bytes, usable %d bytes\n", memory.getTotal(), memory.getAvailable());

    Runtime runtime = Runtime.getRuntime();
    System.out.printf("VM memory free %d bytes, max %d bytes, total %d bytes\n", runtime.freeMemory(),
            runtime.maxMemory(), runtime.totalMemory());

    Processor[] procs = layer.getProcessors();
    System.out.println("CPUs (" + procs.length + "):");
    for (Processor p : procs) {
        System.out.printf("  %s\n", p.getName());
    }

    OSFileStore[] stores = layer.getFileStores();
    System.out.print("Disks (" + stores.length + "):\n");
    for (OSFileStore store : stores) {
        System.out.printf("  %s cap %d bytes, usable %d bytes\n",
                store.getName(), store.getTotalSpace(), store.getUsableSpace());
    }

    PowerSource[] sources = layer.getPowerSources();
    System.out.println("PSUs (" + sources.length + "):");
    for (PowerSource source : sources) {
        System.out.printf("  %s: remaining cap %f, time left %f\n", source.getName(), source.getRemainingCapacity(),
                source.getTimeRemaining());
    }
}
 
开发者ID:AgentTroll,项目名称:Fastest-Fing-Data-Structure-Java,代码行数:61,代码来源:Benchmark.java


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