Search in sources :

Example 6 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)

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