本文整理汇总了Java中oshi.software.os.OSFileStore类的典型用法代码示例。如果您正苦于以下问题:Java OSFileStore类的具体用法?Java OSFileStore怎么用?Java OSFileStore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OSFileStore类属于oshi.software.os包,在下文中一共展示了OSFileStore类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: 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);
}
}
开发者ID:hawkular,项目名称:hawkular-agent,代码行数:24,代码来源:OshiPlatformCache.java
示例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());
}
}
开发者ID:hawkular,项目名称:hawkular-agent,代码行数:27,代码来源:OshiPlatformCacheTest.java
示例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;
}
}
开发者ID:openhab,项目名称:openhab2-addons,代码行数:17,代码来源:OshiSysteminfo.java
示例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;
}
}
开发者ID:openhab,项目名称:openhab2-addons,代码行数:18,代码来源:OshiSysteminfo.java
示例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);
}
}
开发者ID:clidev,项目名称:spike.x,代码行数:15,代码来源:OshiMetrics.java
示例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("======================================================");
}
开发者ID:clidev,项目名称:spike.x,代码行数:39,代码来源:Activator.java
示例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());
}
开发者ID:Krillsson,项目名称:sys-api,代码行数:12,代码来源:DefaultDiskProvider.java
示例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();
}
开发者ID:Krillsson,项目名称:sys-api,代码行数:8,代码来源:DefaultDiskProvider.java
示例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;
}
开发者ID:Krillsson,项目名称:sys-api,代码行数:11,代码来源:DefaultDiskProvider.java
示例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);
}
开发者ID:Krillsson,项目名称:sys-api,代码行数:8,代码来源:DiskStoresResourceTest.java
示例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;
}
开发者ID:hawkular,项目名称:hawkular-agent,代码行数:33,代码来源:OshiPlatformCache.java
示例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);
}
开发者ID:openhab,项目名称:openhab2-addons,代码行数:11,代码来源:OshiSysteminfo.java
示例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);
}
开发者ID:openhab,项目名称:openhab2-addons,代码行数:11,代码来源:OshiSysteminfo.java
示例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);
}
开发者ID:openhab,项目名称:openhab2-addons,代码行数:13,代码来源:OshiSysteminfo.java
示例16: 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
示例17: testSystemInfo
import oshi.software.os.OSFileStore; //导入依赖的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
示例18: DiskInfo
import oshi.software.os.OSFileStore; //导入依赖的package包/类
public DiskInfo(HWDiskStore hwDiskStore, DiskHealth health, DiskSpeed diskSpeed, OSFileStore osFileStore) {
this.hwDiskStore = hwDiskStore;
this.health = health;
this.diskSpeed = diskSpeed;
this.osFileStore = osFileStore;
}
开发者ID:Krillsson,项目名称:sys-api,代码行数:7,代码来源:DiskInfo.java
示例19: getOsFileStore
import oshi.software.os.OSFileStore; //导入依赖的package包/类
public OSFileStore getOsFileStore() {
return osFileStore;
}
开发者ID:Krillsson,项目名称:sys-api,代码行数:4,代码来源:DiskInfo.java
示例20: map
import oshi.software.os.OSFileStore; //导入依赖的package包/类
@Mappings(
@Mapping(source = "UUID", target = "uuid")
)
com.krillsson.sysapi.dto.storage.OsFileStore map(OSFileStore value);
开发者ID:Krillsson,项目名称:sys-api,代码行数:5,代码来源:StorageInfoMapper.java
注:本文中的oshi.software.os.OSFileStore类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论