diff --git a/settings.gradle.kts b/settings.gradle.kts
index 9bf7d6e..71dbf93 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -14,5 +14,5 @@ include(
"thread", "hibernate", "jdbc-sqlite",
"xml", "jackson", "jsoup", "markdown", "network", "httpd",
"swing", "java-fx", "properties",
- "mustache", "thymeleaf", "locale", "quartz"
+ "mustache", "thymeleaf", "locale", "quartz", "sysinfo"
)
diff --git a/sysinfo/build.gradle.kts b/sysinfo/build.gradle.kts
new file mode 100644
index 0000000..87cd099
--- /dev/null
+++ b/sysinfo/build.gradle.kts
@@ -0,0 +1,15 @@
+/*
+ * Examples for Java
+ *
+ * Copyright (c) 2021. Elex. All Rights Reserved.
+ * https://www.elex-project.com/
+ */
+
+plugins {
+ id("elex-java")
+}
+
+dependencies {
+
+
+}
diff --git a/sysinfo/logback.xml b/sysinfo/logback.xml
new file mode 100644
index 0000000..74ff8a3
--- /dev/null
+++ b/sysinfo/logback.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+
+
+
+
+
+
+
diff --git a/sysinfo/src/main/java/kr/pe/elex/examples/ClassLoadingInfo.java b/sysinfo/src/main/java/kr/pe/elex/examples/ClassLoadingInfo.java
new file mode 100644
index 0000000..2c3d080
--- /dev/null
+++ b/sysinfo/src/main/java/kr/pe/elex/examples/ClassLoadingInfo.java
@@ -0,0 +1,35 @@
+/*
+ * Examples for Java
+ *
+ * Copyright (c) 2021. Elex. All Rights Reserved.
+ * https://www.elex-project.com/
+ */
+
+package kr.pe.elex.examples;
+
+import lombok.extern.slf4j.Slf4j;
+
+import java.lang.management.ClassLoadingMXBean;
+import java.lang.management.ManagementFactory;
+
+@Slf4j
+public class ClassLoadingInfo {
+ private final ClassLoadingMXBean bean;
+
+ private ClassLoadingInfo() {
+ bean = ManagementFactory.getClassLoadingMXBean();
+
+ }
+
+ public static ClassLoadingInfo get() {
+ return new ClassLoadingInfo();
+ }
+
+ public long getTotalLoadedClassCount() {
+ return bean.getTotalLoadedClassCount();
+ }
+
+ public int getLoadedClassCount() {
+ return bean.getLoadedClassCount();
+ }
+}
diff --git a/sysinfo/src/main/java/kr/pe/elex/examples/CpuInfo.java b/sysinfo/src/main/java/kr/pe/elex/examples/CpuInfo.java
new file mode 100644
index 0000000..05e1db9
--- /dev/null
+++ b/sysinfo/src/main/java/kr/pe/elex/examples/CpuInfo.java
@@ -0,0 +1,74 @@
+/*
+ * Examples for Java
+ *
+ * Copyright (c) 2021. Elex. All Rights Reserved.
+ * https://www.elex-project.com/
+ */
+
+package kr.pe.elex.examples;
+
+import lombok.extern.slf4j.Slf4j;
+import org.jetbrains.annotations.Contract;
+import org.jetbrains.annotations.NotNull;
+
+import java.lang.management.ManagementFactory;
+
+@Slf4j
+public class CpuInfo {
+ private static final int availableProcessors = OSInfo.get().getAvailableProcessors();
+ private static long lastSystemTime = 0;
+ private static long lastProcessCpuTime = 0;
+ private double systemCpuLoad, processCpuLoad;
+ private long processCpuTime;
+ private CpuInfo() {
+ com.sun.management.OperatingSystemMXBean mxBean =
+ (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
+ this.systemCpuLoad = mxBean.getSystemCpuLoad();
+ this.processCpuLoad = mxBean.getProcessCpuLoad();
+ this.processCpuTime = mxBean.getProcessCpuTime();
+ }
+
+ @NotNull
+ @Contract(" -> new")
+ public static CpuInfo get() {
+ return new CpuInfo();
+ }
+
+ public static synchronized double getCpuUsage() {
+
+ if (lastSystemTime == 0) {
+ baselineCounters();
+ return 0;
+ }
+
+ long systemTime = System.nanoTime();
+ long processCpuTime = 0;
+
+ processCpuTime = new CpuInfo().getProcessCpuTime();
+
+ double cpuUsage = (double) (processCpuTime - lastProcessCpuTime) / (systemTime - lastSystemTime);
+
+ lastSystemTime = systemTime;
+ lastProcessCpuTime = processCpuTime;
+
+ return cpuUsage / availableProcessors;
+ }
+
+ private static void baselineCounters() {
+ lastSystemTime = System.nanoTime();
+ lastProcessCpuTime = new CpuInfo().getProcessCpuTime();
+
+ }
+
+ public double getSystemCpuLoad() {
+ return systemCpuLoad;
+ }
+
+ public double getProcessCpuLoad() {
+ return processCpuLoad;
+ }
+
+ public long getProcessCpuTime() {
+ return processCpuTime;
+ }
+}
diff --git a/sysinfo/src/main/java/kr/pe/elex/examples/DiskInfo.java b/sysinfo/src/main/java/kr/pe/elex/examples/DiskInfo.java
new file mode 100644
index 0000000..fc9fd24
--- /dev/null
+++ b/sysinfo/src/main/java/kr/pe/elex/examples/DiskInfo.java
@@ -0,0 +1,53 @@
+/*
+ * Examples for Java
+ *
+ * Copyright (c) 2021. Elex. All Rights Reserved.
+ * https://www.elex-project.com/
+ */
+
+package kr.pe.elex.examples;
+
+import lombok.extern.slf4j.Slf4j;
+import org.jetbrains.annotations.Contract;
+import org.jetbrains.annotations.NotNull;
+
+import java.io.File;
+
+@Slf4j
+public class DiskInfo {
+ private final long totalSpace, freeSpace, usableSpace;
+
+ private DiskInfo(@NotNull File root) {
+ this.totalSpace = root.getTotalSpace();
+ this.freeSpace = root.getFreeSpace();
+ this.usableSpace = root.getUsableSpace();
+ }
+
+ @NotNull
+ @Contract("_ -> new")
+ public static DiskInfo get(@NotNull File root) {
+
+ return new DiskInfo(root);
+ }
+
+ /**
+ * @return bytes
+ */
+ public long getTotalSpace() {
+ return totalSpace;
+ }
+
+ /**
+ * @return bytes
+ */
+ public long getFreeSpace() {
+ return freeSpace;
+ }
+
+ /**
+ * @return bytes
+ */
+ public long getUsableSpace() {
+ return usableSpace;
+ }
+}
diff --git a/sysinfo/src/main/java/kr/pe/elex/examples/MemoryInfo.java b/sysinfo/src/main/java/kr/pe/elex/examples/MemoryInfo.java
new file mode 100644
index 0000000..81380ff
--- /dev/null
+++ b/sysinfo/src/main/java/kr/pe/elex/examples/MemoryInfo.java
@@ -0,0 +1,79 @@
+/*
+ * Examples for Java
+ *
+ * Copyright (c) 2021. Elex. All Rights Reserved.
+ * https://www.elex-project.com/
+ */
+
+package kr.pe.elex.examples;
+
+import lombok.extern.slf4j.Slf4j;
+import org.jetbrains.annotations.Contract;
+import org.jetbrains.annotations.NotNull;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryMXBean;
+import java.lang.management.MemoryUsage;
+
+@Slf4j
+public class MemoryInfo {
+ private final long heapMax, heapUsed;
+ private final long nonHeapMax, nonHeapUsed;
+ private final long totalPhysicalMemory, freePhysicalMemory;
+ private final long totalSwapMemory, freeSwapMemory;
+ private MemoryInfo() {
+ MemoryMXBean memory = ManagementFactory.getMemoryMXBean();
+ MemoryUsage usage = memory.getHeapMemoryUsage();
+ this.heapMax = usage.getMax();
+ this.heapUsed = usage.getUsed();
+ usage = memory.getNonHeapMemoryUsage();
+ this.nonHeapMax = usage.getMax();
+ this.nonHeapUsed = usage.getUsed();
+
+ com.sun.management.OperatingSystemMXBean osBean =
+ (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
+
+ this.totalPhysicalMemory = osBean.getTotalPhysicalMemorySize();
+ this.freePhysicalMemory = osBean.getFreePhysicalMemorySize();
+ this.totalSwapMemory = osBean.getTotalSwapSpaceSize();
+ this.freeSwapMemory = osBean.getFreeSwapSpaceSize();
+ }
+
+ @NotNull
+ @Contract(" -> new")
+ public static MemoryInfo get() {
+ return new MemoryInfo();
+ }
+
+ public long getHeapMax() {
+ return heapMax;
+ }
+
+ public long getHeapUsed() {
+ return heapUsed;
+ }
+
+ public long getNonHeapMax() {
+ return nonHeapMax;
+ }
+
+ public long getNonHeapUsed() {
+ return nonHeapUsed;
+ }
+
+ public long getTotalPhysicalMemory() {
+ return totalPhysicalMemory;
+ }
+
+ public long getFreePhysicalMemory() {
+ return freePhysicalMemory;
+ }
+
+ public long getTotalSwapMemory() {
+ return totalSwapMemory;
+ }
+
+ public long getFreeSwapMemory() {
+ return freeSwapMemory;
+ }
+}
diff --git a/sysinfo/src/main/java/kr/pe/elex/examples/OSInfo.java b/sysinfo/src/main/java/kr/pe/elex/examples/OSInfo.java
new file mode 100644
index 0000000..7f1503e
--- /dev/null
+++ b/sysinfo/src/main/java/kr/pe/elex/examples/OSInfo.java
@@ -0,0 +1,96 @@
+/*
+ * Examples for Java
+ *
+ * Copyright (c) 2021. Elex. All Rights Reserved.
+ * https://www.elex-project.com/
+ */
+
+package kr.pe.elex.examples;
+
+import lombok.extern.slf4j.Slf4j;
+import org.jetbrains.annotations.Contract;
+import org.jetbrains.annotations.NotNull;
+
+import java.lang.management.ManagementFactory;
+
+@Slf4j
+public class OSInfo {
+ private String name, arch, version;
+ private int availableProcessors;
+ private double systemLoadAverage;
+ private long totalPhysicalMemorySize, freePhysicalMemorySize;
+ private long totalSwapSpaceSize, freeSwapSpaceSize;
+ private long vmMemorySize;
+ private double processCpuLoad;
+ private long processCpuTime;
+ private OSInfo() {
+ com.sun.management.OperatingSystemMXBean bean =
+ (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
+ this.name = bean.getName();
+ this.arch = bean.getArch();
+ this.version = bean.getVersion();
+ this.availableProcessors = bean.getAvailableProcessors();
+ this.systemLoadAverage = bean.getSystemLoadAverage();
+ this.processCpuLoad = bean.getProcessCpuLoad();
+ this.processCpuTime = bean.getProcessCpuTime();
+ this.totalPhysicalMemorySize = bean.getTotalPhysicalMemorySize();
+ this.freePhysicalMemorySize = bean.getFreePhysicalMemorySize();
+ this.totalSwapSpaceSize = bean.getTotalSwapSpaceSize();
+ this.freeSwapSpaceSize = bean.getFreeSwapSpaceSize();
+ this.vmMemorySize = bean.getCommittedVirtualMemorySize();
+ }
+
+ @NotNull
+ @Contract(" -> new")
+ public static OSInfo get() {
+ return new OSInfo();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getArch() {
+ return arch;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public int getAvailableProcessors() {
+ return availableProcessors;
+ }
+
+ public double getSystemLoadAverage() {
+ return systemLoadAverage;
+ }
+
+ public long getTotalPhysicalMemorySize() {
+ return totalPhysicalMemorySize;
+ }
+
+ public long getFreePhysicalMemorySize() {
+ return freePhysicalMemorySize;
+ }
+
+ public long getTotalSwapSpaceSize() {
+ return totalSwapSpaceSize;
+ }
+
+ public long getFreeSwapSpaceSize() {
+ return freeSwapSpaceSize;
+ }
+
+ public long getVmMemorySize() {
+ return vmMemorySize;
+ }
+
+ public double getProcessCpuLoad() {
+ return processCpuLoad;
+ }
+
+ public long getProcessCpuTime() {
+ return processCpuTime;
+ }
+}
diff --git a/sysinfo/src/main/java/kr/pe/elex/examples/RuntimeInfo.java b/sysinfo/src/main/java/kr/pe/elex/examples/RuntimeInfo.java
new file mode 100644
index 0000000..6b3d648
--- /dev/null
+++ b/sysinfo/src/main/java/kr/pe/elex/examples/RuntimeInfo.java
@@ -0,0 +1,86 @@
+/*
+ * Examples for Java
+ *
+ * Copyright (c) 2021. Elex. All Rights Reserved.
+ * https://www.elex-project.com/
+ */
+
+package kr.pe.elex.examples;
+
+import lombok.extern.slf4j.Slf4j;
+import org.jetbrains.annotations.Contract;
+import org.jetbrains.annotations.NotNull;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.RuntimeMXBean;
+
+@Slf4j
+public class RuntimeInfo {
+ private String name, specName, specVendor, specVersion;
+ private String vmName, vmVendor, vmVersion;
+ private long startTime, upTime;
+ private RuntimeInfo() {
+ RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
+
+ this.name = runtime.getName();
+ this.specName = runtime.getSpecName();
+ this.specVendor = runtime.getSpecVendor();
+ this.specVersion = runtime.getSpecVersion();
+
+ this.vmName = runtime.getVmName();
+ this.vmVendor = runtime.getVmVendor();
+ this.vmVersion = runtime.getVmVersion();
+
+ this.startTime = runtime.getStartTime();
+ this.upTime = runtime.getUptime();
+ try {
+ /* Requires 10+ */
+ //info.pid = runtime.getPid();
+ } catch (Throwable e) {
+ //info.pid = 0L;
+ }
+ }
+ //private long pid; /* Requires 10+ */
+
+ @NotNull
+ @Contract(" -> new")
+ public static RuntimeInfo get() {
+ return new RuntimeInfo();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getSpecName() {
+ return specName;
+ }
+
+ public String getSpecVendor() {
+ return specVendor;
+ }
+
+ public String getSpecVersion() {
+ return specVersion;
+ }
+
+ public String getVmName() {
+ return vmName;
+ }
+
+ public String getVmVendor() {
+ return vmVendor;
+ }
+
+ public String getVmVersion() {
+ return vmVersion;
+ }
+
+ public long getStartTime() {
+ return startTime;
+ }
+
+ public long getUpTime() {
+ return upTime;
+ }
+}
diff --git a/sysinfo/src/main/java/kr/pe/elex/examples/SysInfo.java b/sysinfo/src/main/java/kr/pe/elex/examples/SysInfo.java
new file mode 100644
index 0000000..a3a1ac2
--- /dev/null
+++ b/sysinfo/src/main/java/kr/pe/elex/examples/SysInfo.java
@@ -0,0 +1,28 @@
+/*
+ * Examples for Java
+ *
+ * Copyright (c) 2021. Elex. All Rights Reserved.
+ * https://www.elex-project.com/
+ */
+
+package kr.pe.elex.examples;
+
+import lombok.extern.slf4j.Slf4j;
+
+import java.lang.management.CompilationMXBean;
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryManagerMXBean;
+import java.lang.management.ThreadMXBean;
+
+@Slf4j
+class SysInfo {
+
+ private SysInfo() {
+ ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
+ //threadMXBean.
+ MemoryManagerMXBean memoryManagerMXBean = (MemoryManagerMXBean) ManagementFactory.getMemoryManagerMXBeans();
+ //memoryManagerMXBean.
+ CompilationMXBean compilationMXBean = ManagementFactory.getCompilationMXBean();
+ //compilationMXBean.
+ }
+}
diff --git a/sysinfo/src/main/java/kr/pe/elex/examples/SysInfoUtils.java b/sysinfo/src/main/java/kr/pe/elex/examples/SysInfoUtils.java
new file mode 100644
index 0000000..d806422
--- /dev/null
+++ b/sysinfo/src/main/java/kr/pe/elex/examples/SysInfoUtils.java
@@ -0,0 +1,41 @@
+/*
+ * Examples for Java
+ *
+ * Copyright (c) 2021. Elex. All Rights Reserved.
+ * https://www.elex-project.com/
+ */
+
+package kr.pe.elex.examples;
+
+import com.elex_project.abraxas.Exez;
+import lombok.extern.slf4j.Slf4j;
+import org.jetbrains.annotations.NotNull;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Slf4j
+public class SysInfoUtils {
+
+ private SysInfoUtils() {
+ }
+
+ @NotNull
+ public static Map getOSInfo() {
+ HashMap map = new HashMap<>();
+ try {
+ List result = Exez.exec("cat /etc/*-release");
+ for (String line : result) {
+ String[] parted = line.split("=");
+ map.put(parted[0], parted[1]);
+ }
+
+ } catch (IOException | InterruptedException e) {
+ log.error("Oops!", e);
+ }
+
+ return map;
+ }
+}
diff --git a/sysinfo/src/main/java/kr/pe/elex/examples/ThreadInfo.java b/sysinfo/src/main/java/kr/pe/elex/examples/ThreadInfo.java
new file mode 100644
index 0000000..80c8776
--- /dev/null
+++ b/sysinfo/src/main/java/kr/pe/elex/examples/ThreadInfo.java
@@ -0,0 +1,49 @@
+/*
+ * Examples for Java
+ *
+ * Copyright (c) 2021. Elex. All Rights Reserved.
+ * https://www.elex-project.com/
+ */
+
+package kr.pe.elex.examples;
+
+import com.sun.management.ThreadMXBean;
+import lombok.extern.slf4j.Slf4j;
+import org.jetbrains.annotations.Contract;
+import org.jetbrains.annotations.NotNull;
+
+import java.lang.management.ManagementFactory;
+
+@Slf4j
+public class ThreadInfo {
+ private final ThreadMXBean bean;
+
+ private ThreadInfo() {
+ bean = (ThreadMXBean) ManagementFactory.getThreadMXBean();
+ }
+
+ @Contract(" -> new")
+ public static @NotNull ThreadInfo get() {
+ return new ThreadInfo();
+ }
+
+ public long[] getThreadIds() {
+ return bean.getAllThreadIds();
+ }
+
+ public long getThreadCpuTime(long id) {
+ return bean.getThreadCpuTime(id);
+ }
+
+ public long getThreadUserTime(long id) {
+ return bean.getThreadUserTime(id);
+ }
+
+ public int getThreadCount() {
+ return bean.getThreadCount();
+ }
+
+ public long getAllocatedBytes(long id) {
+ return bean.getThreadAllocatedBytes(id);
+ }
+}
diff --git a/sysinfo/src/test/java/kr/pe/elex/examples/SysInfoTest.java b/sysinfo/src/test/java/kr/pe/elex/examples/SysInfoTest.java
new file mode 100644
index 0000000..cc6f7ce
--- /dev/null
+++ b/sysinfo/src/test/java/kr/pe/elex/examples/SysInfoTest.java
@@ -0,0 +1,72 @@
+/*
+ * Examples for Java
+ *
+ * Copyright (c) 2021. Elex. All Rights Reserved.
+ * https://www.elex-project.com/
+ */
+
+package kr.pe.elex.examples;
+
+import lombok.extern.slf4j.Slf4j;
+import org.junit.jupiter.api.Test;
+
+@Slf4j
+public class SysInfoTest {
+ /*@Test
+ public void testProcessorInfo(){
+ ProcessorInfo info = HardwareInfo.getProcessorInfo();
+ L.i("getModelName", info.getModelName());
+ L.i("getStepping", info.getStepping());
+ L.i("getCacheSize", info.getCacheSize());
+ L.i("getFamily", info.getFamily());
+ L.i("getVendorId", info.getVendorId());
+ L.i("getNumCores", info.getNumCores());
+ L.i("getMhz", info.getMhz());
+ L.i("getTemperature", info.getTemperature());
+ }
+
+ @Test
+ public void testBiosInfo(){
+ BiosInfo info = HardwareInfo.getBiosInfo();
+ L.i("getManufacturer", info.getManufacturer());
+ L.i("getVersion", info.getVersion());
+ L.i("getDate", info.getDate());
+ }
+
+ @Test
+ public void testMotherboardInfo(){
+ MotherboardInfo info = HardwareInfo.getMotherboardInfo();
+ L.i("getManufacturer", info.getManufacturer());
+ L.i("getVersion", info.getVersion());
+ L.i("Name", info.getName());
+ }
+
+ @Test
+ public void testOSInfo(){
+ OSInfo info = HardwareInfo.getOSInfo();
+ L.i("getName", info.getName());
+ L.i("getManufacturer", info.getManufacturer());
+ L.i("getVersion", info.getVersion());
+ L.i("getLastBootTime", info.getLastBootTime());
+ }
+
+ @Test
+ public void testMemoryInfo(){
+ MemoryInfo info = HardwareInfo.getMemoryInfo();
+ L.i("getTotalMemory", info.getTotalMemory());
+ L.i("getAvailableMemory", info.getAvailableMemory());
+ L.i("getFreeMemory", info.getFreeMemory());
+ }
+
+ @Test
+ public void testNetworkInfo(){
+ NetworkInfo info = HardwareInfo.getNetworkInfo();
+ NetworkInterfaceInfo networkInterface = info.getNetworkInterfaces().get(0);
+ L.i("getName", networkInterface.getName());
+ L.i("getType", networkInterface.getType());
+ L.i("getIpv4", networkInterface.getIpv4());
+ L.i("getIpv6", networkInterface.getIpv6());
+ L.i("getReceivedBytes", networkInterface.getReceivedBytes());
+ L.i("getTransmittedBytes", networkInterface.getTransmittedBytes());
+ }*/
+}