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