-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProbe.java
More file actions
105 lines (79 loc) · 3.2 KB
/
Probe.java
File metadata and controls
105 lines (79 loc) · 3.2 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import java.io.File;
public class Probe {
public static class probe {
long curTimeMs;
int coreNum;
long freeMemory;
String maxMemory;
long totalMemoryForJVM;
String fileSystemRoot;
String totalSpace;
long freeSpace;
long usableSpace;
String osName;
String osVersion;
String osArch;
probe() {
coreNum = Runtime.getRuntime().availableProcessors();
freeMemory = Runtime.getRuntime().freeMemory();
maxMemory = Runtime.getRuntime().maxMemory() == Long.MAX_VALUE ? "no limit" : maxMemory;
totalMemoryForJVM = Runtime.getRuntime().totalMemory();
File[] roots = File.listRoots();
for (File root : roots) {
fileSystemRoot = root.getAbsolutePath();
totalSpace = root.getAbsolutePath();
freeSpace = root.getTotalSpace();
usableSpace = root.getUsableSpace();
}
String nameOS = "os.name";
String versionOS = "os.version";
String architectureOS = "os.arch";
osName = System.getProperty(nameOS);
osVersion = System.getProperty(versionOS);
osArch = System.getProperty(architectureOS);
curTimeMs = System.currentTimeMillis();
}
probe update() {
return new probe();
}
void print() {
long curTimeMs = System.currentTimeMillis();
System.out.println("curTimeMs: " + curTimeMs + " ms");
/* Total number of processors or cores available to the JVM */
System.out.println("Available processors (cores): "
+ Runtime.getRuntime().availableProcessors());
/* Total amount of free memory available to the JVM */
System.out.println("Free memory (bytes): " + Runtime.getRuntime().freeMemory());
/* This will return Long.MAX_VALUE if there is no preset limit */
long maxMemory = Runtime.getRuntime().maxMemory();
/* Maximum amount of memory the JVM will attempt to use */
System.out.println("Maximum memory (bytes): "
+ (maxMemory == Long.MAX_VALUE ? "no limit" : maxMemory));
/* Total memory currently available to the JVM */
System.out.println("Total memory available to JVM (bytes): "
+ Runtime.getRuntime().totalMemory());
/* Get a list of all filesystem roots on this system */
File[] roots = File.listRoots();
/* For each filesystem root, print some info */
for (File root : roots) {
System.out.println("File system root: " + root.getAbsolutePath());
System.out.println("Total space (bytes): " + root.getTotalSpace());
System.out.println("Free space (bytes): " + root.getFreeSpace());
System.out.println("Usable space (bytes): " + root.getUsableSpace());
}
String nameOS = "os.name";
String versionOS = "os.version";
String architectureOS = "os.arch";
System.out.println("\n The information about OS");
System.out.println("\nName of the OS: " + System.getProperty(nameOS));
System.out.println("Version of the OS: " + System.getProperty(versionOS));
System.out.println("Architecture of THe OS: " + System.getProperty(architectureOS));
}
}
public static void main(String[] args) {
probe p = new probe();
p.print();
p = p.update();
p.print();
}
}