Skip to content

Commit e222d38

Browse files
committed
more work on monitoring support
1 parent 4ed93d2 commit e222d38

File tree

3 files changed

+298
-184
lines changed

3 files changed

+298
-184
lines changed

modules/elasticsearch/src/main/java/org/elasticsearch/monitor/jvm/JvmInfo.java

Lines changed: 62 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
package org.elasticsearch.monitor.jvm;
2121

22-
import org.elasticsearch.util.SizeValue;
2322
import org.elasticsearch.util.io.stream.StreamInput;
2423
import org.elasticsearch.util.io.stream.StreamOutput;
2524
import org.elasticsearch.util.io.stream.Streamable;
@@ -52,64 +51,50 @@ public class JvmInfo implements Streamable, Serializable {
5251
} catch (Exception e) {
5352
pid = -1;
5453
}
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;
6071
}
6172

6273
public static JvmInfo jvmInfo() {
6374
return INSTANCE;
6475
}
6576

66-
private long pid = -1;
77+
long pid = -1;
6778

68-
private String vmName = "";
79+
String vmName = "";
80+
String vmVersion = "";
81+
String vmVendor = "";
6982

70-
private String vmVersion = "";
83+
long startTime = -1;
7184

72-
private String vmVendor = "";
85+
Mem mem;
7386

74-
private long startTime = -1;
87+
String[] inputArguments;
7588

76-
private long memoryHeapInit = -1;
89+
String bootClassPath;
7790

78-
private long memoryHeapMax = -1;
91+
String classPath;
7992

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;
9194

9295
private JvmInfo() {
9396
}
9497

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-
11398
/**
11499
* The process id.
115100
*/
@@ -156,36 +141,12 @@ public long getStartTime() {
156141
return startTime;
157142
}
158143

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;
177146
}
178147

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();
189150
}
190151

191152
public String[] inputArguments() {
@@ -232,10 +193,6 @@ public static JvmInfo readJvmInfo(StreamInput in) throws IOException {
232193
vmVersion = in.readUTF();
233194
vmVendor = in.readUTF();
234195
startTime = in.readLong();
235-
memoryHeapInit = in.readLong();
236-
memoryHeapMax = in.readLong();
237-
memoryNonHeapInit = in.readLong();
238-
memoryNonHeapMax = in.readLong();
239196
inputArguments = new String[in.readInt()];
240197
for (int i = 0; i < inputArguments.length; i++) {
241198
inputArguments[i] = in.readUTF();
@@ -255,10 +212,6 @@ public static JvmInfo readJvmInfo(StreamInput in) throws IOException {
255212
out.writeUTF(vmVersion);
256213
out.writeUTF(vmVendor);
257214
out.writeLong(startTime);
258-
out.writeLong(memoryHeapInit);
259-
out.writeLong(memoryHeapMax);
260-
out.writeLong(memoryNonHeapInit);
261-
out.writeLong(memoryNonHeapMax);
262215
out.writeInt(inputArguments.length);
263216
for (String inputArgument : inputArguments) {
264217
out.writeUTF(inputArgument);
@@ -271,4 +224,35 @@ public static JvmInfo readJvmInfo(StreamInput in) throws IOException {
271224
out.writeUTF(entry.getValue());
272225
}
273226
}
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+
}
274258
}

modules/elasticsearch/src/main/java/org/elasticsearch/monitor/jvm/JvmMonitorService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public JvmMonitor() {
9999

100100
private void monitorLongGc() {
101101
JvmStats currentJvmStats = jvmStats();
102-
long collectionTime = currentJvmStats.gcCollectionTime().millis() - lastJvmStats.gcCollectionTime().millis();
102+
long collectionTime = currentJvmStats.gc().collectionTime().millis() - lastJvmStats.gc().collectionTime().millis();
103103
if (collectionTime > gcCollectionWarning.millis()) {
104104
logger.warn("Long GC collection occurred, took [" + new TimeValue(collectionTime) + "], breached threshold [" + gcCollectionWarning + "]");
105105
}

0 commit comments

Comments
 (0)