From 108ce0a8017827417dda874a815d7094d7025924 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Wed, 18 Jan 2023 12:47:36 -0500 Subject: [PATCH] Added some styles to the overview page; added more information to the overview page --- pom.xml | 5 ++ src/main/java/net/metaunix/App.java | 2 +- src/main/java/net/metaunix/SysInfo.java | 6 ++ .../metaunix/controllers/HomeController.java | 16 +++- .../services/UpdateSystemInfoService.java | 11 +++ src/main/resources/stylesheets/home.css | 13 ++++ src/main/resources/views/home.fxml | 76 ++++++++++++++++--- 7 files changed, 118 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 84eb3d0..c10b2f5 100644 --- a/pom.xml +++ b/pom.xml @@ -25,6 +25,11 @@ oshi-core 6.4.0 + + org.apache.commons + commons-math3 + 3.6.1 + diff --git a/src/main/java/net/metaunix/App.java b/src/main/java/net/metaunix/App.java index d25c854..fb2b730 100644 --- a/src/main/java/net/metaunix/App.java +++ b/src/main/java/net/metaunix/App.java @@ -31,7 +31,7 @@ public class App extends Application { System.out.println(String.valueOf(os)); Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("views/home.fxml")); - var scene = new Scene(root, 640, 480); + var scene = new Scene(root, 800, 600); stage.setTitle("Arrow System Monitor"); stage.setScene(scene); stage.show(); diff --git a/src/main/java/net/metaunix/SysInfo.java b/src/main/java/net/metaunix/SysInfo.java index 120dc1b..493935e 100644 --- a/src/main/java/net/metaunix/SysInfo.java +++ b/src/main/java/net/metaunix/SysInfo.java @@ -5,9 +5,15 @@ public class SysInfo { public static String osString = "N/a"; public static double cpuTemp = 0.0; + public static double cpuUsage = 0.0; public static long cpuFreq = 0; public static long cpuMaxFreq = 0; + public static long memoryUsed = 0; + public static long memoryTotal = 0; + + public static String gpuName = "N/a"; + public static String javaVersion() { return System.getProperty("java.version"); } diff --git a/src/main/java/net/metaunix/controllers/HomeController.java b/src/main/java/net/metaunix/controllers/HomeController.java index 801f196..1196f2e 100644 --- a/src/main/java/net/metaunix/controllers/HomeController.java +++ b/src/main/java/net/metaunix/controllers/HomeController.java @@ -3,7 +3,7 @@ package net.metaunix.controllers; import javafx.fxml.FXML; import javafx.scene.control.Label; import javafx.util.Duration; - +import org.apache.commons.math3.util.Precision; import net.metaunix.SysInfo; import net.metaunix.services.UpdateSystemInfoService; @@ -13,8 +13,14 @@ public class HomeController { @FXML private Label osInfo; @FXML + private Label overCpuUsage; + @FXML private Label overCpuTemp; @FXML + private Label overMemoryUsage; + @FXML + private Label overGpuTemp; + @FXML private Label cpuCpuTemp; @FXML private Label cpuCpuFreq; @@ -33,7 +39,15 @@ public class HomeController { private void updateLabels() { osInfo.setText(SysInfo.osString); + overCpuUsage.setText(String.valueOf(Precision.round(SysInfo.cpuUsage * 100, 1)) + "%"); overCpuTemp.setText(String.valueOf(SysInfo.cpuTemp)); + overMemoryUsage.setText( + String.valueOf(Precision.round((double) SysInfo.memoryUsed / (1024*1024*1024), 2)) + + "GB / " + + String.valueOf(Precision.round((double) SysInfo.memoryTotal / (1024*1024*1024), 2)) + + "GB" + ); + overGpuTemp.setText(String.valueOf(SysInfo.gpuName)); cpuCpuTemp.setText(String.valueOf(SysInfo.cpuTemp)); cpuCpuFreq.setText(String.valueOf(SysInfo.cpuFreq)); cpuCpuMaxFreq.setText(String.valueOf(SysInfo.cpuMaxFreq)); diff --git a/src/main/java/net/metaunix/services/UpdateSystemInfoService.java b/src/main/java/net/metaunix/services/UpdateSystemInfoService.java index 5e514c4..5f2d8f1 100644 --- a/src/main/java/net/metaunix/services/UpdateSystemInfoService.java +++ b/src/main/java/net/metaunix/services/UpdateSystemInfoService.java @@ -1,10 +1,13 @@ package net.metaunix.services; import java.util.Arrays; +import java.util.List; import javafx.concurrent.ScheduledService; import javafx.concurrent.Task; import oshi.SystemInfo; import oshi.hardware.CentralProcessor; +import oshi.hardware.GlobalMemory; +import oshi.hardware.GraphicsCard; import oshi.hardware.HardwareAbstractionLayer; import oshi.hardware.Sensors; import oshi.software.os.OperatingSystem; @@ -32,6 +35,14 @@ public class UpdateSystemInfoService extends ScheduledService { SysInfo.cpuTemp = sensors.getCpuTemperature(); CentralProcessor cpu = hal.getProcessor(); SysInfo.cpuMaxFreq = cpu.getMaxFreq(); + SysInfo.cpuUsage = (cpu.getSystemLoadAverage(3)[0] / cpu.getLogicalProcessorCount()); + + GlobalMemory memory = hal.getMemory(); + SysInfo.memoryTotal = memory.getTotal(); + SysInfo.memoryUsed = (SysInfo.memoryTotal - memory.getAvailable()); + + List gpus = hal.getGraphicsCards(); + SysInfo.gpuName = gpus.get(0).getName(); long[] freqs = cpu.getCurrentFreq(); Arrays.sort(freqs); diff --git a/src/main/resources/stylesheets/home.css b/src/main/resources/stylesheets/home.css index fcba9bb..44681b7 100644 --- a/src/main/resources/stylesheets/home.css +++ b/src/main/resources/stylesheets/home.css @@ -1,3 +1,16 @@ +GridPane{ + -fx-background-color: #212121; + -fx-vgap: 1; + -fx-hgap: 1; +} +GridPane AnchorPane{ + -fx-background-color: white; +} + +.overview-value{ + -fx-font-size: 32px; +} + .info-box{ -fx-padding: 10; } diff --git a/src/main/resources/views/home.fxml b/src/main/resources/views/home.fxml index 1ec7649..354e03a 100644 --- a/src/main/resources/views/home.fxml +++ b/src/main/resources/views/home.fxml @@ -32,7 +32,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --> - @@ -41,6 +40,10 @@ + + + + @@ -92,15 +95,66 @@ - + + + + + + + + + - - - - - + @@ -128,7 +182,11 @@ - + + + +