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


Java OSFileStore.getTotalSpace方法代码示例

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


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

示例1: printFileSystem

import oshi.software.os.OSFileStore; //导入方法依赖的package包/类
/**
 * Prints the file system.
 *
 * @param fileSystem the file system
 */
private static void printFileSystem(FileSystem fileSystem) {
  oshi.add("File System:");

  oshi.add(String.format(" File Descriptors: %d/%d%n", fileSystem.getOpenFileDescriptors(),
      fileSystem.getMaxFileDescriptors()));

  OSFileStore[] fsArray = fileSystem.getFileStores();
  for (OSFileStore fs : fsArray) {
    long usable = fs.getUsableSpace();
    long total = fs.getTotalSpace();
    oshi.add(String.format(" %s (%s) [%s] %s of %s free (%.1f%%) is %s and is mounted at %s%n",
        fs.getName(), fs.getDescription().isEmpty() ? "file system" : fs.getDescription(),
        fs.getType(), FormatUtil.formatBytes(usable), FormatUtil.formatBytes(fs.getTotalSpace()),
        100d * usable / total, fs.getVolume(), fs.getMount()));
  }
}
 
开发者ID:psi-probe,项目名称:psi-probe,代码行数:22,代码来源:OshiController.java

示例2: getFileStores

import oshi.software.os.OSFileStore; //导入方法依赖的package包/类
@Test
public void getFileStores() {
    OshiPlatformCache oshi = newOshiPlatformCache();
    Map<String, OSFileStore> filestores = oshi.getFileStores();
    Assert.assertNotNull(filestores);

    int i = 0;
    for (OSFileStore filestore : filestores.values()) {
        String name = filestore.getName();
        String description = filestore.getDescription();
        long usableSpace = filestore.getUsableSpace();
        long totalSpace = filestore.getTotalSpace();

        Assert.assertNotNull(name);
        Assert.assertNotNull(description);
        Assert.assertTrue(usableSpace > -1L);
        Assert.assertTrue(totalSpace > -1L);

        print("===FILE STORE #%d ===", ++i);
        print("  Name=[%s]", name);
        print("  Description=[%s]", description);
        print("  UsableSpace=[%s] (%d)", FormatUtil.formatBytes(usableSpace), usableSpace);
        print("  TotalSpace=[%s] (%d)", FormatUtil.formatBytes(totalSpace), totalSpace);
        print("  toString=[%s]", filestore.toString());
    }
}
 
开发者ID:hawkular,项目名称:hawkular-agent,代码行数:27,代码来源:OshiPlatformCacheTest.java

示例3: getStorageAvailablePercent

import oshi.software.os.OSFileStore; //导入方法依赖的package包/类
@Override
public DecimalType getStorageAvailablePercent(int deviceIndex) throws DeviceNotFoundException {
    // In the current OSHI version a new query is required for the storage data values to be updated
    // In OSHI 4.0.0. it is planned to change this mechanism - see https://github.com/oshi/oshi/issues/310
    fileStores = operatingSystem.getFileSystem().getFileStores();
    OSFileStore fileStore = (OSFileStore) getDevice(fileStores, deviceIndex);
    long totalSpace = fileStore.getTotalSpace();
    long freeSpace = fileStore.getUsableSpace();
    if (totalSpace > 0) {
        double freePercentDecimal = (double) freeSpace / (double) totalSpace;
        BigDecimal freePercent = getPercentsValue(freePercentDecimal);
        return new DecimalType(freePercent);
    } else {
        return null;
    }
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:17,代码来源:OshiSysteminfo.java

示例4: getStorageUsedPercent

import oshi.software.os.OSFileStore; //导入方法依赖的package包/类
@Override
public DecimalType getStorageUsedPercent(int deviceIndex) throws DeviceNotFoundException {
    // In the current OSHI version a new query is required for the storage data values to be updated
    // In OSHI 4.0.0. it is planned to change this mechanism - see https://github.com/oshi/oshi/issues/310
    fileStores = operatingSystem.getFileSystem().getFileStores();
    OSFileStore fileStore = (OSFileStore) getDevice(fileStores, deviceIndex);
    long totalSpace = fileStore.getTotalSpace();
    long freeSpace = fileStore.getUsableSpace();
    long usedSpace = totalSpace - freeSpace;
    if (totalSpace > 0) {
        double usedPercentDecimal = (double) usedSpace / (double) totalSpace;
        BigDecimal usedPercent = getPercentsValue(usedPercentDecimal);
        return new DecimalType(usedPercent);
    } else {
        return null;
    }
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:18,代码来源:OshiSysteminfo.java

示例5: publishFilesystem

import oshi.software.os.OSFileStore; //导入方法依赖的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

示例6: getStorageTotal

import oshi.software.os.OSFileStore; //导入方法依赖的package包/类
@Override
public DecimalType getStorageTotal(int index) throws DeviceNotFoundException {
    // In the current OSHI version a new query is required for the storage data values to be updated
    // In OSHI 4.0.0. it is planned to change this mechanism - see https://github.com/oshi/oshi/issues/310
    fileStores = operatingSystem.getFileSystem().getFileStores();
    OSFileStore fileStore = (OSFileStore) getDevice(fileStores, index);
    long totalSpace = fileStore.getTotalSpace();
    totalSpace = getSizeInMB(totalSpace);
    return new DecimalType(totalSpace);
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:11,代码来源:OshiSysteminfo.java

示例7: getStorageUsed

import oshi.software.os.OSFileStore; //导入方法依赖的package包/类
@Override
public DecimalType getStorageUsed(int index) throws DeviceNotFoundException {
    // In the current OSHI version a new query is required for the storage data values to be updated
    // In OSHI 4.0.0. it is planned to change this mechanism - see https://github.com/oshi/oshi/issues/310
    fileStores = operatingSystem.getFileSystem().getFileStores();
    OSFileStore fileStore = (OSFileStore) getDevice(fileStores, index);
    long totalSpace = fileStore.getTotalSpace();
    long freeSpace = fileStore.getUsableSpace();
    long usedSpace = totalSpace - freeSpace;
    usedSpace = getSizeInMB(usedSpace);
    return new DecimalType(usedSpace);
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:13,代码来源:OshiSysteminfo.java

示例8: getFileSystems

import oshi.software.os.OSFileStore; //导入方法依赖的package包/类
/**
 * this function retrieve informations about filesystems and calculate total and free space for each of them.
 * After processing the data, send them to the model invoking <code>setAvailabeFileSystemInModel(String[])</code>
 *
 * @see MemoryStats#setAvailabeFileSystemInModel(String[])
 * @return a string containing informations about all filesystems founded with total and free size, label, and type of device
 */
public String getFileSystems() {
    OSFileStore[] fsArray = systemInfo.getOperatingSystem().getFileSystem().getFileStores();
    String[] numericSpace = new String[fsArray.length];
    String[] volume = new String[fsArray.length];
    String[] stringBuilder = new String[fsArray.length];
    for (int i = 0; i < fsArray.length; i++) {
        OSFileStore fs = fsArray[i];
        long usable = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        stringBuilder[i] = (String.format(" %s (%s) [%s] %s free of %s (%.1f%%) " +
                        (fs.getLogicalVolume() != null && fs.getLogicalVolume().length() > 0 ? "[%s]" : "%s") +
                        "%n", fs.getName(),
                fs.getDescription().isEmpty() ? "file system" : fs.getDescription(), fs.getType(),
                FormatUtil.formatBytes(usable), FormatUtil.formatBytes(fs.getTotalSpace()), 100d * usable / total, fs.getLogicalVolume()));
        try {
            if (total == 0) {
                volume[i] = fs.getMount();
                numericSpace[i] = "0";
            } else {
                volume[i] = fs.getMount();
                numericSpace[i] = String.format("%.1f", (100d * usable / total)).replace(",", ".");
            }
        } catch (NumberFormatException e) {
            numericSpace[i] = "error";
        }
    }

    for (int i = 0; i < numericSpace.length; i++) {
        if (volume[i].equals("C:\\")) {
            String genericString = numericSpace[0];
            numericSpace[0] = numericSpace[i];
            numericSpace[i] = genericString;

            genericString = stringBuilder[0];
            stringBuilder[0] = stringBuilder[i];
            stringBuilder[i] = genericString;
        }
    }
    setAvailabeFileSystemInModel(numericSpace);
    return String.join("", stringBuilder);
}
 
开发者ID:andrea9293,项目名称:pcstatus,代码行数:49,代码来源:MemoryStats.java


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