use of oshi.software.os.OperatingSystem in project graylog2-server by Graylog2.
the class OshiFsProbe method init.
private void init() {
final OperatingSystem os = service.getOs();
final FileSystem fileSystem = os.getFileSystem();
final HardwareAbstractionLayer hardware = service.getHal();
for (Path location : locations) {
Path path = location.toAbsolutePath();
oshiFileSystems.put(path, fileSystem.getFileStores().stream().filter(fs -> path.startsWith(fs.getMount())).max(Comparator.comparingInt(p -> Paths.get(p.getMount()).getNameCount())).map(fs -> {
// First try search for the diskstore with the logical volume or volume name
Optional<HWDiskStore> diskStore = hardware.getDiskStores().stream().filter(ds -> ds.getName().equals(StringUtils.defaultIfEmpty(fs.getLogicalVolume(), fs.getVolume()))).findFirst();
if (diskStore.isPresent()) {
return new Pair<>(fs, diskStore.get());
}
// Try to search for the diskstore with the partition of our mountpoint
diskStore = hardware.getDiskStores().stream().filter(ds -> ds.getPartitions().stream().anyMatch(part -> path.startsWith(part.getMountPoint()))).max(Comparator.comparingInt(ds -> ds.getPartitions().stream().filter(part -> path.startsWith(part.getMountPoint())).mapToInt(part -> Paths.get(part.getMountPoint()).getNameCount()).max().orElse(0)));
if (diskStore.isPresent()) {
return new Pair<>(fs, diskStore.get());
}
return new Pair<>(fs, generateDummyDiskStore());
}).orElse(new Pair<>(generateDummyFileStore(), generateDummyDiskStore())));
}
}
Aggregations