mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 18:35:25 +00:00
Node Info / Stats: Add max_file_descriptors (info) and open_file_descriptors (stats), closes #1113.
This commit is contained in:
parent
a8d8eb686e
commit
7ef41eefea
@ -30,7 +30,12 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.management.*;
|
import java.lang.management.GarbageCollectorMXBean;
|
||||||
|
import java.lang.management.ManagementFactory;
|
||||||
|
import java.lang.management.MemoryMXBean;
|
||||||
|
import java.lang.management.MemoryUsage;
|
||||||
|
import java.lang.management.RuntimeMXBean;
|
||||||
|
import java.lang.management.ThreadMXBean;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -23,6 +23,10 @@ import org.elasticsearch.common.component.AbstractComponent;
|
|||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
|
||||||
|
import java.lang.management.ManagementFactory;
|
||||||
|
import java.lang.management.OperatingSystemMXBean;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import static org.elasticsearch.monitor.jvm.JvmInfo.*;
|
import static org.elasticsearch.monitor.jvm.JvmInfo.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,17 +34,65 @@ import static org.elasticsearch.monitor.jvm.JvmInfo.*;
|
|||||||
*/
|
*/
|
||||||
public class JmxProcessProbe extends AbstractComponent implements ProcessProbe {
|
public class JmxProcessProbe extends AbstractComponent implements ProcessProbe {
|
||||||
|
|
||||||
|
private static final OperatingSystemMXBean osMxBean = ManagementFactory.getOperatingSystemMXBean();
|
||||||
|
|
||||||
|
private static final Method getMaxFileDescriptorCountField;
|
||||||
|
private static final Method getOpenFileDescriptorCountField;
|
||||||
|
|
||||||
|
static {
|
||||||
|
Method method = null;
|
||||||
|
try {
|
||||||
|
method = osMxBean.getClass().getDeclaredMethod("getMaxFileDescriptorCount");
|
||||||
|
method.setAccessible(true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// not available
|
||||||
|
}
|
||||||
|
getMaxFileDescriptorCountField = method;
|
||||||
|
|
||||||
|
method = null;
|
||||||
|
try {
|
||||||
|
method = osMxBean.getClass().getDeclaredMethod("getOpenFileDescriptorCount");
|
||||||
|
method.setAccessible(true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// not available
|
||||||
|
}
|
||||||
|
getOpenFileDescriptorCountField = method;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long getMaxFileDescriptorCount() {
|
||||||
|
if (getMaxFileDescriptorCountField == null) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return (Long) getMaxFileDescriptorCountField.invoke(osMxBean);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long getOpenFileDescriptorCount() {
|
||||||
|
if (getOpenFileDescriptorCountField == null) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return (Long) getOpenFileDescriptorCountField.invoke(osMxBean);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Inject public JmxProcessProbe(Settings settings) {
|
@Inject public JmxProcessProbe(Settings settings) {
|
||||||
super(settings);
|
super(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public ProcessInfo processInfo() {
|
@Override public ProcessInfo processInfo() {
|
||||||
return new ProcessInfo(jvmInfo().pid());
|
return new ProcessInfo(jvmInfo().pid(), getMaxFileDescriptorCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public ProcessStats processStats() {
|
@Override public ProcessStats processStats() {
|
||||||
ProcessStats stats = new ProcessStats();
|
ProcessStats stats = new ProcessStats();
|
||||||
stats.timestamp = System.currentTimeMillis();
|
stats.timestamp = System.currentTimeMillis();
|
||||||
|
stats.openFileDescriptors = getOpenFileDescriptorCount();
|
||||||
return stats;
|
return stats;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,12 +37,15 @@ public class ProcessInfo implements Streamable, Serializable, ToXContent {
|
|||||||
|
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
|
private long maxFileDescriptors = -1;
|
||||||
|
|
||||||
ProcessInfo() {
|
ProcessInfo() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProcessInfo(long id) {
|
public ProcessInfo(long id, long maxFileDescriptors) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
this.maxFileDescriptors = maxFileDescriptors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long refreshInterval() {
|
public long refreshInterval() {
|
||||||
@ -67,10 +70,19 @@ public class ProcessInfo implements Streamable, Serializable, ToXContent {
|
|||||||
return id();
|
return id();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long maxFileDescriptors() {
|
||||||
|
return this.maxFileDescriptors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getMaxFileDescriptors() {
|
||||||
|
return maxFileDescriptors;
|
||||||
|
}
|
||||||
|
|
||||||
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject("process");
|
builder.startObject("process");
|
||||||
builder.field("refresh_interval", refreshInterval);
|
builder.field("refresh_interval", refreshInterval);
|
||||||
builder.field("id", id);
|
builder.field("id", id);
|
||||||
|
builder.field("max_file_descriptors", maxFileDescriptors);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
@ -84,10 +96,12 @@ public class ProcessInfo implements Streamable, Serializable, ToXContent {
|
|||||||
@Override public void readFrom(StreamInput in) throws IOException {
|
@Override public void readFrom(StreamInput in) throws IOException {
|
||||||
refreshInterval = in.readLong();
|
refreshInterval = in.readLong();
|
||||||
id = in.readLong();
|
id = in.readLong();
|
||||||
|
maxFileDescriptors = in.readLong();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void writeTo(StreamOutput out) throws IOException {
|
@Override public void writeTo(StreamOutput out) throws IOException {
|
||||||
out.writeLong(refreshInterval);
|
out.writeLong(refreshInterval);
|
||||||
out.writeLong(id);
|
out.writeLong(id);
|
||||||
|
out.writeLong(maxFileDescriptors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,12 +37,12 @@ public class ProcessStats implements Streamable, Serializable, ToXContent {
|
|||||||
|
|
||||||
long timestamp = -1;
|
long timestamp = -1;
|
||||||
|
|
||||||
|
long openFileDescriptors;
|
||||||
|
|
||||||
Cpu cpu = null;
|
Cpu cpu = null;
|
||||||
|
|
||||||
Mem mem = null;
|
Mem mem = null;
|
||||||
|
|
||||||
Fd fd;
|
|
||||||
|
|
||||||
ProcessStats() {
|
ProcessStats() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,17 +70,10 @@ public class ProcessStats implements Streamable, Serializable, ToXContent {
|
|||||||
return mem();
|
return mem();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Fd fd() {
|
|
||||||
return fd;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Fd getFd() {
|
|
||||||
return fd();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject("process");
|
builder.startObject("process");
|
||||||
builder.field("timestamp", timestamp);
|
builder.field("timestamp", timestamp);
|
||||||
|
builder.field("open_file_descriptors", openFileDescriptors);
|
||||||
if (cpu != null) {
|
if (cpu != null) {
|
||||||
builder.startObject("cpu");
|
builder.startObject("cpu");
|
||||||
builder.field("percent", cpu.percent());
|
builder.field("percent", cpu.percent());
|
||||||
@ -102,11 +95,6 @@ public class ProcessStats implements Streamable, Serializable, ToXContent {
|
|||||||
builder.field("total_virtual_in_bytes", mem.totalVirtual().bytes());
|
builder.field("total_virtual_in_bytes", mem.totalVirtual().bytes());
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
if (fd != null) {
|
|
||||||
builder.startObject("fd");
|
|
||||||
builder.field("total", fd.total());
|
|
||||||
builder.endObject();
|
|
||||||
}
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
@ -119,19 +107,18 @@ public class ProcessStats implements Streamable, Serializable, ToXContent {
|
|||||||
|
|
||||||
@Override public void readFrom(StreamInput in) throws IOException {
|
@Override public void readFrom(StreamInput in) throws IOException {
|
||||||
timestamp = in.readVLong();
|
timestamp = in.readVLong();
|
||||||
|
openFileDescriptors = in.readLong();
|
||||||
if (in.readBoolean()) {
|
if (in.readBoolean()) {
|
||||||
cpu = Cpu.readCpu(in);
|
cpu = Cpu.readCpu(in);
|
||||||
}
|
}
|
||||||
if (in.readBoolean()) {
|
if (in.readBoolean()) {
|
||||||
mem = Mem.readMem(in);
|
mem = Mem.readMem(in);
|
||||||
}
|
}
|
||||||
if (in.readBoolean()) {
|
|
||||||
fd = Fd.readFd(in);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void writeTo(StreamOutput out) throws IOException {
|
@Override public void writeTo(StreamOutput out) throws IOException {
|
||||||
out.writeVLong(timestamp);
|
out.writeVLong(timestamp);
|
||||||
|
out.writeLong(openFileDescriptors);
|
||||||
if (cpu == null) {
|
if (cpu == null) {
|
||||||
out.writeBoolean(false);
|
out.writeBoolean(false);
|
||||||
} else {
|
} else {
|
||||||
@ -144,47 +131,6 @@ public class ProcessStats implements Streamable, Serializable, ToXContent {
|
|||||||
out.writeBoolean(true);
|
out.writeBoolean(true);
|
||||||
mem.writeTo(out);
|
mem.writeTo(out);
|
||||||
}
|
}
|
||||||
if (fd == null) {
|
|
||||||
out.writeBoolean(false);
|
|
||||||
} else {
|
|
||||||
out.writeBoolean(true);
|
|
||||||
fd.writeTo(out);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Fd implements Streamable, Serializable {
|
|
||||||
|
|
||||||
long total = -1;
|
|
||||||
|
|
||||||
Fd() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Fd readFd(StreamInput in) throws IOException {
|
|
||||||
Fd fd = new Fd();
|
|
||||||
fd.readFrom(in);
|
|
||||||
return fd;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public void readFrom(StreamInput in) throws IOException {
|
|
||||||
total = in.readLong();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public void writeTo(StreamOutput out) throws IOException {
|
|
||||||
out.writeLong(total);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the Total number of open file descriptors.
|
|
||||||
*
|
|
||||||
* <p>Supported Platforms: AIX, HPUX, Linux, Solaris, Win32.
|
|
||||||
*/
|
|
||||||
public long total() {
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getTotal() {
|
|
||||||
return total();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Mem implements Streamable, Serializable {
|
public static class Mem implements Streamable, Serializable {
|
||||||
|
@ -23,7 +23,10 @@ import org.elasticsearch.common.component.AbstractComponent;
|
|||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.monitor.sigar.SigarService;
|
import org.elasticsearch.monitor.sigar.SigarService;
|
||||||
import org.hyperic.sigar.*;
|
import org.hyperic.sigar.ProcCpu;
|
||||||
|
import org.hyperic.sigar.ProcMem;
|
||||||
|
import org.hyperic.sigar.Sigar;
|
||||||
|
import org.hyperic.sigar.SigarException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kimchy (shay.banon)
|
* @author kimchy (shay.banon)
|
||||||
@ -38,13 +41,14 @@ public class SigarProcessProbe extends AbstractComponent implements ProcessProbe
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public synchronized ProcessInfo processInfo() {
|
@Override public synchronized ProcessInfo processInfo() {
|
||||||
return new ProcessInfo(sigarService.sigar().getPid());
|
return new ProcessInfo(sigarService.sigar().getPid(), JmxProcessProbe.getMaxFileDescriptorCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public synchronized ProcessStats processStats() {
|
@Override public synchronized ProcessStats processStats() {
|
||||||
Sigar sigar = sigarService.sigar();
|
Sigar sigar = sigarService.sigar();
|
||||||
ProcessStats stats = new ProcessStats();
|
ProcessStats stats = new ProcessStats();
|
||||||
stats.timestamp = System.currentTimeMillis();
|
stats.timestamp = System.currentTimeMillis();
|
||||||
|
stats.openFileDescriptors = JmxProcessProbe.getOpenFileDescriptorCount();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ProcCpu cpu = sigar.getProcCpu(sigar.getPid());
|
ProcCpu cpu = sigar.getProcCpu(sigar.getPid());
|
||||||
@ -66,16 +70,6 @@ public class SigarProcessProbe extends AbstractComponent implements ProcessProbe
|
|||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
ProcFd fd = sigar.getProcFd(sigar.getPid());
|
|
||||||
if (fd.getTotal() != Sigar.FIELD_NOTIMPL) {
|
|
||||||
stats.fd = new ProcessStats.Fd();
|
|
||||||
stats.fd.total = fd.getTotal();
|
|
||||||
}
|
|
||||||
} catch (SigarException e) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
return stats;
|
return stats;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user