oshi.software.os.OSFileStore Java Examples

The following examples show how to use oshi.software.os.OSFileStore. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServerInfo.java    From mogu_blog_v2 with Apache License 2.0 6 votes vote down vote up
/**
 * 设置磁盘信息
 */
private void setSysFiles(OperatingSystem os)
{
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray)
    {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFile sysFile = new SysFile();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));
        sysFile.setUsage(Arith.mul(Arith.div(used, total, 4), 100));
        sysFiles.add(sysFile);
    }
}
 
Example #2
Source File: OshiPlatformCacheTest.java    From hawkular-agent with Apache License 2.0 6 votes vote down vote up
@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());
    }
}
 
Example #3
Source File: OshiPlatformCache.java    From hawkular-agent with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the given metric's value, or null if there is no file store with the given name.
 *
 * @param fileStoreNameName name of file store
 * @param metricToCollect the metric to collect
 * @return the value of the metric, or null if there is no file store with the given name
 */
public Double getFileStoreMetric(String fileStoreNameName, ID metricToCollect) {

    Map<String, OSFileStore> cache = getFileStores();
    OSFileStore fileStore = cache.get(fileStoreNameName);
    if (fileStore == null) {
        return null;
    }

    if (PlatformMetricType.FILE_STORE_TOTAL_SPACE.getMetricTypeId().equals(metricToCollect)) {
        return Double.valueOf(fileStore.getTotalSpace());
    } else if (PlatformMetricType.FILE_STORE_USABLE_SPACE.getMetricTypeId().equals(metricToCollect)) {
        return Double.valueOf(fileStore.getUsableSpace());
    } else {
        throw new UnsupportedOperationException("Invalid file store metric to collect: " + metricToCollect);
    }
}
 
Example #4
Source File: Server.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 设置磁盘信息
 */
private void setSysFiles(OperatingSystem os) {
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray) {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFile sysFile = new SysFile();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));
        sysFile.setUsage(NumberUtil.mul(NumberUtil.div(used, total, 4), 100));
        sysFiles.add(sysFile);
    }
}
 
Example #5
Source File: SystemHardwareInfo.java    From Guns with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 设置磁盘信息
 */
private void setSysFiles(OperatingSystem os) {
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray) {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFileInfo sysFile = new SysFileInfo();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));

        if (total == 0) {
            sysFile.setUsage(0);
        } else {
            sysFile.setUsage(NumberUtil.mul(NumberUtil.div(used, total, 4), 100));
        }

        sysFiles.add(sysFile);
    }
}
 
Example #6
Source File: MonitorServiceImpl.java    From albedo with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 获取磁盘信息
 *
 * @return /
 */
private Map<String, Object> getDiskInfo(OperatingSystem os) {
	Map<String, Object> diskInfo = new LinkedHashMap<>();
	try {
		FileSystem fileSystem = os.getFileSystem();
		List<OSFileStore> fsArray = fileSystem.getFileStores();
		for (OSFileStore fs : fsArray) {
			diskInfo.put("total", fs.getTotalSpace() > 0 ? FileUtil.getSize(fs.getTotalSpace()) : "?");
			long used = fs.getTotalSpace() - fs.getUsableSpace();
			diskInfo.put("available", FileUtil.getSize(fs.getUsableSpace()));
			diskInfo.put("used", FileUtil.getSize(used));
			diskInfo.put("usageRate", df.format(used / (double) fs.getTotalSpace() * 100));
		}
	} catch (Exception e) {
		log.error("{}", e);
	}
	return diskInfo;
}
 
Example #7
Source File: Server.java    From boot-actuator with MIT License 6 votes vote down vote up
/**
 * 设置磁盘信息
 */
private void setSysFiles(OperatingSystem os)
{
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray)
    {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFile sysFile = new SysFile();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));
        sysFile.setUsage(Arith.mul(Arith.div(used, total, 4), 100));
        sysFiles.add(sysFile);
    }
}
 
Example #8
Source File: Server.java    From LuckyFrameWeb with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 设置磁盘信息
 */
private void setSysFiles(OperatingSystem os)
{
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray)
    {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFile sysFile = new SysFile();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));
        sysFile.setUsage(Arith.mul(Arith.div(used, total, 4), 100));
        sysFiles.add(sysFile);
    }
}
 
Example #9
Source File: Server.java    From RuoYi with Apache License 2.0 6 votes vote down vote up
/**
 * 设置磁盘信息
 */
private void setSysFiles(OperatingSystem os) {
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray) {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFile sysFile = new SysFile();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));
        sysFile.setUsage(NumberUtil.mul(NumberUtil.div(used, total, 4), 100));
        sysFiles.add(sysFile);
    }
}
 
Example #10
Source File: Server.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 设置磁盘信息
 */
private void setSysFiles(OperatingSystem os) {
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray) {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFile sysFile = new SysFile();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));
        sysFile.setUsage(NumberUtil.mul(NumberUtil.div(used, total, 4), 100));
        sysFiles.add(sysFile);
    }
}
 
Example #11
Source File: Server.java    From Shiro-Action with MIT License 6 votes vote down vote up
/**
 * 设置磁盘信息
 */
private void setSysFiles(OperatingSystem os) {
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray) {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFile sysFile = new SysFile();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));
        sysFile.setUsage(Arith.mul(Arith.div(used, total, 4), 100));
        sysFiles.add(sysFile);
    }
}
 
Example #12
Source File: Server.java    From LuckyFrameClient with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * ���ô�����Ϣ
 */
private void setSysFiles(OperatingSystem os)
{
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray)
    {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFile sysFile = new SysFile();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));
        sysFile.setUsage(Arith.mul(Arith.div(used, total, 4), 100));
        sysFiles.add(sysFile);
    }
}
 
Example #13
Source File: Server.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 设置磁盘信息
 */
private void setSysFiles(OperatingSystem os) {
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray) {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFile sysFile = new SysFile();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));
        sysFile.setUsage(NumberUtil.mul(NumberUtil.div(used, total, 4), 100));
        sysFiles.add(sysFile);
    }
}
 
Example #14
Source File: Server.java    From NutzSite with Apache License 2.0 6 votes vote down vote up
/**
 * 设置磁盘信息
 */
private void setSysFiles(OperatingSystem os)
{
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray)
    {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFile sysFile = new SysFile();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));
        sysFile.setUsage(Arith.mul(Arith.div(used, total, 4), 100));
        sysFiles.add(sysFile);
    }
}
 
Example #15
Source File: Server.java    From ruoyiplus with MIT License 6 votes vote down vote up
/**
 * 设置磁盘信息
 */
private void setSysFiles(OperatingSystem os)
{
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray)
    {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFile sysFile = new SysFile();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));
        sysFile.setUsage(Arith.mul(Arith.div(used, total, 4), 100));
        sysFiles.add(sysFile);
    }
}
 
Example #16
Source File: Server.java    From RuoYi-Vue with MIT License 6 votes vote down vote up
/**
 * 设置磁盘信息
 */
private void setSysFiles(OperatingSystem os)
{
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray)
    {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFile sysFile = new SysFile();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));
        sysFile.setUsage(Arith.mul(Arith.div(used, total, 4), 100));
        sysFiles.add(sysFile);
    }
}
 
Example #17
Source File: Server.java    From supplierShop with MIT License 6 votes vote down vote up
/**
 * 设置磁盘信息
 */
private void setSysFiles(OperatingSystem os)
{
    FileSystem fileSystem = os.getFileSystem();
    OSFileStore[] fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray)
    {
        long free = fs.getUsableSpace();
        long total = fs.getTotalSpace();
        long used = total - free;
        SysFile sysFile = new SysFile();
        sysFile.setDirName(fs.getMount());
        sysFile.setSysTypeName(fs.getType());
        sysFile.setTypeName(fs.getName());
        sysFile.setTotal(convertFileSize(total));
        sysFile.setFree(convertFileSize(free));
        sysFile.setUsed(convertFileSize(used));
        sysFile.setUsage(Arith.mul(Arith.div(used, total, 4), 100));
        sysFiles.add(sysFile);
    }
}
 
Example #18
Source File: ServerServiceImpl.java    From DimpleBlog with Apache License 2.0 5 votes vote down vote up
/**
 * 获取磁盘信息
 *
 * @return /
 */
private Map<String, Object> getDiskInfo(OperatingSystem os) {
    Map<String, Object> diskInfo = new LinkedHashMap<>();
    FileSystem fileSystem = os.getFileSystem();
    List<OSFileStore> fsArray = Arrays.asList(fileSystem.getFileStores());
    for (OSFileStore fs : fsArray) {
        diskInfo.put("total", fs.getTotalSpace() > 0 ? FileUtils.getSizeString(fs.getTotalSpace()) : "?");
        long used = fs.getTotalSpace() - fs.getUsableSpace();
        diskInfo.put("available", FileUtils.getSizeString(fs.getUsableSpace()));
        diskInfo.put("used", FileUtils.getSizeString(used));
        diskInfo.put("usageRate", df.format(used / (double) fs.getTotalSpace() * 100));
    }
    return diskInfo;
}
 
Example #19
Source File: MonitorServiceImpl.java    From eladmin with Apache License 2.0 5 votes vote down vote up
/**
 * 获取磁盘信息
 * @return /
 */
private Map<String,Object> getDiskInfo(OperatingSystem os) {
    Map<String,Object> diskInfo = new LinkedHashMap<>();
    FileSystem fileSystem = os.getFileSystem();
    List<OSFileStore> fsArray = fileSystem.getFileStores();
    for (OSFileStore fs : fsArray){
        diskInfo.put("total", fs.getTotalSpace() > 0 ? FileUtil.getSize(fs.getTotalSpace()) : "?");
        long used = fs.getTotalSpace() - fs.getUsableSpace();
        diskInfo.put("available", FileUtil.getSize(fs.getUsableSpace()));
        diskInfo.put("used", FileUtil.getSize(used));
        diskInfo.put("usageRate", df.format(used/(double)fs.getTotalSpace() * 100));
    }
    return diskInfo;
}
 
Example #20
Source File: UsageStatisticsCollectorImpl.java    From hivemq-community-edition with Apache License 2.0 5 votes vote down vote up
private void collectSystemStatistics(final @NotNull Statistic statistic) {

        if (!SYSTEM_METRICS_ENABLED) {
            return;
        }

        final OperatingSystem operatingSystem;
        final HardwareAbstractionLayer hardware;
        try {
            final SystemInfo systemInfo = new SystemInfo();
            operatingSystem = systemInfo.getOperatingSystem();
            hardware = systemInfo.getHardware();
        } catch (final UnsupportedOperationException e) {
            log.debug("system metrics are not supported, ignoring extended system information");
            log.trace("original exception", e);
            return;
        }

        statistic.setOsManufacturer(operatingSystem.getManufacturer());
        statistic.setOs(operatingSystem.getFamily());
        final OperatingSystemVersion version = operatingSystem.getVersion();
        statistic.setOsVersion(version.getVersion());
        statistic.setOpenFileLimit(operatingSystem.getFileSystem().getMaxFileDescriptors());

        //disk space in MB
        long totalDiskSpace = 0;
        for (final OSFileStore osFileStore : operatingSystem.getFileSystem().getFileStores()) {
            totalDiskSpace += (osFileStore.getTotalSpace() / 1024 / 1024);
        }
        statistic.setDiskSize(totalDiskSpace);

        final CentralProcessor processor = hardware.getProcessor();
        statistic.setCpu(processor.toString());
        statistic.setCpuSockets(processor.getPhysicalPackageCount());
        statistic.setCpuPhysicalCores(processor.getPhysicalProcessorCount());
        statistic.setCpuTotalCores(processor.getLogicalProcessorCount());

        statistic.setOsUptime(processor.getSystemUptime());
        statistic.setMemorySize(hardware.getMemory().getTotal() / 1024 / 1024);
    }
 
Example #21
Source File: NativeCommand.java    From LagMonitor with MIT License 5 votes vote down vote up
private void printMountInfo(CommandSender sender, OSFileStore fileStore) {
    String type = fileStore.getType();
    String desc = fileStore.getDescription();

    long totalSpaceBytes = fileStore.getTotalSpace();
    String totalSpace = LagUtils.readableBytes(totalSpaceBytes);
    String usedSpace = LagUtils.readableBytes(totalSpaceBytes - fileStore.getUsableSpace());

    String format = desc + ' ' + type + ' ' + usedSpace + '/' + totalSpace;
    sendMessage(sender, "    " + fileStore.getMount(), format);
}
 
Example #22
Source File: OshiPlatformCache.java    From hawkular-agent with Apache License 2.0 5 votes vote down vote up
/**
 * @return information about all file stores on the platform
 */
@SuppressWarnings("unchecked")
public Map<String, OSFileStore> getFileStores() {
    Map<String, OSFileStore> ret;

    wLock.lock();
    try {
        if (!sysInfoCache.containsKey(PlatformResourceType.FILE_STORE)) {
            HashMap<String, OSFileStore> cache = new HashMap<>();
            OSFileStore[] arr = sysInfo.getOperatingSystem().getFileSystem().getFileStores();
            if (arr != null) {
                for (OSFileStore item : arr) {
                    cache.put(item.getName(), item);
                }
            }
            sysInfoCache.put(PlatformResourceType.FILE_STORE, cache);
        }
    } finally {
        // downgrade to a read-only lock since we just need it to read from the cache
        rLock.lock();
        try {
            wLock.unlock();
            ret = (Map<String, OSFileStore>) sysInfoCache.get(PlatformResourceType.FILE_STORE);
        } finally {
            rLock.unlock();
        }
    }

    return ret;
}
 
Example #23
Source File: NativeCommand.java    From LagMonitor with MIT License 5 votes vote down vote up
private void printMountInfo(CommandSender sender, OSFileStore fileStore) {
    String type = fileStore.getType();
    String desc = fileStore.getDescription();

    long totalSpaceBytes = fileStore.getTotalSpace();
    String totalSpace = LagUtils.readableBytes(totalSpaceBytes);
    String usedSpace = LagUtils.readableBytes(totalSpaceBytes - fileStore.getUsableSpace());

    String format = desc + ' ' + type + ' ' + usedSpace + '/' + totalSpace;
    sendMessage(sender, "    " + fileStore.getMount(), format);
}
 
Example #24
Source File: NativeCommand.java    From LagMonitor with MIT License 4 votes vote down vote up
private void displayMounts(CommandSender sender, OSFileStore[] fileStores) {
    sender.sendMessage(PRIMARY_COLOR + "Mounts:");
    for (OSFileStore fileStore : fileStores) {
        printMountInfo(sender, fileStore);
    }
}
 
Example #25
Source File: NativeCommand.java    From LagMonitor with MIT License 4 votes vote down vote up
private void displayMounts(CommandSender sender, OSFileStore[] fileStores) {
    sender.sendMessage(PRIMARY_COLOR + "Mounts:");
    for (OSFileStore fileStore : fileStores) {
        printMountInfo(sender, fileStore);
    }
}