use of oshi.SystemInfo 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);
}
}
use of oshi.SystemInfo in project dolphin-platform-examples by canoo.
the class ProcessMonitorController method onInit.
@PostConstruct
public void onInit() {
SystemInfo si = new SystemInfo();
os = si.getOperatingSystem();
memory = si.getHardware().getMemory();
sessionExecutor = context.createSessionExecutor();
update();
}
use of oshi.SystemInfo 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.SystemInfo 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());
}
use of oshi.SystemInfo in project Nukkit by Nukkit.
the class BugReportGenerator method generate.
private String generate() throws IOException {
File reports = new File(Nukkit.DATA_PATH, "logs/bug_reports");
if (!reports.isDirectory()) {
reports.mkdirs();
}
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmSS");
String date = simpleDateFormat.format(new Date());
SystemInfo systemInfo = new SystemInfo();
long totalDiskSize = 0;
StringBuilder model = new StringBuilder();
for (HWDiskStore hwDiskStore : systemInfo.getHardware().getDiskStores()) {
totalDiskSize += hwDiskStore.getSize();
if (!model.toString().contains(hwDiskStore.getModel())) {
model.append(hwDiskStore.getModel()).append(" ");
}
}
StringWriter stringWriter = new StringWriter();
throwable.printStackTrace(new PrintWriter(stringWriter));
File mdReport = new File(reports, date + "_" + throwable.getClass().getSimpleName() + ".md");
mdReport.createNewFile();
String content = Utils.readFile(this.getClass().getClassLoader().getResourceAsStream("report_template.md"));
Properties properties = getGitRepositoryState();
System.out.println(properties.getProperty("git.commit.id.abbrev"));
String abbrev = properties.getProperty("git.commit.id.abbrev");
content = content.replace("${NUKKIT_VERSION}", Nukkit.VERSION);
content = content.replace("${GIT_COMMIT_ABBREV}", abbrev);
content = content.replace("${JAVA_VERSION}", System.getProperty("java.vm.name") + " (" + System.getProperty("java.runtime.version") + ")");
content = content.replace("${HOSTOS}", systemInfo.getOperatingSystem().getFamily() + " [" + systemInfo.getOperatingSystem().getVersion().getVersion() + "]");
content = content.replace("${MEMORY}", getCount(systemInfo.getHardware().getMemory().getTotal(), true));
content = content.replace("${STORAGE_SIZE}", getCount(totalDiskSize, true));
content = content.replace("${CPU_TYPE}", systemInfo.getHardware().getProcessor().getName());
content = content.replace("${PHYSICAL_CORE}", String.valueOf(systemInfo.getHardware().getProcessor().getPhysicalProcessorCount()));
content = content.replace("${LOGICAL_CORE}", String.valueOf(systemInfo.getHardware().getProcessor().getLogicalProcessorCount()));
content = content.replace("${STACKTRACE}", stringWriter.toString());
content = content.replace("${PLUGIN_ERROR}", String.valueOf(!throwable.getStackTrace()[0].getClassName().startsWith("cn.nukkit")).toUpperCase());
content = content.replace("${STORAGE_TYPE}", model.toString());
Utils.writeFile(mdReport, content);
return mdReport.getAbsolutePath();
}
Aggregations