mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 02:14:54 +00:00
parent
6e4586fd6b
commit
efa59f37a8
@ -355,10 +355,10 @@
|
||||
|
||||
################################## GC Logging ################################
|
||||
|
||||
#monitor.jvm.gc.ParNew.warn: 1000ms
|
||||
#monitor.jvm.gc.ParNew.info: 700ms
|
||||
#monitor.jvm.gc.ParNew.debug: 400ms
|
||||
#monitor.jvm.gc.young.warn: 1000ms
|
||||
#monitor.jvm.gc.young.info: 700ms
|
||||
#monitor.jvm.gc.young.debug: 400ms
|
||||
|
||||
#monitor.jvm.gc.ConcurrentMarkSweep.warn: 10s
|
||||
#monitor.jvm.gc.ConcurrentMarkSweep.info: 5s
|
||||
#monitor.jvm.gc.ConcurrentMarkSweep.debug: 2s
|
||||
#monitor.jvm.gc.old.warn: 10s
|
||||
#monitor.jvm.gc.old.info: 5s
|
||||
#monitor.jvm.gc.old.debug: 2s
|
||||
|
55
src/main/java/org/elasticsearch/monitor/jvm/GcNames.java
Normal file
55
src/main/java/org/elasticsearch/monitor/jvm/GcNames.java
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.monitor.jvm;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class GcNames {
|
||||
|
||||
public static String YOUNG = "young";
|
||||
public static String OLD = "old";
|
||||
public static String SURVIVOR = "survivor";
|
||||
|
||||
/**
|
||||
* Resolves the GC type by its memory pool name ({@link java.lang.management.MemoryPoolMXBean#getName()}.
|
||||
*/
|
||||
public static String getByMemoryPoolName(String poolName, String defaultName) {
|
||||
if ("Eden Space".equals(poolName) || "PS Eden Space".equals(poolName) || "Par Eden Space".equals(poolName) || "G1 Eden Space".equals(poolName)) {
|
||||
return YOUNG;
|
||||
}
|
||||
if ("Survivor Space".equals(poolName) || "PS Survivor Space".equals(poolName) || "Par Survivor Space".equals(poolName) || "G1 Survivor Space".equals(poolName)) {
|
||||
return SURVIVOR;
|
||||
}
|
||||
if ("Tenured Gen".equals(poolName) || "PS Old Gen".equals(poolName) || "CMS Old Gen".equals(poolName) || "G1 Old Gen".equals(poolName)) {
|
||||
return OLD;
|
||||
}
|
||||
return defaultName;
|
||||
}
|
||||
|
||||
public static String getByGcName(String gcName, String defaultName) {
|
||||
if ("Copy".equals(gcName) || "PS Scavenge".equals(gcName) || "ParNew".equals(gcName) || "G1 Young Generation".equals(gcName)) {
|
||||
return YOUNG;
|
||||
}
|
||||
if ("MarkSweepCompact".equals(gcName) || "PS MarkSweep".equals(gcName) || "ConcurrentMarkSweep".equals(gcName) || "G1 Old Generation".equals(gcName)) {
|
||||
return OLD;
|
||||
}
|
||||
return defaultName;
|
||||
}
|
||||
}
|
@ -19,6 +19,8 @@
|
||||
|
||||
package org.elasticsearch.monitor.jvm;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.io.stream.Streamable;
|
||||
@ -29,10 +31,9 @@ import org.elasticsearch.common.xcontent.XContentBuilderString;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.MemoryMXBean;
|
||||
import java.lang.management.RuntimeMXBean;
|
||||
import java.lang.management.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -78,6 +79,20 @@ public class JvmInfo implements Streamable, Serializable, ToXContent {
|
||||
info.classPath = runtimeMXBean.getClassPath();
|
||||
info.systemProperties = runtimeMXBean.getSystemProperties();
|
||||
|
||||
List<GarbageCollectorMXBean> gcMxBeans = ManagementFactory.getGarbageCollectorMXBeans();
|
||||
info.gcCollectors = new String[gcMxBeans.size()];
|
||||
for (int i = 0; i < gcMxBeans.size(); i++) {
|
||||
GarbageCollectorMXBean gcMxBean = gcMxBeans.get(i);
|
||||
info.gcCollectors[i] = gcMxBean.getName();
|
||||
}
|
||||
|
||||
List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
|
||||
info.memoryPools = new String[memoryPoolMXBeans.size()];
|
||||
for (int i = 0; i < memoryPoolMXBeans.size(); i++) {
|
||||
MemoryPoolMXBean memoryPoolMXBean = memoryPoolMXBeans.get(i);
|
||||
info.memoryPools[i] = memoryPoolMXBean.getName();
|
||||
}
|
||||
|
||||
INSTANCE = info;
|
||||
}
|
||||
|
||||
@ -104,6 +119,9 @@ public class JvmInfo implements Streamable, Serializable, ToXContent {
|
||||
|
||||
Map<String, String> systemProperties;
|
||||
|
||||
String[] gcCollectors = Strings.EMPTY_ARRAY;
|
||||
String[] memoryPools = Strings.EMPTY_ARRAY;
|
||||
|
||||
private JvmInfo() {
|
||||
}
|
||||
|
||||
@ -281,6 +299,9 @@ public class JvmInfo implements Streamable, Serializable, ToXContent {
|
||||
builder.byteSizeField(Fields.DIRECT_MAX_IN_BYTES, Fields.DIRECT_MAX, mem.directMemoryMax);
|
||||
builder.endObject();
|
||||
|
||||
builder.field(Fields.GC_COLLECTORS, gcCollectors);
|
||||
builder.field(Fields.MEMORY_POOLS, memoryPools);
|
||||
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
@ -305,6 +326,8 @@ public class JvmInfo implements Streamable, Serializable, ToXContent {
|
||||
static final XContentBuilderString NON_HEAP_MAX_IN_BYTES = new XContentBuilderString("non_heap_max_in_bytes");
|
||||
static final XContentBuilderString DIRECT_MAX = new XContentBuilderString("direct_max");
|
||||
static final XContentBuilderString DIRECT_MAX_IN_BYTES = new XContentBuilderString("direct_max_in_bytes");
|
||||
static final XContentBuilderString GC_COLLECTORS = new XContentBuilderString("gc_collectors");
|
||||
static final XContentBuilderString MEMORY_POOLS = new XContentBuilderString("memory_pools");
|
||||
}
|
||||
|
||||
public static JvmInfo readJvmInfo(StreamInput in) throws IOException {
|
||||
@ -334,6 +357,10 @@ public class JvmInfo implements Streamable, Serializable, ToXContent {
|
||||
}
|
||||
mem = new Mem();
|
||||
mem.readFrom(in);
|
||||
if (in.getVersion().after(Version.V_0_90_9)) {
|
||||
gcCollectors = in.readStringArray();
|
||||
memoryPools = in.readStringArray();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -356,6 +383,10 @@ public class JvmInfo implements Streamable, Serializable, ToXContent {
|
||||
out.writeString(entry.getValue());
|
||||
}
|
||||
mem.writeTo(out);
|
||||
if (out.getVersion().after(Version.V_0_90_9)) {
|
||||
out.writeStringArray(gcCollectors);
|
||||
out.writeStringArray(memoryPools);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Mem implements Streamable, Serializable {
|
||||
|
@ -106,11 +106,11 @@ public class JvmMonitorService extends AbstractLifecycleComponent<JvmMonitorServ
|
||||
gcThresholds.put(name, new GcThreshold(name, warn.millis(), info.millis(), debug.millis()));
|
||||
}
|
||||
}
|
||||
if (!gcThresholds.containsKey("ParNew")) {
|
||||
gcThresholds.put("ParNew", new GcThreshold("ParNew", 1000, 700, 400));
|
||||
if (!gcThresholds.containsKey(GcNames.YOUNG)) {
|
||||
gcThresholds.put(GcNames.YOUNG, new GcThreshold(GcNames.YOUNG, 1000, 700, 400));
|
||||
}
|
||||
if (!gcThresholds.containsKey("ConcurrentMarkSweep")) {
|
||||
gcThresholds.put("ConcurrentMarkSweep", new GcThreshold("ConcurrentMarkSweep", 10000, 5000, 2000));
|
||||
if (!gcThresholds.containsKey(GcNames.OLD)) {
|
||||
gcThresholds.put(GcNames.OLD, new GcThreshold(GcNames.OLD, 10000, 5000, 2000));
|
||||
}
|
||||
if (!gcThresholds.containsKey("default")) {
|
||||
gcThresholds.put("default", new GcThreshold("default", 10000, 5000, 2000));
|
||||
@ -154,8 +154,12 @@ public class JvmMonitorService extends AbstractLifecycleComponent<JvmMonitorServ
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
// monitorDeadlock();
|
||||
monitorLongGc();
|
||||
monitorLongGc();
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void monitorLongGc() {
|
||||
|
@ -145,18 +145,23 @@ public class JvmStats implements Streamable, Serializable, ToXContent {
|
||||
stats.mem.nonHeapCommitted = memUsage.getCommitted() < 0 ? 0 : memUsage.getCommitted();
|
||||
|
||||
List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
|
||||
stats.mem.pools = new MemoryPool[memoryPoolMXBeans.size()];
|
||||
List<MemoryPool> pools = new ArrayList<MemoryPool>();
|
||||
for (int i = 0; i < memoryPoolMXBeans.size(); i++) {
|
||||
MemoryPoolMXBean memoryPoolMXBean = memoryPoolMXBeans.get(i);
|
||||
MemoryUsage usage = memoryPoolMXBean.getUsage();
|
||||
MemoryUsage peakUsage = memoryPoolMXBean.getPeakUsage();
|
||||
stats.mem.pools[i] = new MemoryPool(memoryPoolMXBean.getName(),
|
||||
String name = GcNames.getByMemoryPoolName(memoryPoolMXBean.getName(), null);
|
||||
if (name == null) { // if we can't resolve it, its not interesting.... (Per Gen, Code Cache)
|
||||
continue;
|
||||
}
|
||||
pools.add(new MemoryPool(name,
|
||||
usage.getUsed() < 0 ? 0 : usage.getUsed(),
|
||||
usage.getMax() < 0 ? 0 : usage.getMax(),
|
||||
peakUsage.getUsed() < 0 ? 0 : peakUsage.getUsed(),
|
||||
peakUsage.getMax() < 0 ? 0 : peakUsage.getMax()
|
||||
);
|
||||
));
|
||||
}
|
||||
stats.mem.pools = pools.toArray(new MemoryPool[pools.size()]);
|
||||
|
||||
stats.threads = new Threads();
|
||||
stats.threads.count = threadMXBean.getThreadCount();
|
||||
@ -168,7 +173,7 @@ public class JvmStats implements Streamable, Serializable, ToXContent {
|
||||
for (int i = 0; i < stats.gc.collectors.length; i++) {
|
||||
GarbageCollectorMXBean gcMxBean = gcMxBeans.get(i);
|
||||
stats.gc.collectors[i] = new GarbageCollector();
|
||||
stats.gc.collectors[i].name = gcMxBean.getName();
|
||||
stats.gc.collectors[i].name = GcNames.getByGcName(gcMxBean.getName(), gcMxBean.getName());
|
||||
stats.gc.collectors[i].collectionCount = gcMxBean.getCollectionCount();
|
||||
stats.gc.collectors[i].collectionTime = gcMxBean.getCollectionTime();
|
||||
if (enableLastGc) {
|
||||
@ -321,8 +326,6 @@ public class JvmStats implements Streamable, Serializable, ToXContent {
|
||||
}
|
||||
if (gc != null) {
|
||||
builder.startObject(Fields.GC);
|
||||
builder.field(Fields.COLLECTION_COUNT, gc.collectionCount());
|
||||
builder.timeValueField(Fields.COLLECTION_TIME_IN_MILLIS, Fields.COLLECTION_TIME, gc.collectionTime());
|
||||
|
||||
builder.startObject(Fields.COLLECTORS);
|
||||
for (GarbageCollector collector : gc) {
|
||||
@ -482,22 +485,6 @@ public class JvmStats implements Streamable, Serializable, ToXContent {
|
||||
public Iterator<GarbageCollector> iterator() {
|
||||
return Iterators.forArray(collectors);
|
||||
}
|
||||
|
||||
public long collectionCount() {
|
||||
long collectionCount = 0;
|
||||
for (GarbageCollector gc : collectors) {
|
||||
collectionCount += gc.collectionCount();
|
||||
}
|
||||
return collectionCount;
|
||||
}
|
||||
|
||||
public TimeValue collectionTime() {
|
||||
long collectionTime = 0;
|
||||
for (GarbageCollector gc : collectors) {
|
||||
collectionTime += gc.collectionTime;
|
||||
}
|
||||
return new TimeValue(collectionTime, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
public static class GarbageCollector implements Streamable, Serializable {
|
||||
|
Loading…
x
Reference in New Issue
Block a user