Merge pull request #4 from rememberber/dev

Dev
This commit is contained in:
周波 2021-12-22 23:17:17 +08:00 committed by GitHub
commit 1f69d83d74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 961 additions and 66 deletions

93
pom.xml
View File

@ -6,7 +6,7 @@
<groupId>com.luoboduner.moo.info</groupId>
<artifactId>MooInfo</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
<packaging>jar</packaging>
<name>MooInfo</name>
@ -26,11 +26,12 @@
<commons-lang3.version>3.12.0</commons-lang3.version>
<guava.version>31.0.1-jre</guava.version>
<okhttp.version>4.9.3</okhttp.version>
<flatlaf.version>1.6.5</flatlaf.version>
<flatlaf-extras.version>1.6.5</flatlaf-extras.version>
<flatlaf.version>2.0-rc1</flatlaf.version>
<flatlaf-extras.version>2.0-rc1</flatlaf-extras.version>
<hutool-all.version>5.7.16</hutool-all.version>
<fastjson.version>1.2.78</fastjson.version>
<oshi-core.version>5.8.5</oshi-core.version>
<oshi-core.version>5.8.6</oshi-core.version>
<jfreechart.version>1.5.3</jfreechart.version>
</properties>
<dependencies>
@ -120,6 +121,12 @@
<artifactId>oshi-core</artifactId>
<version>${oshi-core.version}</version>
</dependency>
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>${jfreechart.version}</version>
</dependency>
</dependencies>
<build>
@ -134,47 +141,47 @@
<generateInstaller>true</generateInstaller>
</configuration>
<executions>
<!-- <execution>-->
<!-- <id>bundling-for-windows</id>-->
<!-- <phase>package</phase>-->
<!-- <goals>-->
<!-- <goal>package</goal>-->
<!-- </goals>-->
<!-- <configuration>-->
<!-- <platform>windows</platform>-->
<!-- <createZipball>true</createZipball>-->
<!-- &lt;!&ndash; <administratorRequired>true</administratorRequired>&ndash;&gt;-->
<!-- <winConfig>-->
<execution>
<id>bundling-for-windows</id>
<phase>package</phase>
<goals>
<goal>package</goal>
</goals>
<configuration>
<platform>windows</platform>
<createZipball>true</createZipball>
<!-- <administratorRequired>true</administratorRequired>-->
<winConfig>
<!-- &lt;!&ndash; general properties &ndash;&gt;-->
<!-- <generateSetup>true</generateSetup>-->
<!-- <generateMsi>true</generateMsi>-->
<!-- <generateMsm>true</generateMsm>-->
<!-- general properties -->
<generateSetup>true</generateSetup>
<generateMsi>true</generateMsi>
<generateMsm>true</generateMsm>
<!-- &lt;!&ndash; setup generation properties &ndash;&gt;-->
<!-- <setupMode>installForAllUsers</setupMode>-->
<!-- <createDesktopIconTask>true</createDesktopIconTask>-->
<!-- <disableDirPage>false</disableDirPage>-->
<!-- <disableFinishedPage>false</disableFinishedPage>-->
<!-- <setupLanguages>-->
<!-- <english>compiler:Default.isl</english>-->
<!-- &lt;!&ndash; <spanish>compiler:Languages\Chinese.isl</spanish>&ndash;&gt;-->
<!-- </setupLanguages>-->
<!-- </winConfig>-->
<!-- </configuration>-->
<!-- </execution>-->
<execution>
<id>bundling-for-linux</id>
<phase>package</phase>
<goals>
<goal>package</goal>
</goals>
<configuration>
<platform>linux</platform>
<createTarball>true</createTarball>
<!-- <jdkPath>X:\\path\to\linux\jdk</jdkPath>-->
</configuration>
</execution>
<!-- setup generation properties -->
<setupMode>installForAllUsers</setupMode>
<createDesktopIconTask>true</createDesktopIconTask>
<disableDirPage>false</disableDirPage>
<disableFinishedPage>false</disableFinishedPage>
<setupLanguages>
<english>compiler:Default.isl</english>
<!-- <spanish>compiler:Languages\Chinese.isl</spanish>-->
</setupLanguages>
</winConfig>
</configuration>
</execution>
<!-- <execution>-->
<!-- <id>bundling-for-linux</id>-->
<!-- <phase>package</phase>-->
<!-- <goals>-->
<!-- <goal>package</goal>-->
<!-- </goals>-->
<!-- <configuration>-->
<!-- <platform>linux</platform>-->
<!-- <createTarball>true</createTarball>-->
<!--&lt;!&ndash; <jdkPath>X:\\path\to\linux\jdk</jdkPath>&ndash;&gt;-->
<!-- </configuration>-->
<!-- </execution>-->
<!-- <execution>-->
<!-- <id>bundling-for-mac</id>-->
<!-- <phase>package</phase>-->

Binary file not shown.

Before

Width:  |  Height:  |  Size: 607 KiB

After

Width:  |  Height:  |  Size: 639 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 735 KiB

After

Width:  |  Height:  |  Size: 686 KiB

View File

@ -1,12 +1,17 @@
package com.luoboduner.moo.info;
import com.formdev.flatlaf.extras.FlatDesktop;
import com.formdev.flatlaf.util.SystemInfo;
import com.luoboduner.moo.info.ui.Init;
import com.luoboduner.moo.info.ui.dialog.AboutDialog;
import com.luoboduner.moo.info.ui.dialog.SettingDialog;
import com.luoboduner.moo.info.ui.form.LoadingForm;
import com.luoboduner.moo.info.ui.form.MainWindow;
import com.luoboduner.moo.info.ui.frame.MainFrame;
import com.luoboduner.moo.info.util.ConfigUtil;
import com.luoboduner.moo.info.util.UpgradeUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;
import javax.swing.*;
import java.awt.*;
@ -17,6 +22,7 @@ import java.awt.*;
* @author <a href="https://github.com/rememberber">RememBerBer</a>
* @since 2021/11/07.
*/
@Slf4j
public class App {
public static ConfigUtil config = ConfigUtil.getInstance();
@ -34,6 +40,29 @@ public class App {
System.setProperty("apple.awt.application.name", "MooInfo");
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "MooInfo");
System.setProperty("apple.awt.application.appearance", "system");
FlatDesktop.setAboutHandler(() -> {
try {
AboutDialog dialog = new AboutDialog();
dialog.pack();
dialog.setVisible(true);
} catch (Exception e2) {
log.error(ExceptionUtils.getStackTrace(e2));
}
});
FlatDesktop.setPreferencesHandler(() -> {
try {
SettingDialog dialog = new SettingDialog();
dialog.pack();
dialog.setVisible(true);
} catch (Exception e2) {
log.error(ExceptionUtils.getStackTrace(e2));
}
});
FlatDesktop.setQuitHandler(FlatDesktop.QuitResponse::performQuit);
}
Init.initTheme();

View File

@ -11,7 +11,7 @@ import java.awt.*;
public class UiConsts {
public static final String APP_NAME = "MooInfo";
public static final String APP_VERSION = "1.0.0";
public static final String APP_VERSION = "1.1.0";
public static final int TABLE_ROW_HEIGHT = 36;

View File

@ -8,6 +8,7 @@ import com.luoboduner.moo.info.ui.Init;
import com.luoboduner.moo.info.ui.dialog.AboutDialog;
import com.luoboduner.moo.info.ui.dialog.SettingDialog;
import com.luoboduner.moo.info.ui.dialog.SystemEnvResultDialog;
import com.luoboduner.moo.info.ui.dialog.SystemInfoTestDialog;
import com.luoboduner.moo.info.ui.form.MainWindow;
import com.luoboduner.moo.info.util.SystemUtil;
import com.luoboduner.moo.info.util.UpgradeUtil;
@ -107,6 +108,12 @@ public class TopMenuBar extends JMenuBar {
logMenuItem.addActionListener(e -> logActionPerformed());
appMenu.add(logMenuItem);
// System Info Test
JMenuItem syInfoTestMenuItem = new JMenuItem();
syInfoTestMenuItem.setText("System Info Test");
syInfoTestMenuItem.addActionListener(e -> sysInfoTestActionPerformed());
appMenu.add(syInfoTestMenuItem);
// System environment variables
JMenuItem sysEnvMenuItem = new JMenuItem();
sysEnvMenuItem.setText("System environment variables");
@ -335,6 +342,16 @@ public class TopMenuBar extends JMenuBar {
}
}
private void sysInfoTestActionPerformed() {
try {
SystemInfoTestDialog dialog = new SystemInfoTestDialog();
dialog.pack();
dialog.setVisible(true);
} catch (Exception e2) {
log.error("Show system info test dialog failed", e2);
}
}
private void sysEnvActionPerformed() {
try {
SystemEnvResultDialog dialog = new SystemEnvResultDialog();

View File

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.luoboduner.moo.info.ui.dialog.SystemInfoTestDialog">
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<xy x="48" y="54" width="436" height="297"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<hspacer id="98af6">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="e7465" class="javax.swing.JButton" binding="buttonOK">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Start"/>
</properties>
</component>
<component id="5723f" class="javax.swing.JButton" binding="buttonCancel">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Cancel"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<grid id="e3588" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<scrollpane id="580ba">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="35d0a" class="javax.swing.JTextArea" binding="textArea1" default-binding="true">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
</children>
</grid>
</children>
</grid>
</form>

View File

@ -0,0 +1,464 @@
package com.luoboduner.moo.info.ui.dialog;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
import com.luoboduner.moo.info.App;
import com.luoboduner.moo.info.util.ComponentUtil;
import com.luoboduner.moo.info.util.ConsoleUtil;
import oshi.SystemInfo;
import oshi.hardware.*;
import oshi.software.os.*;
import oshi.util.FormatUtil;
import oshi.util.Util;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.time.Instant;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
public class SystemInfoTestDialog extends JDialog {
private static final Log logger = LogFactory.get();
private JPanel contentPane;
private JButton buttonOK;
private JButton buttonCancel;
private JTextArea textArea1;
public SystemInfoTestDialog() {
super(App.mainFrame, "System Info Test");
ComponentUtil.setPreferSizeAndLocateToCenter(this, 0.6, 0.64);
setContentPane(contentPane);
setModal(true);
getRootPane().setDefaultButton(buttonOK);
buttonOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onOK();
}
});
buttonCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onCancel();
}
});
// call onCancel() when cross is clicked
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
onCancel();
}
});
// call onCancel() on ESCAPE
contentPane.registerKeyboardAction(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onCancel();
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
}
private void onOK() {
ThreadUtil.execute(this::sysInfoTest);
}
private void sysInfoTest() {
logger.info("Initializing System...");
SystemInfo si = new SystemInfo();
HardwareAbstractionLayer hal = si.getHardware();
OperatingSystem os = si.getOperatingSystem();
printOperatingSystem(os);
textArea1.append("\n");
logger.info("Checking computer system...");
printComputerSystem(hal.getComputerSystem());
textArea1.append("\n");
logger.info("Checking Processor...");
printProcessor(hal.getProcessor());
textArea1.append("\n");
logger.info("Checking Memory...");
printMemory(hal.getMemory());
textArea1.append("\n");
logger.info("Checking CPU...");
printCpu(hal.getProcessor());
textArea1.append("\n");
logger.info("Checking Processes...");
printProcesses(os, hal.getMemory());
textArea1.append("\n");
logger.info("Checking Services...");
printServices(os);
textArea1.append("\n");
logger.info("Checking Sensors...");
printSensors(hal.getSensors());
textArea1.append("\n");
logger.info("Checking Power sources...");
printPowerSources(hal.getPowerSources());
textArea1.append("\n");
logger.info("Checking Disks...");
printDisks(hal.getDiskStores());
textArea1.append("\n");
logger.info("Checking Logical Volume Groups ...");
printLVgroups(hal.getLogicalVolumeGroups());
textArea1.append("\n");
logger.info("Checking File System...");
printFileSystem(os.getFileSystem());
textArea1.append("\n");
logger.info("Checking Network interfaces...");
printNetworkInterfaces(hal.getNetworkIFs());
textArea1.append("\n");
logger.info("Checking Network parameters...");
printNetworkParameters(os.getNetworkParams());
textArea1.append("\n");
logger.info("Checking IP statistics...");
printInternetProtocolStats(os.getInternetProtocolStats());
textArea1.append("\n");
logger.info("Checking Displays...");
printDisplays(hal.getDisplays());
textArea1.append("\n");
logger.info("Checking USB Devices...");
printUsbDevices(hal.getUsbDevices(true));
textArea1.append("\n");
logger.info("Checking Sound Cards...");
printSoundCards(hal.getSoundCards());
textArea1.append("\n");
logger.info("Checking Graphics Cards...");
printGraphicsCards(hal.getGraphicsCards());
JOptionPane.showMessageDialog(contentPane, "Done!\n", "Finished!", JOptionPane.PLAIN_MESSAGE);
}
private void onCancel() {
// add your code here if necessary
dispose();
}
// all functions codes bellow are copied from oshi-core, and have some changed
private void printOperatingSystem(final OperatingSystem os) {
ConsoleUtil.consoleOnly(textArea1, String.valueOf(os));
ConsoleUtil.consoleOnly(textArea1, "Booted: " + Instant.ofEpochSecond(os.getSystemBootTime()));
ConsoleUtil.consoleOnly(textArea1, "Uptime: " + FormatUtil.formatElapsedSecs(os.getSystemUptime()));
ConsoleUtil.consoleOnly(textArea1, "Running with" + (os.isElevated() ? "" : "out") + " elevated permissions.");
ConsoleUtil.consoleOnly(textArea1, "Sessions:");
for (OSSession s : os.getSessions()) {
ConsoleUtil.consoleOnly(textArea1, " " + s.toString());
}
}
private void printComputerSystem(final ComputerSystem computerSystem) {
ConsoleUtil.consoleOnly(textArea1, "System: " + computerSystem.toString());
ConsoleUtil.consoleOnly(textArea1, " Firmware: " + computerSystem.getFirmware().toString());
ConsoleUtil.consoleOnly(textArea1, " Baseboard: " + computerSystem.getBaseboard().toString());
}
private void printProcessor(CentralProcessor processor) {
ConsoleUtil.consoleOnly(textArea1, processor.toString());
}
private void printMemory(GlobalMemory memory) {
ConsoleUtil.consoleOnly(textArea1, "Physical Memory: \n " + memory.toString());
VirtualMemory vm = memory.getVirtualMemory();
ConsoleUtil.consoleOnly(textArea1, "Virtual Memory: \n " + vm.toString());
List<PhysicalMemory> pmList = memory.getPhysicalMemory();
if (!pmList.isEmpty()) {
ConsoleUtil.consoleOnly(textArea1, "Physical Memory: ");
for (PhysicalMemory pm : pmList) {
ConsoleUtil.consoleOnly(textArea1, " " + pm.toString());
}
}
}
private void printCpu(CentralProcessor processor) {
ConsoleUtil.consoleOnly(textArea1, "Context Switches/Interrupts: " + processor.getContextSwitches() + " / " + processor.getInterrupts());
long[] prevTicks = processor.getSystemCpuLoadTicks();
long[][] prevProcTicks = processor.getProcessorCpuLoadTicks();
ConsoleUtil.consoleOnly(textArea1, "CPU, IOWait, and IRQ ticks @ 0 sec:" + Arrays.toString(prevTicks));
// Wait a second...
Util.sleep(1000);
long[] ticks = processor.getSystemCpuLoadTicks();
ConsoleUtil.consoleOnly(textArea1, "CPU, IOWait, and IRQ ticks @ 1 sec:" + Arrays.toString(ticks));
long user = ticks[CentralProcessor.TickType.USER.getIndex()] - prevTicks[CentralProcessor.TickType.USER.getIndex()];
long nice = ticks[CentralProcessor.TickType.NICE.getIndex()] - prevTicks[CentralProcessor.TickType.NICE.getIndex()];
long sys = ticks[CentralProcessor.TickType.SYSTEM.getIndex()] - prevTicks[CentralProcessor.TickType.SYSTEM.getIndex()];
long idle = ticks[CentralProcessor.TickType.IDLE.getIndex()] - prevTicks[CentralProcessor.TickType.IDLE.getIndex()];
long iowait = ticks[CentralProcessor.TickType.IOWAIT.getIndex()] - prevTicks[CentralProcessor.TickType.IOWAIT.getIndex()];
long irq = ticks[CentralProcessor.TickType.IRQ.getIndex()] - prevTicks[CentralProcessor.TickType.IRQ.getIndex()];
long softirq = ticks[CentralProcessor.TickType.SOFTIRQ.getIndex()] - prevTicks[CentralProcessor.TickType.SOFTIRQ.getIndex()];
long steal = ticks[CentralProcessor.TickType.STEAL.getIndex()] - prevTicks[CentralProcessor.TickType.STEAL.getIndex()];
long totalCpu = user + nice + sys + idle + iowait + irq + softirq + steal;
ConsoleUtil.consoleOnly(textArea1, String.format(
"User: %.1f%% Nice: %.1f%% System: %.1f%% Idle: %.1f%% IOwait: %.1f%% IRQ: %.1f%% SoftIRQ: %.1f%% Steal: %.1f%%",
100d * user / totalCpu, 100d * nice / totalCpu, 100d * sys / totalCpu, 100d * idle / totalCpu,
100d * iowait / totalCpu, 100d * irq / totalCpu, 100d * softirq / totalCpu, 100d * steal / totalCpu));
ConsoleUtil.consoleOnly(textArea1, String.format("CPU load: %.1f%%", processor.getSystemCpuLoadBetweenTicks(prevTicks) * 100));
double[] loadAverage = processor.getSystemLoadAverage(3);
ConsoleUtil.consoleOnly(textArea1, "CPU load averages:" + (loadAverage[0] < 0 ? " N/A" : String.format(" %.2f", loadAverage[0]))
+ (loadAverage[1] < 0 ? " N/A" : String.format(" %.2f", loadAverage[1]))
+ (loadAverage[2] < 0 ? " N/A" : String.format(" %.2f", loadAverage[2])));
// per core CPU
StringBuilder procCpu = new StringBuilder("CPU load per processor:");
double[] load = processor.getProcessorCpuLoadBetweenTicks(prevProcTicks);
for (double avg : load) {
procCpu.append(String.format(" %.1f%%", avg * 100));
}
ConsoleUtil.consoleOnly(textArea1, procCpu.toString());
long freq = processor.getProcessorIdentifier().getVendorFreq();
if (freq > 0) {
ConsoleUtil.consoleOnly(textArea1, "Vendor Frequency: " + FormatUtil.formatHertz(freq));
}
freq = processor.getMaxFreq();
if (freq > 0) {
ConsoleUtil.consoleOnly(textArea1, "Max Frequency: " + FormatUtil.formatHertz(freq));
}
long[] freqs = processor.getCurrentFreq();
if (freqs[0] > 0) {
StringBuilder sb = new StringBuilder("Current Frequencies: ");
for (int i = 0; i < freqs.length; i++) {
if (i > 0) {
sb.append(", ");
}
sb.append(FormatUtil.formatHertz(freqs[i]));
}
ConsoleUtil.consoleOnly(textArea1, sb.toString());
}
}
private void printProcesses(OperatingSystem os, GlobalMemory memory) {
OSProcess myProc = os.getProcess(os.getProcessId());
// current process will never be null. Other code should check for null here
ConsoleUtil.consoleOnly(textArea1,
"My PID: " + myProc.getProcessID() + " with affinity " + Long.toBinaryString(myProc.getAffinityMask()));
ConsoleUtil.consoleOnly(textArea1, "Processes: " + os.getProcessCount() + ", Threads: " + os.getThreadCount());
// Sort by highest CPU
List<OSProcess> procs = os.getProcesses(OperatingSystem.ProcessFiltering.ALL_PROCESSES, OperatingSystem.ProcessSorting.CPU_DESC, 5);
ConsoleUtil.consoleOnly(textArea1, " PID %CPU %MEM VSZ RSS Name");
for (int i = 0; i < procs.size() && i < 5; i++) {
OSProcess p = procs.get(i);
ConsoleUtil.consoleOnly(textArea1, String.format(" %5d %5.1f %4.1f %9s %9s %s", p.getProcessID(),
100d * (p.getKernelTime() + p.getUserTime()) / p.getUpTime(),
100d * p.getResidentSetSize() / memory.getTotal(), FormatUtil.formatBytes(p.getVirtualSize()),
FormatUtil.formatBytes(p.getResidentSetSize()), p.getName()));
}
OSProcess p = os.getProcess(os.getProcessId());
ConsoleUtil.consoleOnly(textArea1, "Current process arguments: ");
for (String s : p.getArguments()) {
ConsoleUtil.consoleOnly(textArea1, " " + s);
}
ConsoleUtil.consoleOnly(textArea1, "Current process environment: ");
for (Map.Entry<String, String> e : p.getEnvironmentVariables().entrySet()) {
ConsoleUtil.consoleOnly(textArea1, " " + e.getKey() + "=" + e.getValue());
}
}
private void printServices(OperatingSystem os) {
ConsoleUtil.consoleOnly(textArea1, "Services: ");
ConsoleUtil.consoleOnly(textArea1, " PID State Name");
// DO 5 each of running and stopped
int i = 0;
for (OSService s : os.getServices()) {
if (s.getState().equals(OSService.State.RUNNING) && i++ < 5) {
ConsoleUtil.consoleOnly(textArea1, String.format(" %5d %7s %s", s.getProcessID(), s.getState(), s.getName()));
}
}
i = 0;
for (OSService s : os.getServices()) {
if (s.getState().equals(OSService.State.STOPPED) && i++ < 5) {
ConsoleUtil.consoleOnly(textArea1, String.format(" %5d %7s %s", s.getProcessID(), s.getState(), s.getName()));
}
}
}
private void printSensors(Sensors sensors) {
ConsoleUtil.consoleOnly(textArea1, "Sensors: " + sensors.toString());
}
private void printPowerSources(List<PowerSource> list) {
StringBuilder sb = new StringBuilder("Power Sources: ");
if (list.isEmpty()) {
sb.append("Unknown");
}
for (PowerSource powerSource : list) {
sb.append("\n ").append(powerSource.toString());
}
ConsoleUtil.consoleOnly(textArea1, sb.toString());
}
private void printDisks(List<HWDiskStore> list) {
ConsoleUtil.consoleOnly(textArea1, "Disks:");
for (HWDiskStore disk : list) {
ConsoleUtil.consoleOnly(textArea1, " " + disk.toString());
List<HWPartition> partitions = disk.getPartitions();
for (HWPartition part : partitions) {
ConsoleUtil.consoleOnly(textArea1, " |-- " + part.toString());
}
}
}
private void printLVgroups(List<LogicalVolumeGroup> list) {
if (!list.isEmpty()) {
ConsoleUtil.consoleOnly(textArea1, "Logical Volume Groups:");
for (LogicalVolumeGroup lvg : list) {
ConsoleUtil.consoleOnly(textArea1, " " + lvg.toString());
}
}
}
private void printFileSystem(FileSystem fileSystem) {
ConsoleUtil.consoleOnly(textArea1, "File System:");
ConsoleUtil.consoleOnly(textArea1, String.format(" File Descriptors: %d/%d", fileSystem.getOpenFileDescriptors(),
fileSystem.getMaxFileDescriptors()));
for (OSFileStore fs : fileSystem.getFileStores()) {
long usable = fs.getUsableSpace();
long total = fs.getTotalSpace();
ConsoleUtil.consoleOnly(textArea1, String.format(
" %s (%s) [%s] %s of %s free (%.1f%%), %s of %s files free (%.1f%%) is %s "
+ (fs.getLogicalVolume() != null && fs.getLogicalVolume().length() > 0 ? "[%s]" : "%s")
+ " and is mounted at %s",
fs.getName(), fs.getDescription().isEmpty() ? "file system" : fs.getDescription(), fs.getType(),
FormatUtil.formatBytes(usable), FormatUtil.formatBytes(fs.getTotalSpace()), 100d * usable / total,
FormatUtil.formatValue(fs.getFreeInodes(), ""), FormatUtil.formatValue(fs.getTotalInodes(), ""),
100d * fs.getFreeInodes() / fs.getTotalInodes(), fs.getVolume(), fs.getLogicalVolume(),
fs.getMount()));
}
}
private void printNetworkInterfaces(List<NetworkIF> list) {
StringBuilder sb = new StringBuilder("Network Interfaces:");
if (list.isEmpty()) {
sb.append(" Unknown");
} else {
for (NetworkIF net : list) {
sb.append("\n ").append(net.toString());
}
}
ConsoleUtil.consoleOnly(textArea1, sb.toString());
}
private void printNetworkParameters(NetworkParams networkParams) {
ConsoleUtil.consoleOnly(textArea1, "Network parameters:\n " + networkParams.toString());
}
private void printInternetProtocolStats(InternetProtocolStats ip) {
ConsoleUtil.consoleOnly(textArea1, "Internet Protocol statistics:");
ConsoleUtil.consoleOnly(textArea1, " TCPv4: " + ip.getTCPv4Stats());
ConsoleUtil.consoleOnly(textArea1, " TCPv6: " + ip.getTCPv6Stats());
ConsoleUtil.consoleOnly(textArea1, " UDPv4: " + ip.getUDPv4Stats());
ConsoleUtil.consoleOnly(textArea1, " UDPv6: " + ip.getUDPv6Stats());
}
private void printDisplays(List<Display> list) {
ConsoleUtil.consoleOnly(textArea1, "Displays:");
int i = 0;
for (Display display : list) {
ConsoleUtil.consoleOnly(textArea1, " Display " + i + ":");
ConsoleUtil.consoleOnly(textArea1, String.valueOf(display));
i++;
}
}
private void printUsbDevices(List<UsbDevice> list) {
ConsoleUtil.consoleOnly(textArea1, "USB Devices:");
for (UsbDevice usbDevice : list) {
ConsoleUtil.consoleOnly(textArea1, String.valueOf(usbDevice));
}
}
private void printSoundCards(List<SoundCard> list) {
ConsoleUtil.consoleOnly(textArea1, "Sound Cards:");
for (SoundCard card : list) {
ConsoleUtil.consoleOnly(textArea1, " " + String.valueOf(card));
}
}
private void printGraphicsCards(List<GraphicsCard> list) {
ConsoleUtil.consoleOnly(textArea1, "Graphics Cards:");
if (list.isEmpty()) {
ConsoleUtil.consoleOnly(textArea1, " None detected.");
} else {
for (GraphicsCard card : list) {
ConsoleUtil.consoleOnly(textArea1, " " + String.valueOf(card));
}
}
}
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
/**
* Method generated by IntelliJ IDEA GUI Designer
* >>> IMPORTANT!! <<<
* DO NOT edit this method OR call it in your code!
*
* @noinspection ALL
*/
private void $$$setupUI$$$() {
contentPane = new JPanel();
contentPane.setLayout(new GridLayoutManager(2, 1, new Insets(10, 10, 10, 10), -1, -1));
final JPanel panel1 = new JPanel();
panel1.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
contentPane.add(panel1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, 1, null, null, null, 0, false));
final Spacer spacer1 = new Spacer();
panel1.add(spacer1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
final JPanel panel2 = new JPanel();
panel2.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1, true, false));
panel1.add(panel2, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
buttonOK = new JButton();
buttonOK.setText("Start");
panel2.add(buttonOK, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
buttonCancel = new JButton();
buttonCancel.setText("Cancel");
panel2.add(buttonCancel, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final JPanel panel3 = new JPanel();
panel3.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
contentPane.add(panel3, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
final JScrollPane scrollPane1 = new JScrollPane();
panel3.add(scrollPane1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
textArea1 = new JTextArea();
scrollPane1.setViewportView(textArea1);
}
/**
* @noinspection ALL
*/
public JComponent $$$getRootComponent$$$() {
return contentPane;
}
}

View File

@ -36,8 +36,8 @@
<properties/>
<border type="none"/>
<children>
<grid id="a9c92" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<grid id="a9c92" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="8" left="0" bottom="0" right="0"/>
<constraints/>
<properties/>
<border type="none"/>
@ -45,7 +45,7 @@
<grid id="3ad43" binding="scuPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
@ -69,7 +69,7 @@
<grid id="7a05a" binding="pcuPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
@ -96,7 +96,7 @@
<grid id="5e92c" binding="panel1" default-binding="true" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
@ -122,9 +122,18 @@
</grid>
<vspacer id="a377f">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<grid id="c1f1" binding="chartPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
</children>
</grid>
</children>

View File

@ -9,6 +9,11 @@ import com.luoboduner.moo.info.App;
import com.luoboduner.moo.info.ui.Style;
import com.luoboduner.moo.info.util.ScrollUtil;
import lombok.Getter;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.time.DynamicTimeSeriesCollection;
import org.jfree.data.time.Second;
import oshi.hardware.CentralProcessor;
import oshi.hardware.Sensors;
@ -17,8 +22,11 @@ import java.awt.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@ -53,6 +61,7 @@ public class CpuForm {
private JLabel voltageLabel;
private JLabel fanSpeedsLabel;
private JSplitPane splitPane;
private JPanel chartPanel;
private static final Log logger = LogFactory.get();
@ -65,6 +74,8 @@ public class CpuForm {
private static List<JProgressBar> processorProgressBars;
private static List<JTextField> processorTextFields;
private static DynamicTimeSeriesCollection sysData;
public static CpuForm getInstance() {
if (cpuForm == null) {
cpuForm = new CpuForm();
@ -143,6 +154,31 @@ public class CpuForm {
processorTextFields.add(textField);
}
// Codes bellow are copied from oshi demo.
Date date = Date.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant());
sysData = new DynamicTimeSeriesCollection(1, 60, new Second());
sysData.setTimeBase(new Second(date));
sysData.addSeries(floatArrayPercent(cpuData(cpu)), 0, "All cpus");
JFreeChart systemCpu = ChartFactory.createTimeSeriesChart(null, null, null, sysData, false,
true, false);
systemCpu.setBackgroundPaint(cpuForm.getChartPanel().getBackground());
systemCpu.setAntiAlias(true);
systemCpu.getXYPlot().setDomainGridlinesVisible(false);
systemCpu.getXYPlot().setRangeGridlinesVisible(false);
systemCpu.getXYPlot().setBackgroundPaint(cpuForm.getScuProgressBar().getBackground());
systemCpu.getXYPlot().setOutlinePaint(cpuForm.getScuProgressBar().getBackground());
systemCpu.getXYPlot().getRenderer().setSeriesPaint(0, cpuForm.getScuProgressBar().getForeground());
systemCpu.getXYPlot().getRenderer().setSeriesStroke(0, new BasicStroke(2f));
systemCpu.getXYPlot().getDomainAxis().setVisible(false);
systemCpu.getXYPlot().getRangeAxis().setVisible(false);
cpuForm.getChartPanel().setPreferredSize(new Dimension(-1, 100));
cpuForm.getChartPanel().setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
cpuForm.getChartPanel().add(new ChartPanel(systemCpu), new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_WANT_GROW, null, new Dimension(150, 50), null, 0, false));
}
private static void initCpuInfo() {
@ -200,6 +236,9 @@ public class CpuForm {
long steal = ticks[CentralProcessor.TickType.STEAL.getIndex()] - prevTicks[CentralProcessor.TickType.STEAL.getIndex()];
long totalCpu = Math.max(user + nice + cSys + idle + ioWait + irq + softIrq + steal, 0);
sysData.advanceTime();
sysData.appendData(floatArrayPercent(cpuData(processor)));
prevTicks = ticks;
double free = Double.parseDouble(format.format(idle <= 0 ? 0 : (100d * idle / totalCpu)));
@ -291,6 +330,32 @@ public class CpuForm {
cpuForm.getFanSpeedsLabel().setText(Arrays.toString(sensors.getFanSpeeds()));
}
/**
* Codes are copied from oshi demo.
*
* @param d
* @return
*/
private static float[] floatArrayPercent(double d) {
float[] f = new float[1];
f[0] = (float) (100d * d);
return f;
}
/**
* Codes are copied from oshi demo.
*
* @param proc
* @return
*/
private static double cpuData(CentralProcessor proc) {
if (prevTicks == null) {
return 0;
}
double d = proc.getSystemCpuLoadBetweenTicks(prevTicks);
return d;
}
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
@ -319,11 +384,11 @@ public class CpuForm {
scrollPaneLeft = new JScrollPane();
panel2.add(scrollPaneLeft, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
final JPanel panel3 = new JPanel();
panel3.setLayout(new GridLayoutManager(4, 1, new Insets(0, 0, 0, 0), -1, -1));
panel3.setLayout(new GridLayoutManager(5, 1, new Insets(8, 0, 0, 0), -1, -1));
scrollPaneLeft.setViewportView(panel3);
scuPanel = new JPanel();
scuPanel.setLayout(new GridLayoutManager(2, 1, new Insets(10, 10, 10, 10), -1, -1));
panel3.add(scuPanel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
panel3.add(scuPanel, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
scuTitleLabel = new JLabel();
scuTitleLabel.setText("System CPU Usage");
scuPanel.add(scuTitleLabel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
@ -331,7 +396,7 @@ public class CpuForm {
scuPanel.add(scuProgressBar, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
pcuPanel = new JPanel();
pcuPanel.setLayout(new GridLayoutManager(2, 1, new Insets(10, 10, 10, 10), -1, -1));
panel3.add(pcuPanel, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
panel3.add(pcuPanel, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
pcuTitleLabel = new JLabel();
pcuTitleLabel.setText("Processor CPU Usage");
pcuPanel.add(pcuTitleLabel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
@ -340,7 +405,7 @@ public class CpuForm {
pcuPanel.add(pcuProgressBarPanel, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
panel1 = new JPanel();
panel1.setLayout(new GridLayoutManager(2, 1, new Insets(10, 10, 10, 10), -1, -1));
panel3.add(panel1, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
panel3.add(panel1, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
pcfLabel = new JLabel();
pcfLabel.setText("Processor CPU Frequency");
panel1.add(pcfLabel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
@ -348,7 +413,10 @@ public class CpuForm {
pcfPanel.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
panel1.add(pcfPanel, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
final Spacer spacer1 = new Spacer();
panel3.add(spacer1, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
panel3.add(spacer1, new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
chartPanel = new JPanel();
chartPanel.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
panel3.add(chartPanel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
final JPanel panel4 = new JPanel();
panel4.setLayout(new GridLayoutManager(3, 1, new Insets(10, 0, 10, 10), -1, -1));
splitPane.setRightComponent(panel4);

View File

@ -9,8 +9,10 @@ import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
import com.luoboduner.moo.info.App;
import com.luoboduner.moo.info.ui.Style;
import com.luoboduner.moo.info.util.DateTimeUtil;
import com.luoboduner.moo.info.util.ScrollUtil;
import lombok.Getter;
import org.apache.commons.lang3.time.DateFormatUtils;
import oshi.hardware.*;
import oshi.software.os.NetworkParams;
import oshi.software.os.OperatingSystem;
@ -146,8 +148,8 @@ public class DetailForm {
builder.append("<br/><b>Open File Descriptors: </b>").append(operatingSystem.getFileSystem().getOpenFileDescriptors());
builder.append("<br/><b>Thread Count: </b>").append(operatingSystem.getThreadCount());
builder.append("<br/><b>Process Count: </b>").append(operatingSystem.getProcessCount());
builder.append("<br/><b>System Boot Time: </b>").append(operatingSystem.getSystemBootTime());
builder.append("<br/><b>System Uptime: </b>").append(operatingSystem.getSystemUptime());
builder.append("<br/><b>System Boot Time: </b>").append(DateFormatUtils.format(operatingSystem.getSystemBootTime() * 1000, "yyyy-MM-dd HH:mm:ss"));
builder.append("<br/><b>System Uptime: </b>").append(DateTimeUtil.toReadableTime(operatingSystem.getSystemUptime()));
return builder.toString();
}

View File

@ -1,16 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.luoboduner.moo.info.ui.form.ProcessesForm">
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="20" left="20" bottom="20" right="20"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
<xy x="20" y="20" width="760" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<scrollpane id="306d1">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
@ -21,6 +21,77 @@
</component>
</children>
</scrollpane>
<grid id="b5aed" layout-manager="GridLayoutManager" row-count="1" column-count="8" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="10" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="1fce3" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Sort by: "/>
</properties>
</component>
<hspacer id="496f9">
<constraints>
<grid row="0" column="4" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="d0b3e" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="CPU %: "/>
</properties>
</component>
<component id="23441" class="javax.swing.JRadioButton" binding="cpuButton">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="CPU %"/>
</properties>
</component>
<component id="a05b5" class="javax.swing.JRadioButton" binding="cumulativeCpuButton">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Cumulative CPU"/>
</properties>
</component>
<component id="5b233" class="javax.swing.JRadioButton" binding="memButton">
<constraints>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Memory %"/>
</properties>
</component>
<component id="a334" class="javax.swing.JRadioButton" binding="perProc">
<constraints>
<grid row="0" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="of one Processor"/>
</properties>
</component>
<component id="e33d0" class="javax.swing.JRadioButton" binding="perSystem">
<constraints>
<grid row="0" column="7" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="of System"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</form>

View File

@ -4,6 +4,7 @@ import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
import com.luoboduner.moo.info.App;
import com.luoboduner.moo.info.ui.UiConsts;
import lombok.Getter;
@ -40,6 +41,11 @@ public class ProcessesForm {
private static ProcessesForm processesForm;
private JPanel mainPanel;
private JTable processTable;
private JRadioButton cpuButton;
private JRadioButton cumulativeCpuButton;
private JRadioButton memButton;
private JRadioButton perProc;
private JRadioButton perSystem;
public static ProcessesForm getInstance() {
if (processesForm == null) {
@ -56,6 +62,38 @@ public class ProcessesForm {
}
private static void initUi() {
resetCpuPercentButtonGroup();
resetSortByButtonGroup();
processesForm = getInstance();
if (SystemInfo.getCurrentPlatform().equals(PlatformEnum.WINDOWS)) {
processesForm.perSystem.setSelected(true);
} else {
processesForm.perProc.setSelected(true);
}
processesForm.cpuButton.setSelected(true);
processesForm.perProc.addActionListener(e -> {
resetCpuPercentButtonGroup();
processesForm.perProc.setSelected(true);
});
processesForm.perSystem.addActionListener(e -> {
resetCpuPercentButtonGroup();
processesForm.perSystem.setSelected(true);
});
processesForm.cpuButton.addActionListener(e -> {
resetSortByButtonGroup();
processesForm.cpuButton.setSelected(true);
});
processesForm.cumulativeCpuButton.addActionListener(e -> {
resetSortByButtonGroup();
processesForm.cumulativeCpuButton.setSelected(true);
});
processesForm.memButton.addActionListener(e -> {
resetSortByButtonGroup();
processesForm.memButton.setSelected(true);
});
}
/**
@ -105,6 +143,7 @@ public class ProcessesForm {
* @return
*/
private static Object[][] parseProcesses(List<OSProcess> list, SystemInfo si) {
processesForm = getInstance();
long totalMem = si.getHardware().getMemory().getTotal();
int cpuCount = si.getHardware().getProcessor().getLogicalProcessorCount();
// Build a map with a value for each process to control the sort
@ -114,7 +153,13 @@ public class ProcessesForm {
// Ignore the Idle process on Windows
if (pid > 0 || !SystemInfo.getCurrentPlatform().equals(PlatformEnum.WINDOWS)) {
// Set up for appropriate sort
processSortValueMap.put(p, (double) p.getResidentSetSize());
if (processesForm.cpuButton.isSelected()) {
processSortValueMap.put(p, p.getProcessCpuLoadBetweenTicks(priorSnapshotMap.get(pid)));
} else if (processesForm.cumulativeCpuButton.isSelected()) {
processSortValueMap.put(p, p.getProcessCpuLoadCumulative());
} else {
processSortValueMap.put(p, (double) p.getResidentSetSize());
}
}
}
// Now sort the list by the values
@ -132,7 +177,11 @@ public class ProcessesForm {
procArr[i][0] = pid;
procArr[i][1] = p.getParentProcessID();
procArr[i][2] = p.getThreadCount();
{
if (processesForm.perProc.isSelected()) {
procArr[i][3] = String.format("%.1f",
100d * p.getProcessCpuLoadBetweenTicks(priorSnapshotMap.get(pid)) / cpuCount);
procArr[i][4] = String.format("%.1f", 100d * p.getProcessCpuLoadCumulative() / cpuCount);
} else {
procArr[i][3] = String.format("%.1f",
100d * p.getProcessCpuLoadBetweenTicks(priorSnapshotMap.get(pid)));
procArr[i][4] = String.format("%.1f", 100d * p.getProcessCpuLoadCumulative());
@ -166,6 +215,21 @@ public class ProcessesForm {
}
}
private static void resetSortByButtonGroup() {
processesForm = getInstance();
processesForm.cpuButton.setSelected(false);
processesForm.cumulativeCpuButton.setSelected(false);
processesForm.memButton.setSelected(false);
}
private static void resetCpuPercentButtonGroup() {
processesForm = getInstance();
processesForm.perProc.setSelected(false);
processesForm.perSystem.setSelected(false);
}
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
@ -182,11 +246,37 @@ public class ProcessesForm {
*/
private void $$$setupUI$$$() {
mainPanel = new JPanel();
mainPanel.setLayout(new GridLayoutManager(1, 1, new Insets(20, 20, 20, 20), -1, -1));
mainPanel.setLayout(new GridLayoutManager(2, 1, new Insets(20, 20, 20, 20), -1, -1));
final JScrollPane scrollPane1 = new JScrollPane();
mainPanel.add(scrollPane1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
mainPanel.add(scrollPane1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
processTable = new JTable();
scrollPane1.setViewportView(processTable);
final JPanel panel1 = new JPanel();
panel1.setLayout(new GridLayoutManager(1, 8, new Insets(0, 0, 10, 0), -1, -1));
mainPanel.add(panel1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
final JLabel label1 = new JLabel();
label1.setText("Sort by: ");
panel1.add(label1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final Spacer spacer1 = new Spacer();
panel1.add(spacer1, new GridConstraints(0, 4, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
final JLabel label2 = new JLabel();
label2.setText("CPU %: ");
panel1.add(label2, new GridConstraints(0, 5, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
cpuButton = new JRadioButton();
cpuButton.setText("CPU %");
panel1.add(cpuButton, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
cumulativeCpuButton = new JRadioButton();
cumulativeCpuButton.setText("Cumulative CPU");
panel1.add(cumulativeCpuButton, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
memButton = new JRadioButton();
memButton.setText("Memory %");
panel1.add(memButton, new GridConstraints(0, 3, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
perProc = new JRadioButton();
perProc.setText("of one Processor");
panel1.add(perProc, new GridConstraints(0, 6, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
perSystem = new JRadioButton();
perSystem.setText("of System");
panel1.add(perSystem, new GridConstraints(0, 7, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
}
/**

View File

@ -0,0 +1,36 @@
package com.luoboduner.moo.info.util;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import javax.swing.*;
import java.util.Date;
/**
* <pre>
* ConsoleUtil to print text into textarea
* </pre>
*
* @author <a href="https://github.com/rememberber">RememBerBer</a>
* @since 2021/12/15.
*/
@Slf4j
public class ConsoleUtil {
private static final Log logger = LogFactory.get();
public static void consoleWithLog(JTextArea textArea, String log) {
textArea.append(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS") + " ");
textArea.append(log + "\n");
textArea.setCaretPosition(textArea.getText().length());
logger.warn(log);
}
public static void consoleOnly(JTextArea textArea, String log) {
textArea.append(log + "\n");
textArea.setCaretPosition(textArea.getText().length());
}
}

View File

@ -0,0 +1,14 @@
package com.luoboduner.moo.info.util;
public class DateTimeUtil {
public static String toReadableTime(long seconds) {
String readableTime;
int hours = (int) (seconds / 3600);
int minutes = (int) (seconds % 3600 / 60);
readableTime = String.format("%dh:%02dmin", hours, minutes);
return readableTime;
}
}

View File

@ -13,6 +13,11 @@
<encoder>
<pattern>%date{HH:mm:ss.SSS} [%thread] %-5level %logger{36} :%line - %msg%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<root level="INFO">

View File

@ -1,8 +1,9 @@
{
"currentVersion": "1.0.0",
"currentVersion": "1.1.0",
"versionIndex": {
"0.0.0": "0",
"1.0.0": "1"
"1.0.0": "1",
"1.1.0": "2"
},
"versionDetailList": [
{
@ -14,6 +15,11 @@
"version": "1.0.0",
"title": "The first version",
"log": "The first version\n"
},
{
"version": "1.1.0",
"title": "Some minor features and optimizations",
"log": "● update oshi-core to 5.8.6\n● update flatlaf to 2.0-rc1(Support Windows 11 snap layouts menu, macOS screen menu optimization)\n● processes sort method added same as the oshi's demo\n● add cpu usage chart\n● make System Boot Time and Uptime readable\n● add System Info Test function menu same as oshi-core\n"
}
]
}