From 4ed93d20f659a3eb92b43a694eb529f1d387f357 Mon Sep 17 00:00:00 2001 From: kimchy Date: Fri, 7 May 2010 19:16:08 +0300 Subject: [PATCH] more work on monitoring support --- .../elasticsearch/monitor/MonitorModule.java | 7 + .../memory/alpha/AlphaMemoryMonitor.java | 5 +- .../monitor/network/JmxNetworkProbe.java | 45 +++ .../monitor/network/NetworkInfo.java | 112 ++++++ .../monitor/network/NetworkProbe.java | 30 ++ .../monitor/network/NetworkService.java | 49 +++ .../monitor/network/NetworkStats.java | 196 ++++++++++ .../monitor/network/SigarNetworkProbe.java | 83 ++++ .../org/elasticsearch/monitor/os/OsInfo.java | 240 +++++++----- .../org/elasticsearch/monitor/os/OsStats.java | 316 ++++++++++------ .../monitor/os/SigarOsProbe.java | 46 ++- .../monitor/process/ProcessStats.java | 356 ++++++++++++------ .../monitor/process/SigarProcessProbe.java | 21 +- 13 files changed, 1141 insertions(+), 365 deletions(-) create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/JmxNetworkProbe.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkInfo.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkProbe.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkService.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkStats.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/SigarNetworkProbe.java diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/MonitorModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/MonitorModule.java index 4c1dcb059c7..1038172e35c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/MonitorModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/MonitorModule.java @@ -30,6 +30,10 @@ import org.elasticsearch.monitor.jvm.JvmService; import org.elasticsearch.monitor.memory.MemoryMonitor; import org.elasticsearch.monitor.memory.MemoryMonitorService; import org.elasticsearch.monitor.memory.alpha.AlphaMemoryMonitor; +import org.elasticsearch.monitor.network.JmxNetworkProbe; +import org.elasticsearch.monitor.network.NetworkProbe; +import org.elasticsearch.monitor.network.NetworkService; +import org.elasticsearch.monitor.network.SigarNetworkProbe; import org.elasticsearch.monitor.os.JmxOsProbe; import org.elasticsearch.monitor.os.OsProbe; import org.elasticsearch.monitor.os.OsService; @@ -81,6 +85,7 @@ public class MonitorModule extends AbstractModule { bind(SigarService.class).toInstance(sigarService); bind(ProcessProbe.class).to(SigarProcessProbe.class).asEagerSingleton(); bind(OsProbe.class).to(SigarOsProbe.class).asEagerSingleton(); + bind(NetworkProbe.class).to(SigarNetworkProbe.class).asEagerSingleton(); sigarLoaded = true; } } catch (Throwable e) { @@ -90,10 +95,12 @@ public class MonitorModule extends AbstractModule { // bind non sigar implementations bind(ProcessProbe.class).to(JmxProcessProbe.class).asEagerSingleton(); bind(OsProbe.class).to(JmxOsProbe.class).asEagerSingleton(); + bind(NetworkProbe.class).to(JmxNetworkProbe.class).asEagerSingleton(); } // bind other services bind(ProcessService.class).asEagerSingleton(); bind(OsService.class).asEagerSingleton(); + bind(NetworkService.class).asEagerSingleton(); bind(JvmService.class).asEagerSingleton(); bind(JvmMonitorService.class).asEagerSingleton(); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/memory/alpha/AlphaMemoryMonitor.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/memory/alpha/AlphaMemoryMonitor.java index e0757b63bab..f28a8672f1b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/memory/alpha/AlphaMemoryMonitor.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/memory/alpha/AlphaMemoryMonitor.java @@ -19,7 +19,6 @@ package org.elasticsearch.monitor.memory.alpha; -import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.indices.IndicesMemoryCleaner; import org.elasticsearch.monitor.memory.MemoryMonitor; @@ -29,6 +28,7 @@ import org.elasticsearch.util.SizeValue; import org.elasticsearch.util.StopWatch; import org.elasticsearch.util.TimeValue; import org.elasticsearch.util.component.AbstractLifecycleComponent; +import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.util.settings.Settings; import java.util.concurrent.ScheduledFuture; @@ -39,8 +39,7 @@ import static org.elasticsearch.util.TimeValue.*; /** * @author kimchy (shay.banon) */ -public class - AlphaMemoryMonitor extends AbstractLifecycleComponent implements MemoryMonitor { +public class AlphaMemoryMonitor extends AbstractLifecycleComponent implements MemoryMonitor { private final double upperMemoryThreshold; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/JmxNetworkProbe.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/JmxNetworkProbe.java new file mode 100644 index 00000000000..76e242b83af --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/JmxNetworkProbe.java @@ -0,0 +1,45 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search 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.network; + +import org.elasticsearch.util.component.AbstractComponent; +import org.elasticsearch.util.guice.inject.Inject; +import org.elasticsearch.util.settings.Settings; + +/** + * @author kimchy (shay.banon) + */ +public class JmxNetworkProbe extends AbstractComponent implements NetworkProbe { + + @Inject public JmxNetworkProbe(Settings settings) { + super(settings); + } + + @Override public NetworkInfo networkInfo() { + NetworkInfo info = new NetworkInfo(); + return info; + } + + @Override public NetworkStats networkStats() { + NetworkStats stats = new NetworkStats(); + stats.timestamp = System.currentTimeMillis(); + return stats; + } +} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkInfo.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkInfo.java new file mode 100644 index 00000000000..3ab3ff5811a --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkInfo.java @@ -0,0 +1,112 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search 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.network; + +import org.elasticsearch.util.io.stream.StreamInput; +import org.elasticsearch.util.io.stream.StreamOutput; +import org.elasticsearch.util.io.stream.Streamable; + +import java.io.IOException; +import java.io.Serializable; + +/** + * @author kimchy (shay.banon) + */ +public class NetworkInfo implements Streamable, Serializable { + + public static final Interface NA_INTERFACE = new Interface(); + + Interface primary = NA_INTERFACE; + + public Interface primaryInterface() { + return primary; + } + + public Interface getPrimaryInterface() { + return primaryInterface(); + } + + @Override public void readFrom(StreamInput in) throws IOException { + primary = Interface.readNetworkInterface(in); + } + + @Override public void writeTo(StreamOutput out) throws IOException { + primary.writeTo(out); + } + + public static class Interface implements Streamable, Serializable { + + private String name = ""; + private String address = ""; + private String macAddress = ""; + + private Interface() { + } + + public Interface(String name, String address, String macAddress) { + this.name = name; + this.address = address; + this.macAddress = macAddress; + } + + public String name() { + return name; + } + + public String getName() { + return name(); + } + + public String address() { + return address; + } + + public String getAddress() { + return address(); + } + + public String macAddress() { + return macAddress; + } + + public String getMacAddress() { + return macAddress(); + } + + public static Interface readNetworkInterface(StreamInput in) throws IOException { + Interface inf = new Interface(); + inf.readFrom(in); + return inf; + } + + @Override public void readFrom(StreamInput in) throws IOException { + name = in.readUTF(); + address = in.readUTF(); + macAddress = in.readUTF(); + } + + @Override public void writeTo(StreamOutput out) throws IOException { + out.writeUTF(name); + out.writeUTF(address); + out.writeUTF(macAddress); + } + + } +} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkProbe.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkProbe.java new file mode 100644 index 00000000000..0006e47a294 --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkProbe.java @@ -0,0 +1,30 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search 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.network; + +/** + * @author kimchy (shay.banon) + */ +public interface NetworkProbe { + + NetworkInfo networkInfo(); + + NetworkStats networkStats(); +} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkService.java new file mode 100644 index 00000000000..ea567193916 --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkService.java @@ -0,0 +1,49 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search 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.network; + +import org.elasticsearch.util.component.AbstractComponent; +import org.elasticsearch.util.guice.inject.Inject; +import org.elasticsearch.util.settings.Settings; + +/** + * @author kimchy (shay.banon) + */ +public class NetworkService extends AbstractComponent { + + private final NetworkProbe probe; + + private final NetworkInfo info; + + @Inject public NetworkService(Settings settings, NetworkProbe probe) { + super(settings); + this.probe = probe; + + this.info = probe.networkInfo(); + } + + public NetworkInfo info() { + return this.info; + } + + public NetworkStats stats() { + return probe.networkStats(); + } +} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkStats.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkStats.java new file mode 100644 index 00000000000..3e4bb11b380 --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkStats.java @@ -0,0 +1,196 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search 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.network; + +import org.elasticsearch.util.io.stream.StreamInput; +import org.elasticsearch.util.io.stream.StreamOutput; +import org.elasticsearch.util.io.stream.Streamable; + +import java.io.IOException; +import java.io.Serializable; + +/** + * @author kimchy (shay.banon) + */ +public class NetworkStats implements Streamable, Serializable { + + long timestamp; + + Tcp tcp = null; + + @Override public void readFrom(StreamInput in) throws IOException { + timestamp = in.readVLong(); + if (in.readBoolean()) { + tcp = Tcp.readNetworkTcp(in); + } + } + + public long timestamp() { + return timestamp; + } + + public long getTimestamp() { + return timestamp(); + } + + public Tcp tcp() { + return tcp; + } + + public Tcp getTcp() { + return tcp(); + } + + @Override public void writeTo(StreamOutput out) throws IOException { + out.writeVLong(timestamp); + if (tcp == null) { + out.writeBoolean(false); + } else { + out.writeBoolean(true); + tcp.writeTo(out); + } + } + + public static class Tcp implements Serializable, Streamable { + + long activeOpens; + long passiveOpens; + long attemptFails; + long estabResets; + long currEstab; + long inSegs; + long outSegs; + long retransSegs; + long inErrs; + long outRsts; + + public static Tcp readNetworkTcp(StreamInput in) throws IOException { + Tcp tcp = new Tcp(); + tcp.readFrom(in); + return tcp; + } + + @Override public void readFrom(StreamInput in) throws IOException { + activeOpens = in.readLong(); + passiveOpens = in.readLong(); + attemptFails = in.readLong(); + estabResets = in.readLong(); + currEstab = in.readLong(); + inSegs = in.readLong(); + outSegs = in.readLong(); + retransSegs = in.readLong(); + inErrs = in.readLong(); + outRsts = in.readLong(); + } + + @Override public void writeTo(StreamOutput out) throws IOException { + out.writeLong(activeOpens); + out.writeLong(passiveOpens); + out.writeLong(attemptFails); + out.writeLong(estabResets); + out.writeLong(currEstab); + out.writeLong(inSegs); + out.writeLong(outSegs); + out.writeLong(retransSegs); + out.writeLong(inErrs); + out.writeLong(outRsts); + } + + public long activeOpens() { + return this.activeOpens; + } + + public long getActiveOpens() { + return activeOpens(); + } + + public long passiveOpens() { + return passiveOpens; + } + + public long getPassiveOpens() { + return passiveOpens(); + } + + public long attemptFails() { + return attemptFails; + } + + public long getAttemptFails() { + return attemptFails(); + } + + public long estabResets() { + return estabResets; + } + + public long getEstabResets() { + return estabResets(); + } + + public long currEstab() { + return currEstab; + } + + public long getCurrEstab() { + return currEstab(); + } + + public long inSegs() { + return inSegs; + } + + public long getInSegs() { + return inSegs(); + } + + public long outSegs() { + return outSegs; + } + + public long getOutSegs() { + return outSegs(); + } + + public long retransSegs() { + return retransSegs; + } + + public long getRetransSegs() { + return retransSegs(); + } + + public long inErrs() { + return inErrs; + } + + public long getInErrs() { + return inErrs(); + } + + public long outRsts() { + return outRsts; + } + + public long getOutRsts() { + return outRsts(); + } + } +} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/SigarNetworkProbe.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/SigarNetworkProbe.java new file mode 100644 index 00000000000..30921d5c171 --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/SigarNetworkProbe.java @@ -0,0 +1,83 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search 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.network; + +import org.elasticsearch.monitor.sigar.SigarService; +import org.elasticsearch.util.component.AbstractComponent; +import org.elasticsearch.util.guice.inject.Inject; +import org.elasticsearch.util.settings.Settings; +import org.hyperic.sigar.NetInterfaceConfig; +import org.hyperic.sigar.Sigar; +import org.hyperic.sigar.SigarException; +import org.hyperic.sigar.Tcp; + +/** + * @author kimchy (shay.banon) + */ +public class SigarNetworkProbe extends AbstractComponent implements NetworkProbe { + + private final SigarService sigarService; + + @Inject public SigarNetworkProbe(Settings settings, SigarService sigarService) { + super(settings); + this.sigarService = sigarService; + } + + @Override public NetworkInfo networkInfo() { + Sigar sigar = sigarService.sigar(); + + NetworkInfo networkInfo = new NetworkInfo(); + + try { + NetInterfaceConfig netInterfaceConfig = sigar.getNetInterfaceConfig(); + networkInfo.primary = new NetworkInfo.Interface(netInterfaceConfig.getName(), netInterfaceConfig.getAddress(), netInterfaceConfig.getAddress()); + } catch (SigarException e) { + // ignore + } + + return networkInfo; + } + + @Override public synchronized NetworkStats networkStats() { + Sigar sigar = sigarService.sigar(); + + NetworkStats stats = new NetworkStats(); + stats.timestamp = System.currentTimeMillis(); + + try { + Tcp tcp = sigar.getTcp(); + stats.tcp = new NetworkStats.Tcp(); + stats.tcp.activeOpens = tcp.getActiveOpens(); + stats.tcp.passiveOpens = tcp.getPassiveOpens(); + stats.tcp.attemptFails = tcp.getAttemptFails(); + stats.tcp.estabResets = tcp.getEstabResets(); + stats.tcp.currEstab = tcp.getCurrEstab(); + stats.tcp.inSegs = tcp.getInSegs(); + stats.tcp.outSegs = tcp.getOutSegs(); + stats.tcp.retransSegs = tcp.getRetransSegs(); + stats.tcp.inErrs = tcp.getInErrs(); + stats.tcp.outRsts = tcp.getOutRsts(); + } catch (SigarException e) { + // ignore + } + + return stats; + } +} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsInfo.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsInfo.java index 7a59c5d2233..16f15e322f9 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsInfo.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsInfo.java @@ -32,97 +32,37 @@ import java.io.Serializable; */ public class OsInfo implements Streamable, Serializable { - String cpuVendor = ""; + Cpu cpu = null; - String cpuModel = ""; + Mem mem = null; - int cpuMhz = -1; - - int cpuTotalCores = -1; - - int cpuTotalSockets = -1; - - int cpuCoresPerSocket = -1; - - long cpuCacheSize = -1; - - long memTotal = -1; - - long swapTotal = -1; + Swap swap = null; OsInfo() { } - public String cpuVendor() { - return cpuVendor; + public Cpu cpu() { + return this.cpu; } - public String getCpuVendor() { - return cpuVendor(); + public Cpu getCpu() { + return cpu(); } - public String cpuModel() { - return cpuModel; + public Mem mem() { + return this.mem; } - public String getCpuModel() { - return cpuModel(); + public Mem getMem() { + return mem(); } - public int cpuMhz() { - return cpuMhz; + public Swap swap() { + return this.swap; } - public int getCpuMhz() { - return cpuMhz(); - } - - public int cpuTotalCores() { - return cpuTotalCores; - } - - public int getCpuTotalCores() { - return cpuTotalCores(); - } - - public int cpuTotalSockets() { - return cpuTotalSockets; - } - - public int getCpuTotalSockets() { - return cpuTotalSockets(); - } - - public int cpuCoresPerSocket() { - return cpuCoresPerSocket; - } - - public int getCpuCoresPerSocket() { - return cpuCoresPerSocket(); - } - - public SizeValue cpuCacheSize() { - return new SizeValue(cpuCacheSize); - } - - public SizeValue getCpuCacheSize() { - return cpuCacheSize(); - } - - public SizeValue memTotal() { - return new SizeValue(memTotal); - } - - public SizeValue getMemTotal() { - return memTotal(); - } - - public SizeValue swapTotal() { - return new SizeValue(swapTotal); - } - - public SizeValue getSwapTotal() { - return swapTotal(); + public Swap getSwap() { + return swap(); } public static OsInfo readOsInfo(StreamInput in) throws IOException { @@ -132,26 +72,140 @@ public class OsInfo implements Streamable, Serializable { } @Override public void readFrom(StreamInput in) throws IOException { - cpuVendor = in.readUTF(); - cpuModel = in.readUTF(); - cpuMhz = in.readInt(); - cpuTotalCores = in.readInt(); - cpuTotalSockets = in.readInt(); - cpuCoresPerSocket = in.readInt(); - cpuCacheSize = in.readLong(); - memTotal = in.readLong(); - swapTotal = in.readLong(); + if (in.readBoolean()) { + cpu = Cpu.readCpu(in); + } + if (in.readBoolean()) { + mem = Mem.readMem(in); + } + if (in.readBoolean()) { + swap = Swap.readSwap(in); + } } @Override public void writeTo(StreamOutput out) throws IOException { - out.writeUTF(cpuVendor); - out.writeUTF(cpuModel); - out.writeInt(cpuMhz); - out.writeInt(cpuTotalCores); - out.writeInt(cpuTotalSockets); - out.writeInt(cpuCoresPerSocket); - out.writeLong(cpuCacheSize); - out.writeLong(memTotal); - out.writeLong(swapTotal); + if (cpu == null) { + out.writeBoolean(false); + } else { + out.writeBoolean(true); + cpu.writeTo(out); + } + if (mem == null) { + out.writeBoolean(false); + } else { + out.writeBoolean(true); + mem.writeTo(out); + } + if (swap == null) { + out.writeBoolean(false); + } else { + out.writeBoolean(true); + swap.writeTo(out); + } + } + + public static class Swap implements Streamable, Serializable { + + long total = -1; + + Swap() { + + } + + public static Swap readSwap(StreamInput in) throws IOException { + Swap swap = new Swap(); + swap.readFrom(in); + return swap; + } + + @Override public void readFrom(StreamInput in) throws IOException { + total = in.readLong(); + } + + @Override public void writeTo(StreamOutput out) throws IOException { + out.writeLong(total); + } + + public SizeValue total() { + return new SizeValue(total); + } + + public SizeValue getTotal() { + return total(); + } + + } + + public static class Mem implements Streamable, Serializable { + + long total = -1; + + Mem() { + + } + + public static Mem readMem(StreamInput in) throws IOException { + Mem mem = new Mem(); + mem.readFrom(in); + return mem; + } + + @Override public void readFrom(StreamInput in) throws IOException { + total = in.readLong(); + } + + @Override public void writeTo(StreamOutput out) throws IOException { + out.writeLong(total); + } + + public SizeValue total() { + return new SizeValue(total); + } + + public SizeValue getTotal() { + return total(); + } + + } + + public static class Cpu implements Streamable, Serializable { + + String vendor = ""; + String model = ""; + int mhz = -1; + int totalCores = -1; + int totalSockets = -1; + int coresPerSocket = -1; + long cacheSize = -1; + + Cpu() { + + } + + public static Cpu readCpu(StreamInput in) throws IOException { + Cpu cpu = new Cpu(); + cpu.readFrom(in); + return cpu; + } + + @Override public void readFrom(StreamInput in) throws IOException { + vendor = in.readUTF(); + model = in.readUTF(); + mhz = in.readInt(); + totalCores = in.readInt(); + totalSockets = in.readInt(); + coresPerSocket = in.readInt(); + cacheSize = in.readLong(); + } + + @Override public void writeTo(StreamOutput out) throws IOException { + out.writeUTF(vendor); + out.writeUTF(model); + out.writeInt(mhz); + out.writeInt(totalCores); + out.writeInt(totalSockets); + out.writeInt(coresPerSocket); + out.writeLong(cacheSize); + } } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsStats.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsStats.java index 9780f25898e..34dadd59f9a 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsStats.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsStats.java @@ -44,27 +44,11 @@ public class OsStats implements Streamable, Serializable { long uptime = -1; - double cpuSys = -1; + Cpu cpu = null; - double cpuUser = -1; + Mem mem = null; - double cpuIdle = -1; - - long memFree = -1; - - double memFreePercent = -1; - - long memUsed = -1; - - double memUsedPercent = -1; - - long memActualFree = -1; - - long memActualUsed = -1; - - long swapFree = -1; - - long swapUsed = -1; + Swap swap = null; OsStats() { } @@ -93,92 +77,28 @@ public class OsStats implements Streamable, Serializable { return uptime(); } - public Percent cpuSys() { - return new Percent(cpuSys); + public Cpu cpu() { + return this.cpu; } - public Percent getCpuSys() { - return cpuSys(); + public Cpu getCpu() { + return cpu(); } - public Percent cpuUser() { - return new Percent(cpuUser); + public Mem mem() { + return this.mem; } - public Percent getCpuUser() { - return cpuUser(); + public Mem getMem() { + return mem(); } - public Percent cpuIdle() { - return new Percent(cpuIdle); + public Swap swap() { + return this.swap; } - public Percent getCpuIdle() { - return cpuIdle(); - } - - public SizeValue memUsed() { - return new SizeValue(memUsed); - } - - public SizeValue getMemUsed() { - return memUsed(); - } - - public Percent memUsedPercent() { - return new Percent(memUsedPercent); - } - - public Percent getMemUsedPercent() { - return memUsedPercent(); - } - - public SizeValue memFree() { - return new SizeValue(memFree); - } - - public SizeValue getMemFree() { - return memFree(); - } - - public Percent memFreePercent() { - return new Percent(memFreePercent); - } - - public Percent getMemFreePercent() { - return memFreePercent(); - } - - public SizeValue memActualFree() { - return new SizeValue(memActualFree); - } - - public SizeValue getMemActualFree() { - return memActualFree(); - } - - public SizeValue memActualUsed() { - return new SizeValue(memActualUsed); - } - - public SizeValue getMemActualUsed() { - return memActualUsed(); - } - - public SizeValue swapUsed() { - return new SizeValue(swapUsed); - } - - public SizeValue getSwapUsed() { - return swapUsed(); - } - - public SizeValue swapFree() { - return new SizeValue(swapFree); - } - - public SizeValue getSwapFree() { - return swapFree(); + public Swap getSwap() { + return swap(); } public static OsStats readOsStats(StreamInput in) throws IOException { @@ -194,17 +114,15 @@ public class OsStats implements Streamable, Serializable { loadAverage[i] = in.readDouble(); } uptime = in.readLong(); - cpuSys = in.readDouble(); - cpuUser = in.readDouble(); - cpuIdle = in.readDouble(); - memFree = in.readLong(); - memFreePercent = in.readDouble(); - memUsed = in.readLong(); - memUsedPercent = in.readDouble(); - memActualFree = in.readLong(); - memActualUsed = in.readLong(); - swapFree = in.readLong(); - swapUsed = in.readLong(); + if (in.readBoolean()) { + cpu = Cpu.readCpu(in); + } + if (in.readBoolean()) { + mem = Mem.readMem(in); + } + if (in.readBoolean()) { + swap = Swap.readSwap(in); + } } @Override public void writeTo(StreamOutput out) throws IOException { @@ -214,16 +132,180 @@ public class OsStats implements Streamable, Serializable { out.writeDouble(val); } out.writeLong(uptime); - out.writeDouble(cpuSys); - out.writeDouble(cpuUser); - out.writeDouble(cpuIdle); - out.writeLong(memFree); - out.writeDouble(memFreePercent); - out.writeLong(memUsed); - out.writeDouble(memUsedPercent); - out.writeLong(memActualFree); - out.writeLong(memActualUsed); - out.writeLong(swapFree); - out.writeLong(swapFree); + if (cpu == null) { + out.writeBoolean(false); + } else { + out.writeBoolean(true); + cpu.writeTo(out); + } + if (mem == null) { + out.writeBoolean(false); + } else { + out.writeBoolean(true); + mem.writeTo(out); + } + if (swap == null) { + out.writeBoolean(false); + } else { + out.writeBoolean(true); + swap.writeTo(out); + } + } + + public static class Swap implements Streamable, Serializable { + + long free = -1; + long used = -1; + + public static Swap readSwap(StreamInput in) throws IOException { + Swap swap = new Swap(); + swap.readFrom(in); + return swap; + } + + @Override public void readFrom(StreamInput in) throws IOException { + free = in.readLong(); + used = in.readLong(); + } + + @Override public void writeTo(StreamOutput out) throws IOException { + out.writeLong(free); + out.writeLong(used); + } + } + + public static class Mem implements Streamable, Serializable { + + long free = -1; + double freePercent = -1; + long used = -1; + double usedPercent = -1; + long actualFree = -1; + long actualUsed = -1; + + public static Mem readMem(StreamInput in) throws IOException { + Mem mem = new Mem(); + mem.readFrom(in); + return mem; + } + + @Override public void readFrom(StreamInput in) throws IOException { + free = in.readLong(); + freePercent = in.readDouble(); + used = in.readLong(); + usedPercent = in.readDouble(); + actualFree = in.readLong(); + actualUsed = in.readLong(); + } + + @Override public void writeTo(StreamOutput out) throws IOException { + out.writeLong(free); + out.writeDouble(freePercent); + out.writeLong(used); + out.writeDouble(usedPercent); + out.writeLong(actualFree); + out.writeLong(actualUsed); + } + + public SizeValue used() { + return new SizeValue(used); + } + + public SizeValue getUsed() { + return used(); + } + + public Percent usedPercent() { + return new Percent(usedPercent); + } + + public Percent getUsedPercent() { + return usedPercent(); + } + + public SizeValue free() { + return new SizeValue(free); + } + + public SizeValue getFree() { + return free(); + } + + public Percent freePercent() { + return new Percent(freePercent); + } + + public Percent getFreePercent() { + return freePercent(); + } + + public SizeValue actualFree() { + return new SizeValue(actualFree); + } + + public SizeValue getActualFree() { + return actualFree(); + } + + public SizeValue actualUsed() { + return new SizeValue(actualUsed); + } + + public SizeValue getActualUsed() { + return actualUsed(); + } + } + + public static class Cpu implements Streamable, Serializable { + + double sys = -1; + double user = -1; + double idle = -1; + + Cpu() { + + } + + public static Cpu readCpu(StreamInput in) throws IOException { + Cpu cpu = new Cpu(); + cpu.readFrom(in); + return cpu; + } + + @Override public void readFrom(StreamInput in) throws IOException { + sys = in.readDouble(); + user = in.readDouble(); + idle = in.readDouble(); + } + + @Override public void writeTo(StreamOutput out) throws IOException { + out.writeDouble(sys); + out.writeDouble(user); + out.writeDouble(idle); + } + + public Percent sys() { + return new Percent(sys); + } + + public Percent getSys() { + return sys(); + } + + public Percent user() { + return new Percent(user); + } + + public Percent getUser() { + return user(); + } + + public Percent idle() { + return new Percent(idle); + } + + public Percent getIdle() { + return idle(); + } } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/SigarOsProbe.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/SigarOsProbe.java index c3807775b18..041331dbdc4 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/SigarOsProbe.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/SigarOsProbe.java @@ -42,14 +42,15 @@ public class SigarOsProbe extends AbstractComponent implements OsProbe { OsInfo info = new OsInfo(); try { CpuInfo[] infos = sigar.getCpuInfoList(); - info.cpuVendor = infos[0].getVendor(); - info.cpuModel = infos[0].getModel(); - info.cpuMhz = infos[0].getMhz(); - info.cpuTotalCores = infos[0].getTotalCores(); - info.cpuTotalSockets = infos[0].getTotalSockets(); - info.cpuCoresPerSocket = infos[0].getCoresPerSocket(); + info.cpu = new OsInfo.Cpu(); + info.cpu.vendor = infos[0].getVendor(); + info.cpu.model = infos[0].getModel(); + info.cpu.mhz = infos[0].getMhz(); + info.cpu.totalCores = infos[0].getTotalCores(); + info.cpu.totalSockets = infos[0].getTotalSockets(); + info.cpu.coresPerSocket = infos[0].getCoresPerSocket(); if (infos[0].getCacheSize() != Sigar.FIELD_NOTIMPL) { - info.cpuCacheSize = infos[0].getCacheSize(); + info.cpu.cacheSize = infos[0].getCacheSize(); } } catch (SigarException e) { // ignore @@ -57,14 +58,16 @@ public class SigarOsProbe extends AbstractComponent implements OsProbe { try { Mem mem = sigar.getMem(); - info.memTotal = mem.getTotal(); + info.mem = new OsInfo.Mem(); + info.mem.total = mem.getTotal(); } catch (SigarException e) { // ignore } try { Swap swap = sigar.getSwap(); - info.swapTotal = swap.getTotal(); + info.swap = new OsInfo.Swap(); + info.swap.total = swap.getTotal(); } catch (SigarException e) { // ignore } @@ -91,29 +94,32 @@ public class SigarOsProbe extends AbstractComponent implements OsProbe { try { CpuPerc cpuPerc = sigar.getCpuPerc(); - stats.cpuSys = cpuPerc.getSys(); - stats.cpuUser = cpuPerc.getUser(); - stats.cpuIdle = cpuPerc.getIdle(); + stats.cpu = new OsStats.Cpu(); + stats.cpu.sys = cpuPerc.getSys(); + stats.cpu.user = cpuPerc.getUser(); + stats.cpu.idle = cpuPerc.getIdle(); } catch (SigarException e) { // ignore } try { Mem mem = sigar.getMem(); - stats.memFree = mem.getFree(); - stats.memFreePercent = mem.getFreePercent() / 100; - stats.memUsed = mem.getUsed(); - stats.memUsedPercent = mem.getUsedPercent() / 100; - stats.memActualFree = mem.getActualFree(); - stats.memActualUsed = mem.getActualUsed(); + stats.mem = new OsStats.Mem(); + stats.mem.free = mem.getFree(); + stats.mem.freePercent = mem.getFreePercent() / 100; + stats.mem.used = mem.getUsed(); + stats.mem.usedPercent = mem.getUsedPercent() / 100; + stats.mem.actualFree = mem.getActualFree(); + stats.mem.actualUsed = mem.getActualUsed(); } catch (SigarException e) { // ignore } try { Swap swap = sigar.getSwap(); - stats.swapFree = swap.getFree(); - stats.swapUsed = swap.getUsed(); + stats.swap = new OsStats.Swap(); + stats.swap.free = swap.getFree(); + stats.swap.used = swap.getUsed(); } catch (SigarException e) { // ignore } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessStats.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessStats.java index bcdd9e19788..0feb2a986dd 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessStats.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessStats.java @@ -36,21 +36,11 @@ public class ProcessStats implements Streamable, Serializable { long timestamp = -1; - double cpuPercent = -1; + Cpu cpu = null; - long cpuSys = -1; + Mem mem = null; - long cpuUser = -1; - - long cpuTotal = -1; - - long memTotalVirtual = -1; - - long memResident = -1; - - long memShare = -1; - - long fd; + Fd fd; ProcessStats() { } @@ -63,112 +53,27 @@ public class ProcessStats implements Streamable, Serializable { return timestamp(); } - /** - * Get the Process cpu usage. - * - *

Supported Platforms: All. - */ - public Percent cpuPercent() { - return new Percent(cpuPercent); + public Cpu cpu() { + return cpu; } - /** - * Get the Process cpu usage. - * - *

Supported Platforms: All. - */ - public Percent getCpuPercent() { - return cpuPercent(); + public Cpu getCpu() { + return cpu(); } - /** - * Get the Process cpu kernel time. - * - *

Supported Platforms: All. - */ - public TimeValue cpuSys() { - return new TimeValue(cpuSys); + public Mem mem() { + return mem; } - /** - * Get the Process cpu kernel time. - * - *

Supported Platforms: All. - */ - public TimeValue getCpuSys() { - return cpuSys(); + public Mem getMem() { + return mem(); } - /** - * Get the Process cpu user time. - * - *

Supported Platforms: All. - */ - public TimeValue cpuUser() { - return new TimeValue(cpuUser); - } - - /** - * Get the Process cpu time (sum of User and Sys). - * - * Supported Platforms: All. - */ - public TimeValue cpuTotal() { - return new TimeValue(cpuTotal); - } - - /** - * Get the Process cpu time (sum of User and Sys). - * - * Supported Platforms: All. - */ - public TimeValue getCpuTotal() { - return cpuTotal(); - } - - /** - * Get the Process cpu user time. - * - *

Supported Platforms: All. - */ - public TimeValue getCpuUser() { - return cpuUser(); - } - - public SizeValue memTotalVirtual() { - return new SizeValue(memTotalVirtual); - } - - public SizeValue getMemTotalVirtual() { - return memTotalVirtual(); - } - - public SizeValue memResident() { - return new SizeValue(memResident); - } - - public SizeValue getMemResident() { - return memResident(); - } - - public SizeValue memShare() { - return new SizeValue(memShare); - } - - public SizeValue getMemShare() { - return memShare(); - } - - /** - * Get the Total number of open file descriptors. - * - *

Supported Platforms: AIX, HPUX, Linux, Solaris, Win32. - */ - public long fd() { + public Fd fd() { return fd; } - public long getFd() { + public Fd getFd() { return fd(); } @@ -180,25 +85,228 @@ public class ProcessStats implements Streamable, Serializable { @Override public void readFrom(StreamInput in) throws IOException { timestamp = in.readVLong(); - cpuPercent = in.readDouble(); - cpuSys = in.readLong(); - cpuUser = in.readLong(); - cpuTotal = in.readLong(); - memTotalVirtual = in.readLong(); - memResident = in.readLong(); - memShare = in.readLong(); - fd = in.readLong(); + if (in.readBoolean()) { + cpu = Cpu.readCpu(in); + } + if (in.readBoolean()) { + mem = Mem.readMem(in); + } + if (in.readBoolean()) { + fd = Fd.readFd(in); + } } @Override public void writeTo(StreamOutput out) throws IOException { out.writeVLong(timestamp); - out.writeDouble(cpuPercent); - out.writeLong(cpuSys); - out.writeLong(cpuUser); - out.writeLong(cpuTotal); - out.writeLong(memTotalVirtual); - out.writeLong(memResident); - out.writeLong(memShare); - out.writeLong(fd); + if (cpu == null) { + out.writeBoolean(false); + } else { + out.writeBoolean(true); + cpu.writeTo(out); + } + if (mem == null) { + out.writeBoolean(false); + } else { + out.writeBoolean(true); + 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. + * + *

Supported Platforms: AIX, HPUX, Linux, Solaris, Win32. + */ + public long total() { + return total; + } + + public long getTotal() { + return total(); + } + } + + public static class Mem implements Streamable, Serializable { + + long totalVirtual = -1; + long resident = -1; + long share = -1; + + Mem() { + } + + public static Mem readMem(StreamInput in) throws IOException { + Mem mem = new Mem(); + mem.readFrom(in); + return mem; + } + + @Override public void readFrom(StreamInput in) throws IOException { + totalVirtual = in.readLong(); + resident = in.readLong(); + share = in.readLong(); + } + + @Override public void writeTo(StreamOutput out) throws IOException { + out.writeLong(totalVirtual); + out.writeLong(resident); + out.writeLong(share); + } + + public SizeValue totalVirtual() { + return new SizeValue(totalVirtual); + } + + public SizeValue getTotalVirtual() { + return totalVirtual(); + } + + public SizeValue resident() { + return new SizeValue(resident); + } + + public SizeValue getResident() { + return resident(); + } + + public SizeValue share() { + return new SizeValue(share); + } + + public SizeValue getShare() { + return share(); + } + } + + public static class Cpu implements Streamable, Serializable { + + double percent = -1; + long sys = -1; + long user = -1; + long total = -1; + + Cpu() { + + } + + public static Cpu readCpu(StreamInput in) throws IOException { + Cpu cpu = new Cpu(); + cpu.readFrom(in); + return cpu; + } + + @Override public void readFrom(StreamInput in) throws IOException { + percent = in.readDouble(); + sys = in.readLong(); + user = in.readLong(); + total = in.readLong(); + } + + @Override public void writeTo(StreamOutput out) throws IOException { + out.writeDouble(percent); + out.writeLong(sys); + out.writeLong(user); + out.writeLong(total); + } + + /** + * Get the Process cpu usage. + * + *

Supported Platforms: All. + */ + public Percent percent() { + return new Percent(percent); + } + + /** + * Get the Process cpu usage. + * + *

Supported Platforms: All. + */ + public Percent getPercent() { + return percent(); + } + + /** + * Get the Process cpu kernel time. + * + *

Supported Platforms: All. + */ + public TimeValue sys() { + return new TimeValue(sys); + } + + /** + * Get the Process cpu kernel time. + * + *

Supported Platforms: All. + */ + public TimeValue getSys() { + return sys(); + } + + /** + * Get the Process cpu user time. + * + *

Supported Platforms: All. + */ + public TimeValue user() { + return new TimeValue(user); + } + + /** + * Get the Process cpu time (sum of User and Sys). + * + * Supported Platforms: All. + */ + public TimeValue total() { + return new TimeValue(total); + } + + /** + * Get the Process cpu time (sum of User and Sys). + * + * Supported Platforms: All. + */ + public TimeValue getTotal() { + return total(); + } + + /** + * Get the Process cpu user time. + * + *

Supported Platforms: All. + */ + public TimeValue getUser() { + return user(); + } + } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/SigarProcessProbe.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/SigarProcessProbe.java index 8c14fb85630..ea7805e8855 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/SigarProcessProbe.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/SigarProcessProbe.java @@ -45,28 +45,33 @@ public class SigarProcessProbe extends AbstractComponent implements ProcessProbe Sigar sigar = sigarService.sigar(); ProcessStats stats = new ProcessStats(); stats.timestamp = System.currentTimeMillis(); - + try { ProcCpu cpu = sigar.getProcCpu(sigar.getPid()); - stats.cpuPercent = cpu.getPercent(); - stats.cpuSys = cpu.getSys(); - stats.cpuUser = cpu.getUser(); + stats.cpu = new ProcessStats.Cpu(); + stats.cpu.percent = cpu.getPercent(); + stats.cpu.sys = cpu.getSys(); + stats.cpu.user = cpu.getUser(); } catch (SigarException e) { // ignore } try { ProcMem mem = sigar.getProcMem(sigar.getPid()); - stats.memTotalVirtual = mem.getSize(); - stats.memResident = mem.getResident(); - stats.memShare = mem.getShare(); + stats.mem = new ProcessStats.Mem(); + stats.mem.totalVirtual = mem.getSize(); + stats.mem.resident = mem.getResident(); + stats.mem.share = mem.getShare(); } catch (SigarException e) { // ignore } try { ProcFd fd = sigar.getProcFd(sigar.getPid()); - stats.fd = fd.getTotal(); + if (fd.getTotal() != Sigar.FIELD_NOTIMPL) { + stats.fd = new ProcessStats.Fd(); + stats.fd.total = fd.getTotal(); + } } catch (SigarException e) { // ignore }