Search in sources :

Example 1 with FileSystem

use of oshi.software.os.FileSystem in project graylog2-server by Graylog2.

the class OshiProcessProbe method processStats.

@Override
public ProcessStats processStats() {
    final OperatingSystem os = service.getOs();
    final FileSystem fs = os.getFileSystem();
    final long pid = os.getProcessId();
    final OSProcess proc = os.getProcess(os.getProcessId());
    final ProcessStats.Cpu cpu = ProcessStats.Cpu.create(((short) proc.getProcessCpuLoadCumulative()), proc.getKernelTime(), proc.getUserTime(), proc.getUpTime());
    final ProcessStats.Memory mem = ProcessStats.Memory.create(proc.getVirtualSize(), proc.getResidentSetSize(), -1);
    return ProcessStats.create(pid, fs.getOpenFileDescriptors(), fs.getMaxFileDescriptors(), cpu, mem);
}
Also used : OperatingSystem(oshi.software.os.OperatingSystem) FileSystem(oshi.software.os.FileSystem) OSProcess(oshi.software.os.OSProcess)

Example 2 with FileSystem

use of oshi.software.os.FileSystem in project ats-framework by Axway.

the class OshiSystemInformation method listFileSystems.

@Override
public IFileSystem[] listFileSystems() {
    FileSystem fs = this.systemInfo.getOperatingSystem().getFileSystem();
    // enumerate only local drives. (Network ones are excluded)
    List<OSFileStore> fileStores = fs.getFileStores(true);
    List<IFileSystem> fileSystems = new ArrayList<IFileSystem>();
    for (OSFileStore fileStore : fileStores) {
        fileSystems.add(new OshiFileSystem(fileStore, fileStore.getMount()));
    }
    return fileSystems.toArray(new IFileSystem[fileSystems.size()]);
}
Also used : OSFileStore(oshi.software.os.OSFileStore) FileSystem(oshi.software.os.FileSystem) IFileSystem(com.axway.ats.agent.core.monitoring.systemmonitor.systeminformation.IFileSystem) IFileSystem(com.axway.ats.agent.core.monitoring.systemmonitor.systeminformation.IFileSystem) ArrayList(java.util.ArrayList)

Example 3 with FileSystem

use of oshi.software.os.FileSystem in project ats-framework by Axway.

the class OshiSystemInformation method getFileSystem.

@Override
public IFileSystem getFileSystem(String devName) {
    try {
        FileSystem fs = this.os.getFileSystem();
        List<OSFileStore> fileStores = fs.getFileStores();
        for (OSFileStore fileStore : fileStores) {
            if (fileStore.getName().equals(devName)) {
                return new OshiFileSystem(fileStore, fileStore.getName());
            }
        }
        throw new SystemInformationException("No such file system drive device '" + devName + "'");
    } catch (Exception e) {
        throw new SystemInformationException("Could not obtain file system for/from device '" + devName + "'", e);
    }
}
Also used : OSFileStore(oshi.software.os.OSFileStore) FileSystem(oshi.software.os.FileSystem) IFileSystem(com.axway.ats.agent.core.monitoring.systemmonitor.systeminformation.IFileSystem) SystemInformationException(com.axway.ats.agent.core.monitoring.systemmonitor.systeminformation.exceptions.SystemInformationException) SystemInformationException(com.axway.ats.agent.core.monitoring.systemmonitor.systeminformation.exceptions.SystemInformationException)

Example 4 with FileSystem

use of oshi.software.os.FileSystem 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())));
    }
}
Also used : OperatingSystem(oshi.software.os.OperatingSystem) HardwareAbstractionLayer(oshi.hardware.HardwareAbstractionLayer) Path(java.nio.file.Path) Pair(oshi.util.tuples.Pair) java.util(java.util) ImmutableSet(com.google.common.collect.ImmutableSet) KafkaJournalConfiguration(org.graylog2.plugin.KafkaJournalConfiguration) AbstractOSFileStore(oshi.software.common.AbstractOSFileStore) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) AbstractHWDiskStore(oshi.hardware.common.AbstractHWDiskStore) OSFileStore(oshi.software.os.OSFileStore) OperatingSystem(oshi.software.os.OperatingSystem) Inject(javax.inject.Inject) FileSystem(oshi.software.os.FileSystem) Configuration(org.graylog2.Configuration) Paths(java.nio.file.Paths) HWDiskStore(oshi.hardware.HWDiskStore) HardwareAbstractionLayer(oshi.hardware.HardwareAbstractionLayer) HWPartition(oshi.hardware.HWPartition) Path(java.nio.file.Path) OshiService(org.graylog2.shared.system.stats.OshiService) FileSystem(oshi.software.os.FileSystem) AbstractHWDiskStore(oshi.hardware.common.AbstractHWDiskStore) HWDiskStore(oshi.hardware.HWDiskStore) Pair(oshi.util.tuples.Pair)

Aggregations

FileSystem (oshi.software.os.FileSystem)4 OSFileStore (oshi.software.os.OSFileStore)3 IFileSystem (com.axway.ats.agent.core.monitoring.systemmonitor.systeminformation.IFileSystem)2 OperatingSystem (oshi.software.os.OperatingSystem)2 SystemInformationException (com.axway.ats.agent.core.monitoring.systemmonitor.systeminformation.exceptions.SystemInformationException)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Configuration (org.graylog2.Configuration)1 KafkaJournalConfiguration (org.graylog2.plugin.KafkaJournalConfiguration)1 OshiService (org.graylog2.shared.system.stats.OshiService)1 HWDiskStore (oshi.hardware.HWDiskStore)1 HWPartition (oshi.hardware.HWPartition)1 HardwareAbstractionLayer (oshi.hardware.HardwareAbstractionLayer)1 AbstractHWDiskStore (oshi.hardware.common.AbstractHWDiskStore)1