Skip to content

Commit e9e295e

Browse files
committed
[FEATURE] systeminfo
Fixes #82
1 parent 16c762d commit e9e295e

File tree

3 files changed

+77
-4
lines changed

3 files changed

+77
-4
lines changed

CheckList.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
---
88

99
## 🧭 System Information & Management
10-
- [ ] systeminfo
10+
- [x] systeminfo
1111
- [x] hostname
1212
- [x] ver
1313
- [ ] vol

src/main/java/com/mycmd/App.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ private static void registerCommands(Map<String, Command> commands) {
106106
commands.put("unalias", new UnaliasCommand());
107107
commands.put("rename", new RenameCommand());
108108
commands.put("set", new SetCommand());
109-
}
109+
commands.put("systeminfo", new SysteminfoCommand());
110+
}
110111
}
111-
112-
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.mycmd.commands;
2+
3+
import com.mycmd.Command;
4+
import com.mycmd.ShellContext;
5+
import java.lang.management.ManagementFactory;
6+
import java.lang.management.OperatingSystemMXBean;
7+
import java.net.InetAddress;
8+
import java.net.UnknownHostException;
9+
import java.text.NumberFormat;
10+
import java.text.SimpleDateFormat;
11+
import java.util.Date;
12+
import java.util.TimeZone;
13+
14+
public class SysteminfoCommand implements Command {
15+
@Override
16+
public void execute(String[] args, ShellContext context) {
17+
OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
18+
NumberFormat nf = NumberFormat.getInstance();
19+
Runtime rt = Runtime.getRuntime();
20+
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
21+
sdf.setTimeZone(TimeZone.getDefault());
22+
23+
String hostname;
24+
try {
25+
hostname = InetAddress.getLocalHost().getHostName();
26+
} catch (UnknownHostException e) {
27+
hostname = System.getenv("COMPUTERNAME");
28+
if (hostname == null) hostname = System.getenv("HOSTNAME");
29+
if (hostname == null) hostname = "Unknown";
30+
}
31+
32+
long uptime = ManagementFactory.getRuntimeMXBean().getUptime();
33+
long bootTimeMillis = System.currentTimeMillis() - uptime;
34+
long maxMem = rt.maxMemory();
35+
long totalMem = rt.totalMemory();
36+
long freeMem = rt.freeMemory();
37+
long usedMem = totalMem - freeMem;
38+
39+
System.out.println();
40+
System.out.println("Host Name: " + hostname);
41+
System.out.println("OS Name: " + System.getProperty("os.name"));
42+
System.out.println("OS Version: " + System.getProperty("os.version"));
43+
System.out.println("Architecture: " + System.getProperty("os.arch"));
44+
System.out.println("User Name: " + System.getProperty("user.name"));
45+
System.out.println("Java Vendor: " + System.getProperty("java.vendor"));
46+
System.out.println("Java VM: " + System.getProperty("java.vm.name"));
47+
System.out.println("Available Processors: " + osBean.getAvailableProcessors());
48+
System.out.println("JVM Boot Time: " + sdf.format(new Date(bootTimeMillis)));
49+
System.out.println("User Language: " + System.getProperty("user.language"));
50+
System.out.println("User Country: " + System.getProperty("user.country"));
51+
System.out.println("Home Directory: " + System.getProperty("user.home"));
52+
System.out.println();
53+
System.out.println("JVM Memory (Heap):");
54+
System.out.println(" Total: " + nf.format(totalMem / (1024 * 1024)) + " MB");
55+
System.out.println(" Used: " + nf.format(usedMem / (1024 * 1024)) + " MB");
56+
System.out.println(" Free: " + nf.format(freeMem / (1024 * 1024)) + " MB");
57+
System.out.println(
58+
" Max: "
59+
+ (maxMem == Long.MAX_VALUE
60+
? "No Limit"
61+
: nf.format(maxMem / (1024 * 1024)) + " MB"));
62+
System.out.println();
63+
}
64+
65+
@Override
66+
public String description() {
67+
return "Displays system and JVM information.";
68+
}
69+
70+
@Override
71+
public String usage() {
72+
return "systeminfo";
73+
}
74+
}

0 commit comments

Comments
 (0)