Search in sources :

Example 1 with OperatingSystem

use of oshi.software.os.OperatingSystem in project buck by facebook.

the class ProcessHelper method getProcessResourceConsumption.

/**
   * Gets resource consumption of the process with the given pid.
   */
@Nullable
public ProcessResourceConsumption getProcessResourceConsumption(long pid) {
    try {
        OperatingSystem os = OSHI.getOperatingSystem();
        OSProcess process = os.getProcess((int) pid);
        return getProcessResourceConsumptionInternal(process);
    } catch (Exception ex) {
        // do nothing
        return null;
    }
}
Also used : OperatingSystem(oshi.software.os.OperatingSystem) OSProcess(oshi.software.os.OSProcess) Nullable(javax.annotation.Nullable)

Example 2 with OperatingSystem

use of oshi.software.os.OperatingSystem 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 3 with OperatingSystem

use of oshi.software.os.OperatingSystem in project UniversalMediaServer by UniversalMediaServer.

the class SystemInformation method getSystemInfo.

/**
 * Collects and returns system information.
 *
 * @return A {@link List} of {@link String}s containing the collected system
 *         information.
 */
public static List<String> getSystemInfo() {
    List<String> result = new ArrayList<>();
    StringBuilder sb = new StringBuilder();
    long jvmMemory = Runtime.getRuntime().maxMemory();
    OperatingSystem os = null;
    CentralProcessor processor = null;
    GlobalMemory memory = null;
    try {
        SystemInfo systemInfo = new SystemInfo();
        HardwareAbstractionLayer hardware = systemInfo.getHardware();
        os = systemInfo.getOperatingSystem();
        processor = hardware.getProcessor();
        memory = hardware.getMemory();
    } catch (Error e) {
        LOGGER.debug("Could not retrieve system information: {}", e.getMessage());
        LOGGER.trace("", e);
    }
    sb.append("JVM: ").append(System.getProperty("java.vm.name")).append(" ").append(System.getProperty("java.version")).append(" (").append(System.getProperty("sun.arch.data.model")).append("-bit) by ").append(System.getProperty("java.vendor"));
    result.add(sb.toString());
    sb.setLength(0);
    sb.append("OS: ");
    if (os != null && isNotBlank(os.toString())) {
        sb.append(os.toString()).append(" ").append(getOSBitness()).append("-bit");
    } else {
        sb.append(System.getProperty("os.name")).append(" ").append(getOSBitness()).append("-bit ");
        sb.append(System.getProperty("os.version"));
    }
    result.add(sb.toString());
    sb.setLength(0);
    if (processor != null) {
        sb.append("CPU: ").append(processor.getName()).append(" with ").append(processor.getPhysicalProcessorCount());
        if (processor.getPhysicalProcessorCount() > 1) {
            sb.append(" cores");
        } else {
            sb.append(" core");
        }
        if (processor.getLogicalProcessorCount() != processor.getPhysicalProcessorCount()) {
            sb.append(" (").append(processor.getLogicalProcessorCount());
            if (processor.getLogicalProcessorCount() > 1) {
                sb.append(" virtual cores)");
            } else {
                sb.append(" virtual core)");
            }
        }
        result.add(sb.toString());
        sb.setLength(0);
    }
    if (memory != null) {
        sb.append("Physical Memory: ").append(StringUtil.formatBytes(memory.getTotal(), true));
        result.add(sb.toString());
        sb.setLength(0);
        sb.append("Free Memory: ").append(StringUtil.formatBytes(memory.getAvailable(), true));
        result.add(sb.toString());
        sb.setLength(0);
    }
    sb.append("Maximum JVM Memory: ");
    if (jvmMemory == Long.MAX_VALUE) {
        sb.append("Unlimited");
    } else {
        sb.append(StringUtil.formatBytes(jvmMemory, true));
    }
    result.add(sb.toString());
    return result;
}
Also used : OperatingSystem(oshi.software.os.OperatingSystem) HardwareAbstractionLayer(oshi.hardware.HardwareAbstractionLayer) GlobalMemory(oshi.hardware.GlobalMemory) SystemInfo(oshi.SystemInfo) CentralProcessor(oshi.hardware.CentralProcessor) ArrayList(java.util.ArrayList)

Example 4 with OperatingSystem

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())));
    }
}
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)

Example 5 with OperatingSystem

use of oshi.software.os.OperatingSystem in project yyl_example by Relucent.

the class OshiExample method main.

public static void main(String[] args) {
    SystemInfo si = new SystemInfo();
    HardwareAbstractionLayer hal = si.getHardware();
    OperatingSystem os = si.getOperatingSystem();
    infoPlatform(si);
    infoIdentifier(si);
    infoCpu(si);
    infoMemory(hal.getMemory());
    infoFileSystem(os.getFileSystem());
}
Also used : HardwareAbstractionLayer(oshi.hardware.HardwareAbstractionLayer) OperatingSystem(oshi.software.os.OperatingSystem) SystemInfo(oshi.SystemInfo)

Aggregations

OperatingSystem (oshi.software.os.OperatingSystem)6 HardwareAbstractionLayer (oshi.hardware.HardwareAbstractionLayer)4 SystemInfo (oshi.SystemInfo)2 CentralProcessor (oshi.hardware.CentralProcessor)2 FileSystem (oshi.software.os.FileSystem)2 OSProcess (oshi.software.os.OSProcess)2 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 Nullable (javax.annotation.Nullable)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 ComputerSystem (oshi.hardware.ComputerSystem)1 GlobalMemory (oshi.hardware.GlobalMemory)1