本文整理汇总了Java中oshi.software.os.OSFileStore类的典型用法代码示例。如果您正苦于以下问题:Java OSFileStore类的具体用法?Java OSFileStore怎么用?Java OSFileStore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OSFileStore类属于oshi.software.os包,在下文中一共展示了OSFileStore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()));
}
}
示例2: getFileStoreMetric
import oshi.software.os.OSFileStore; //导入依赖的package包/类
/**
* 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);
}
}
示例3: 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());
}
}
示例4: 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;
}
}
示例5: 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;
}
}
示例6: 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);
}
}
示例7: outputSysInfo
import oshi.software.os.OSFileStore; //导入依赖的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("======================================================");
}
示例8: storageInfo
import oshi.software.os.OSFileStore; //导入依赖的package包/类
StorageInfo storageInfo() {
List<DiskInfo> diskInfos = new ArrayList<>();
for (HWDiskStore diskStore : hal.getDiskStores()) {
OSFileStore associatedFileStore = findAssociatedFileStore(diskStore);
String name = associatedFileStore != null ? associatedFileStore.getName() : "N/A";
diskInfos.add(new DiskInfo(diskStore, diskHealth(name), diskSpeedForName(diskStore.getName()), associatedFileStore));
}
FileSystem fileSystem = operatingSystem.getFileSystem();
return new StorageInfo(diskInfos.toArray(/*type reference*/new DiskInfo[0]), fileSystem.getOpenFileDescriptors(), fileSystem.getMaxFileDescriptors());
}
示例9: getDiskInfoByName
import oshi.software.os.OSFileStore; //导入依赖的package包/类
Optional<DiskInfo> getDiskInfoByName(String name) {
return Arrays.stream(hal.getDiskStores()).filter(d -> d.getName().equals(name)).map(di -> {
OSFileStore associatedFileStore = findAssociatedFileStore(di);
String mount = associatedFileStore != null ? associatedFileStore.getName() : "N/A";
return new DiskInfo(di, diskHealth(mount), diskSpeedForName(di.getName()), associatedFileStore);
}).findFirst();
}
示例10: findAssociatedFileStore
import oshi.software.os.OSFileStore; //导入依赖的package包/类
private OSFileStore findAssociatedFileStore(HWDiskStore diskStore) {
for (OSFileStore osFileStore : Arrays.asList(operatingSystem.getFileSystem().getFileStores())) {
for (HWPartition hwPartition : Arrays.asList(diskStore.getPartitions())) {
if (osFileStore.getUUID().equalsIgnoreCase(hwPartition.getUuid())) {
return osFileStore;
}
}
}
return null;
}
示例11: setUp
import oshi.software.os.OSFileStore; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
diskInfo = new DiskInfo(new HWDiskStore(), new DiskHealth(0, new HealthData[0]),
new DiskSpeed(0,0), new OSFileStore("diskInfo", "", "", "", "", "", 0, 0));
diskInfo.getHwDiskStore().setName("sd0");
diskSd0 = new StorageInfo(new DiskInfo[]{diskInfo}, 0, 0);
}
示例12: getFileStores
import oshi.software.os.OSFileStore; //导入依赖的package包/类
/**
* @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;
}
示例13: 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);
}
示例14: getStorageAvailable
import oshi.software.os.OSFileStore; //导入依赖的package包/类
@Override
public DecimalType getStorageAvailable(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 freeSpace = fileStore.getUsableSpace();
freeSpace = getSizeInMB(freeSpace);
return new DecimalType(freeSpace);
}
示例15: 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);
}