19
19
20
20
package org .elasticsearch .monitor .jvm ;
21
21
22
- import org .elasticsearch .util .SizeValue ;
23
22
import org .elasticsearch .util .io .stream .StreamInput ;
24
23
import org .elasticsearch .util .io .stream .StreamOutput ;
25
24
import org .elasticsearch .util .io .stream .Streamable ;
@@ -52,64 +51,50 @@ public class JvmInfo implements Streamable, Serializable {
52
51
} catch (Exception e ) {
53
52
pid = -1 ;
54
53
}
55
- INSTANCE = new JvmInfo (pid , runtimeMXBean .getVmName (), System .getProperty ("java.version" ), System .getProperty ("java.vendor" ),
56
- runtimeMXBean .getStartTime (),
57
- memoryMXBean .getHeapMemoryUsage ().getInit (), memoryMXBean .getHeapMemoryUsage ().getMax (),
58
- memoryMXBean .getNonHeapMemoryUsage ().getInit (), memoryMXBean .getNonHeapMemoryUsage ().getMax (),
59
- runtimeMXBean .getInputArguments ().toArray (new String [runtimeMXBean .getInputArguments ().size ()]), runtimeMXBean .getBootClassPath (), runtimeMXBean .getClassPath (), runtimeMXBean .getSystemProperties ());
54
+ JvmInfo info = new JvmInfo ();
55
+ info .pid = pid ;
56
+ info .startTime = runtimeMXBean .getStartTime ();
57
+ info .vmName = runtimeMXBean .getVmName ();
58
+ info .vmVendor = runtimeMXBean .getVmVendor ();
59
+ info .vmVersion = runtimeMXBean .getVmVersion ();
60
+ info .mem = new Mem ();
61
+ info .mem .heapInit = memoryMXBean .getHeapMemoryUsage ().getInit ();
62
+ info .mem .heapMax = memoryMXBean .getHeapMemoryUsage ().getMax ();
63
+ info .mem .nonHeapInit = memoryMXBean .getNonHeapMemoryUsage ().getInit ();
64
+ info .mem .nonHeapMax = memoryMXBean .getNonHeapMemoryUsage ().getMax ();
65
+ info .inputArguments = runtimeMXBean .getInputArguments ().toArray (new String [runtimeMXBean .getInputArguments ().size ()]);
66
+ info .bootClassPath = runtimeMXBean .getBootClassPath ();
67
+ info .classPath = runtimeMXBean .getClassPath ();
68
+ info .systemProperties = runtimeMXBean .getSystemProperties ();
69
+
70
+ INSTANCE = info ;
60
71
}
61
72
62
73
public static JvmInfo jvmInfo () {
63
74
return INSTANCE ;
64
75
}
65
76
66
- private long pid = -1 ;
77
+ long pid = -1 ;
67
78
68
- private String vmName = "" ;
79
+ String vmName = "" ;
80
+ String vmVersion = "" ;
81
+ String vmVendor = "" ;
69
82
70
- private String vmVersion = "" ;
83
+ long startTime = - 1 ;
71
84
72
- private String vmVendor = "" ;
85
+ Mem mem ;
73
86
74
- private long startTime = - 1 ;
87
+ String [] inputArguments ;
75
88
76
- private long memoryHeapInit = - 1 ;
89
+ String bootClassPath ;
77
90
78
- private long memoryHeapMax = - 1 ;
91
+ String classPath ;
79
92
80
- private long memoryNonHeapInit = -1 ;
81
-
82
- private long memoryNonHeapMax = -1 ;
83
-
84
- private String [] inputArguments ;
85
-
86
- private String bootClassPath ;
87
-
88
- private String classPath ;
89
-
90
- private Map <String , String > systemProperties ;
93
+ Map <String , String > systemProperties ;
91
94
92
95
private JvmInfo () {
93
96
}
94
97
95
- public JvmInfo (long pid , String vmName , String vmVersion , String vmVendor , long startTime ,
96
- long memoryHeapInit , long memoryHeapMax , long memoryNonHeapInit , long memoryNonHeapMax ,
97
- String [] inputArguments , String bootClassPath , String classPath , Map <String , String > systemProperties ) {
98
- this .pid = pid ;
99
- this .vmName = vmName ;
100
- this .vmVersion = vmVersion ;
101
- this .vmVendor = vmVendor ;
102
- this .startTime = startTime ;
103
- this .memoryHeapInit = memoryHeapInit ;
104
- this .memoryHeapMax = memoryHeapMax ;
105
- this .memoryNonHeapInit = memoryNonHeapInit ;
106
- this .memoryNonHeapMax = memoryNonHeapMax ;
107
- this .inputArguments = inputArguments ;
108
- this .bootClassPath = bootClassPath ;
109
- this .classPath = classPath ;
110
- this .systemProperties = systemProperties ;
111
- }
112
-
113
98
/**
114
99
* The process id.
115
100
*/
@@ -156,36 +141,12 @@ public long getStartTime() {
156
141
return startTime ;
157
142
}
158
143
159
- public SizeValue memoryHeapInit () {
160
- return new SizeValue (memoryHeapInit );
161
- }
162
-
163
- public SizeValue getMemoryHeapInit () {
164
- return memoryHeapInit ();
165
- }
166
-
167
- public SizeValue memoryHeapMax () {
168
- return new SizeValue (memoryHeapMax );
169
- }
170
-
171
- public SizeValue getMemoryHeapMax () {
172
- return memoryHeapMax ();
173
- }
174
-
175
- public SizeValue memoryNonHeapInit () {
176
- return new SizeValue (memoryNonHeapInit );
144
+ public Mem mem () {
145
+ return mem ;
177
146
}
178
147
179
- public SizeValue getMemoryNonHeapInit () {
180
- return memoryNonHeapInit ();
181
- }
182
-
183
- public SizeValue memoryNonHeapMax () {
184
- return new SizeValue (memoryNonHeapMax );
185
- }
186
-
187
- public SizeValue getMemoryNonHeapMax () {
188
- return memoryNonHeapMax ();
148
+ public Mem getMem () {
149
+ return mem ();
189
150
}
190
151
191
152
public String [] inputArguments () {
@@ -232,10 +193,6 @@ public static JvmInfo readJvmInfo(StreamInput in) throws IOException {
232
193
vmVersion = in .readUTF ();
233
194
vmVendor = in .readUTF ();
234
195
startTime = in .readLong ();
235
- memoryHeapInit = in .readLong ();
236
- memoryHeapMax = in .readLong ();
237
- memoryNonHeapInit = in .readLong ();
238
- memoryNonHeapMax = in .readLong ();
239
196
inputArguments = new String [in .readInt ()];
240
197
for (int i = 0 ; i < inputArguments .length ; i ++) {
241
198
inputArguments [i ] = in .readUTF ();
@@ -255,10 +212,6 @@ public static JvmInfo readJvmInfo(StreamInput in) throws IOException {
255
212
out .writeUTF (vmVersion );
256
213
out .writeUTF (vmVendor );
257
214
out .writeLong (startTime );
258
- out .writeLong (memoryHeapInit );
259
- out .writeLong (memoryHeapMax );
260
- out .writeLong (memoryNonHeapInit );
261
- out .writeLong (memoryNonHeapMax );
262
215
out .writeInt (inputArguments .length );
263
216
for (String inputArgument : inputArguments ) {
264
217
out .writeUTF (inputArgument );
@@ -271,4 +224,35 @@ public static JvmInfo readJvmInfo(StreamInput in) throws IOException {
271
224
out .writeUTF (entry .getValue ());
272
225
}
273
226
}
227
+
228
+ public static class Mem implements Streamable , Serializable {
229
+
230
+ long heapInit = -1 ;
231
+ long heapMax = -1 ;
232
+ long nonHeapInit = -1 ;
233
+ long nonHeapMax = -1 ;
234
+
235
+ Mem () {
236
+ }
237
+
238
+ public static Mem readMem (StreamInput in ) throws IOException {
239
+ Mem mem = new Mem ();
240
+ mem .readFrom (in );
241
+ return mem ;
242
+ }
243
+
244
+ @ Override public void readFrom (StreamInput in ) throws IOException {
245
+ heapInit = in .readVLong ();
246
+ heapMax = in .readVLong ();
247
+ nonHeapInit = in .readVLong ();
248
+ nonHeapMax = in .readVLong ();
249
+ }
250
+
251
+ @ Override public void writeTo (StreamOutput out ) throws IOException {
252
+ out .writeVLong (heapInit );
253
+ out .writeVLong (heapMax );
254
+ out .writeVLong (nonHeapInit );
255
+ out .writeVLong (nonHeapMax );
256
+ }
257
+ }
274
258
}
0 commit comments