From b54f6b77ded19bba0eb62b285d899d87fa9679e4 Mon Sep 17 00:00:00 2001 From: kimchy Date: Thu, 6 May 2010 23:46:53 +0300 Subject: [PATCH] add os level stats and info (still some more info left...) --- .idea/dictionaries/kimchy.xml | 1 + .../elasticsearch/monitor/MonitorModule.java | 7 + .../elasticsearch/monitor/os/JmxOsProbe.java | 44 ++++ .../org/elasticsearch/monitor/os/OsInfo.java | 157 ++++++++++++ .../org/elasticsearch/monitor/os/OsProbe.java | 30 +++ .../elasticsearch/monitor/os/OsService.java | 51 ++++ .../org/elasticsearch/monitor/os/OsStats.java | 229 ++++++++++++++++++ .../monitor/os/SigarOsProbe.java | 123 ++++++++++ .../monitor/process/JmxProcessProbe.java | Bin 1519 -> 1579 bytes .../monitor/process/ProcessInfo.java | 2 +- .../monitor/process/ProcessStats.java | 51 +++- .../monitor/process/SigarProcessProbe.java | 5 +- 12 files changed, 696 insertions(+), 4 deletions(-) create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/JmxOsProbe.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsInfo.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsProbe.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsService.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsStats.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/SigarOsProbe.java diff --git a/.idea/dictionaries/kimchy.xml b/.idea/dictionaries/kimchy.xml index 1b4e0735a35..17cab7523fa 100644 --- a/.idea/dictionaries/kimchy.xml +++ b/.idea/dictionaries/kimchy.xml @@ -21,6 +21,7 @@ committable configurator coord + cpus datagram desc deserialize 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 b513a3f6385..4c1dcb059c7 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.os.JmxOsProbe; +import org.elasticsearch.monitor.os.OsProbe; +import org.elasticsearch.monitor.os.OsService; +import org.elasticsearch.monitor.os.SigarOsProbe; import org.elasticsearch.monitor.process.JmxProcessProbe; import org.elasticsearch.monitor.process.ProcessProbe; import org.elasticsearch.monitor.process.ProcessService; @@ -76,6 +80,7 @@ public class MonitorModule extends AbstractModule { if (sigarService.sigarAvailable()) { bind(SigarService.class).toInstance(sigarService); bind(ProcessProbe.class).to(SigarProcessProbe.class).asEagerSingleton(); + bind(OsProbe.class).to(SigarOsProbe.class).asEagerSingleton(); sigarLoaded = true; } } catch (Throwable e) { @@ -84,9 +89,11 @@ public class MonitorModule extends AbstractModule { if (!sigarLoaded) { // bind non sigar implementations bind(ProcessProbe.class).to(JmxProcessProbe.class).asEagerSingleton(); + bind(OsProbe.class).to(JmxOsProbe.class).asEagerSingleton(); } // bind other services bind(ProcessService.class).asEagerSingleton(); + bind(OsService.class).asEagerSingleton(); bind(JvmService.class).asEagerSingleton(); bind(JvmMonitorService.class).asEagerSingleton(); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/JmxOsProbe.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/JmxOsProbe.java new file mode 100644 index 00000000000..d6c66fa91bd --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/JmxOsProbe.java @@ -0,0 +1,44 @@ +/* + * 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.os; + +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 JmxOsProbe extends AbstractComponent implements OsProbe { + + @Inject public JmxOsProbe(Settings settings) { + super(settings); + } + + @Override public OsInfo osInfo() { + return new OsInfo(); + } + + @Override public OsStats osStats() { + OsStats stats = new OsStats(); + stats.timestamp = System.currentTimeMillis(); + 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 new file mode 100644 index 00000000000..7a59c5d2233 --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsInfo.java @@ -0,0 +1,157 @@ +/* + * 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.os; + +import org.elasticsearch.util.SizeValue; +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 OsInfo implements Streamable, Serializable { + + String cpuVendor = ""; + + String cpuModel = ""; + + int cpuMhz = -1; + + int cpuTotalCores = -1; + + int cpuTotalSockets = -1; + + int cpuCoresPerSocket = -1; + + long cpuCacheSize = -1; + + long memTotal = -1; + + long swapTotal = -1; + + OsInfo() { + } + + public String cpuVendor() { + return cpuVendor; + } + + public String getCpuVendor() { + return cpuVendor(); + } + + public String cpuModel() { + return cpuModel; + } + + public String getCpuModel() { + return cpuModel(); + } + + public int cpuMhz() { + return cpuMhz; + } + + 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 static OsInfo readOsInfo(StreamInput in) throws IOException { + OsInfo info = new OsInfo(); + info.readFrom(in); + return info; + } + + @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(); + } + + @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); + } +} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsProbe.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsProbe.java new file mode 100644 index 00000000000..4a34e72a76b --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsProbe.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.os; + +/** + * @author kimchy (shay.banon) + */ +public interface OsProbe { + + OsInfo osInfo(); + + OsStats osStats(); +} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsService.java new file mode 100644 index 00000000000..179fd8626d2 --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsService.java @@ -0,0 +1,51 @@ +/* + * 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.os; + +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 OsService extends AbstractComponent { + + private final OsProbe probe; + + private final OsInfo info; + + @Inject public OsService(Settings settings, OsProbe probe) { + super(settings); + this.probe = probe; + + this.info = probe.osInfo(); + + logger.trace("Using probe [{}]", probe); + } + + public OsInfo info() { + return this.info; + } + + public OsStats stats() { + return probe.osStats(); + } +} 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 new file mode 100644 index 00000000000..9780f25898e --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsStats.java @@ -0,0 +1,229 @@ +/* + * 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.os; + +import org.elasticsearch.util.Percent; +import org.elasticsearch.util.SizeValue; +import org.elasticsearch.util.TimeValue; +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; +import java.util.concurrent.TimeUnit; + +/** + * @author kimchy (shay.banon) + */ +public class OsStats implements Streamable, Serializable { + + public static final double[] EMPTY_LOAD = new double[0]; + + + long timestamp; + + double[] loadAverage = EMPTY_LOAD; + + long uptime = -1; + + double cpuSys = -1; + + double cpuUser = -1; + + 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; + + OsStats() { + } + + public long timestamp() { + return timestamp; + } + + public long getTimestamp() { + return timestamp(); + } + + public double[] loadAverage() { + return loadAverage; + } + + public double[] getLoadAverage() { + return loadAverage(); + } + + public TimeValue uptime() { + return new TimeValue(uptime, TimeUnit.SECONDS); + } + + public TimeValue getUptime() { + return uptime(); + } + + public Percent cpuSys() { + return new Percent(cpuSys); + } + + public Percent getCpuSys() { + return cpuSys(); + } + + public Percent cpuUser() { + return new Percent(cpuUser); + } + + public Percent getCpuUser() { + return cpuUser(); + } + + public Percent cpuIdle() { + return new Percent(cpuIdle); + } + + 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 static OsStats readOsStats(StreamInput in) throws IOException { + OsStats stats = new OsStats(); + stats.readFrom(in); + return stats; + } + + @Override public void readFrom(StreamInput in) throws IOException { + timestamp = in.readVLong(); + loadAverage = new double[in.readVInt()]; + for (int i = 0; i < loadAverage.length; i++) { + 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(); + } + + @Override public void writeTo(StreamOutput out) throws IOException { + out.writeVLong(timestamp); + out.writeVInt(loadAverage.length); + for (double val : loadAverage) { + 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); + } +} 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 new file mode 100644 index 00000000000..c3807775b18 --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/SigarOsProbe.java @@ -0,0 +1,123 @@ +/* + * 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.os; + +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.*; + +/** + * @author kimchy (shay.banon) + */ +public class SigarOsProbe extends AbstractComponent implements OsProbe { + + private final SigarService sigarService; + + @Inject public SigarOsProbe(Settings settings, SigarService sigarService) { + super(settings); + this.sigarService = sigarService; + } + + @Override public OsInfo osInfo() { + Sigar sigar = sigarService.sigar(); + 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(); + if (infos[0].getCacheSize() != Sigar.FIELD_NOTIMPL) { + info.cpuCacheSize = infos[0].getCacheSize(); + } + } catch (SigarException e) { + // ignore + } + + try { + Mem mem = sigar.getMem(); + info.memTotal = mem.getTotal(); + } catch (SigarException e) { + // ignore + } + + try { + Swap swap = sigar.getSwap(); + info.swapTotal = swap.getTotal(); + } catch (SigarException e) { + // ignore + } + + + return info; + } + + @Override public OsStats osStats() { + Sigar sigar = sigarService.sigar(); + OsStats stats = new OsStats(); + stats.timestamp = System.currentTimeMillis(); + try { + stats.loadAverage = sigar.getLoadAverage(); + } catch (SigarException e) { + // ignore + } + + try { + stats.uptime = (long) sigar.getUptime().getUptime(); + } catch (SigarException e) { + // ignore + } + + try { + CpuPerc cpuPerc = sigar.getCpuPerc(); + stats.cpuSys = cpuPerc.getSys(); + stats.cpuUser = cpuPerc.getUser(); + stats.cpuIdle = 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(); + } catch (SigarException e) { + // ignore + } + + try { + Swap swap = sigar.getSwap(); + stats.swapFree = swap.getFree(); + stats.swapUsed = swap.getUsed(); + } catch (SigarException e) { + // ignore + } + + return stats; + } +} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/JmxProcessProbe.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/JmxProcessProbe.java index 1cb4503f87de149638087fca61f34367c36f1030..88b035287e1e3d00cea2118569b386df8190f716 100644 GIT binary patch delta 73 zcmaFQy_#o33nL!`gVX!{dl}e(1Q2cRVf1CuEG|hbDb_2=%uNNdatjn}6@n{^OHy<7 Yl1qz30A@~ delta 25 gcmZ3@^PYP{3nPbuLS%laLT=*bNsPWMlSSFY0C0W>wEzGB diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessInfo.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessInfo.java index 65a5c83ea6d..08d9c46d546 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessInfo.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessInfo.java @@ -33,7 +33,7 @@ public class ProcessInfo implements Streamable, Serializable { private long id; - private ProcessInfo() { + ProcessInfo() { } 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 74bacb113db..bcdd9e19788 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 @@ -22,11 +22,19 @@ package org.elasticsearch.monitor.process; import org.elasticsearch.util.Percent; import org.elasticsearch.util.SizeValue; import org.elasticsearch.util.TimeValue; +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 ProcessStats { +public class ProcessStats implements Streamable, Serializable { + + long timestamp = -1; double cpuPercent = -1; @@ -44,6 +52,17 @@ public class ProcessStats { long fd; + ProcessStats() { + } + + public long timestamp() { + return this.timestamp; + } + + public long getTimestamp() { + return timestamp(); + } + /** * Get the Process cpu usage. * @@ -152,4 +171,34 @@ public class ProcessStats { public long getFd() { return fd(); } + + public static ProcessStats readProcessStats(StreamInput in) throws IOException { + ProcessStats stats = new ProcessStats(); + stats.readFrom(in); + return stats; + } + + @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(); + } + + @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); + } } 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 77752269fb9..8c14fb85630 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 @@ -37,13 +37,14 @@ public class SigarProcessProbe extends AbstractComponent implements ProcessProbe this.sigarService = sigarService; } - @Override public ProcessInfo processInfo() { + @Override public synchronized ProcessInfo processInfo() { return new ProcessInfo(sigarService.sigar().getPid()); } - @Override public ProcessStats processStats() { + @Override public synchronized ProcessStats processStats() { Sigar sigar = sigarService.sigar(); ProcessStats stats = new ProcessStats(); + stats.timestamp = System.currentTimeMillis(); try { ProcCpu cpu = sigar.getProcCpu(sigar.getPid());