Search in sources :

Example 1 with HardwareAbstractionLayer

use of oshi.hardware.HardwareAbstractionLayer in project flink by apache.

the class SystemResourcesMetricsInitializer method instantiateSystemMetrics.

public static void instantiateSystemMetrics(MetricGroup metricGroup, Time probeInterval) {
    try {
        MetricGroup system = metricGroup.addGroup("System");
        SystemResourcesCounter systemResourcesCounter = new SystemResourcesCounter(probeInterval);
        systemResourcesCounter.start();
        SystemInfo systemInfo = new SystemInfo();
        HardwareAbstractionLayer hardwareAbstractionLayer = systemInfo.getHardware();
        instantiateMemoryMetrics(system.addGroup("Memory"), hardwareAbstractionLayer.getMemory());
        instantiateSwapMetrics(system.addGroup("Swap"), hardwareAbstractionLayer.getMemory());
        instantiateCPUMetrics(system.addGroup("CPU"), systemResourcesCounter);
        instantiateNetworkMetrics(system.addGroup("Network"), systemResourcesCounter);
    } catch (NoClassDefFoundError ex) {
        LOG.warn("Failed to initialize system resource metrics because of missing class definitions." + " Did you forget to explicitly add the oshi-core optional dependency?", ex);
    }
}
Also used : HardwareAbstractionLayer(oshi.hardware.HardwareAbstractionLayer) SystemInfo(oshi.SystemInfo) MetricGroup(org.apache.flink.metrics.MetricGroup)

Example 2 with HardwareAbstractionLayer

use of oshi.hardware.HardwareAbstractionLayer 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 3 with HardwareAbstractionLayer

use of oshi.hardware.HardwareAbstractionLayer 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 4 with HardwareAbstractionLayer

use of oshi.hardware.HardwareAbstractionLayer in project graylog2-server by Graylog2.

the class OshiOsProbe method osStats.

@Override
public OsStats osStats() {
    final HardwareAbstractionLayer hardware = service.getHal();
    final GlobalMemory globalMemory = hardware.getMemory();
    final Memory mem = Memory.create(globalMemory.getTotal(), globalMemory.getAvailable(), (short) (globalMemory.getAvailable() * 100 / globalMemory.getTotal()), globalMemory.getTotal() - globalMemory.getAvailable(), (short) ((globalMemory.getTotal() - globalMemory.getAvailable()) * 100 / globalMemory.getTotal()), globalMemory.getAvailable(), globalMemory.getTotal() - globalMemory.getAvailable());
    final VirtualMemory virtualMemory = globalMemory.getVirtualMemory();
    final Swap swap = Swap.create(virtualMemory.getSwapTotal(), virtualMemory.getSwapTotal() - virtualMemory.getSwapUsed(), virtualMemory.getSwapUsed());
    final CentralProcessor centralProcessor = hardware.getProcessor();
    long[] prevTicks = centralProcessor.getSystemCpuLoadTicks();
    long[] ticks = centralProcessor.getSystemCpuLoadTicks();
    short user = (short) (ticks[TickType.USER.getIndex()] - prevTicks[TickType.USER.getIndex()]);
    short sys = (short) (ticks[TickType.SYSTEM.getIndex()] - prevTicks[TickType.SYSTEM.getIndex()]);
    short idle = (short) (ticks[TickType.IDLE.getIndex()] - prevTicks[TickType.IDLE.getIndex()]);
    short steal = (short) (ticks[TickType.STEAL.getIndex()] - prevTicks[TickType.STEAL.getIndex()]);
    final CentralProcessor.ProcessorIdentifier processorIdentifier = centralProcessor.getProcessorIdentifier();
    final Processor proc = Processor.create(processorIdentifier.getName(), processorIdentifier.getVendor(), ((int) processorIdentifier.getVendorFreq() / 1000000), centralProcessor.getLogicalProcessorCount(), centralProcessor.getPhysicalPackageCount(), centralProcessor.getLogicalProcessorCount() / centralProcessor.getPhysicalPackageCount(), -1, sys, user, idle, steal);
    return OsStats.create(centralProcessor.getSystemLoadAverage(3), service.getOs().getSystemUptime(), proc, mem, swap);
}
Also used : HardwareAbstractionLayer(oshi.hardware.HardwareAbstractionLayer) GlobalMemory(oshi.hardware.GlobalMemory) CentralProcessor(oshi.hardware.CentralProcessor) GlobalMemory(oshi.hardware.GlobalMemory) VirtualMemory(oshi.hardware.VirtualMemory) CentralProcessor(oshi.hardware.CentralProcessor) VirtualMemory(oshi.hardware.VirtualMemory)

Example 5 with HardwareAbstractionLayer

use of oshi.hardware.HardwareAbstractionLayer 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

HardwareAbstractionLayer (oshi.hardware.HardwareAbstractionLayer)6 OperatingSystem (oshi.software.os.OperatingSystem)4 SystemInfo (oshi.SystemInfo)3 CentralProcessor (oshi.hardware.CentralProcessor)3 GlobalMemory (oshi.hardware.GlobalMemory)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 Inject (javax.inject.Inject)1 StringUtils (org.apache.commons.lang3.StringUtils)1 MetricGroup (org.apache.flink.metrics.MetricGroup)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 HWDiskStore (oshi.hardware.HWDiskStore)1 HWPartition (oshi.hardware.HWPartition)1