-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShowJvmProperties.java
More file actions
61 lines (45 loc) · 2.14 KB
/
ShowJvmProperties.java
File metadata and controls
61 lines (45 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.lang.management.OperatingSystemMXBean;
import java.util.Map;
import java.util.Properties;
public class ShowJvmProperties {
public static void main(String[] args) {
Properties properties = System.getProperties();
// for (Map.Entry entry : properties.entrySet()) {
// System.out.println(entry.getKey() + " " + entry.getValue());
// }
//
// properties.forEach((key, value) -> System.out.println(key + "\t" + value));
// outputEnv();
// outputSystemMemory();
// outputMemoryFromMXBean();
outputOperatingSystemInfo();
}
private static void outputEnv() {
Map<String, String> env = System.getenv();
env.forEach((key, value) -> System.out.println(key + "\t" + value));
}
private static void outputSystemMemory() {
Runtime runtime = Runtime.getRuntime();
long freeMemory = runtime.freeMemory();
long maxMemory = runtime.maxMemory();
long totalMemory = runtime.totalMemory();
System.out.println("Memory: free " + freeMemory + "\tmax\t" + maxMemory + "\ttotal\t" + totalMemory);
}
private static void outputMemoryFromMXBean() {
MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
System.out.println("Heap memory usage " + ((MemoryMXBean) memoryMXBean).getHeapMemoryUsage());
}
private static void outputOperatingSystemInfo() {
OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
String name = operatingSystemMXBean.getName();
String version = operatingSystemMXBean.getVersion();
String arch = operatingSystemMXBean.getArch();
int availableProcessors = operatingSystemMXBean.getAvailableProcessors();
double systemLoadAverage = operatingSystemMXBean.getSystemLoadAverage();
System.out.println("OS: " + name + " " + version);
System.out.println("Architecture: " + arch + " processors: " + availableProcessors);
System.out.println("Current load average: " + systemLoadAverage);
}
}