initial support for process monitoring using sigar

This commit is contained in:
kimchy 2010-05-06 21:07:24 +03:00
parent 5603c4d09c
commit 371bfebd16
40 changed files with 807 additions and 34 deletions

View File

@ -29,7 +29,10 @@
<w>flushable</w>
<w>formatter</w>
<w>formatters</w>
<w>frac</w>
<w>freqs</w>
<w>hpux</w>
<w>hyperic</w>
<w>indices</w>
<w>inet</w>
<w>infos</w>
@ -69,7 +72,9 @@
<w>sbuf</w>
<w>searchable</w>
<w>serializers</w>
<w>sigar</w>
<w>snapshotting</w>
<w>solaris</w>
<w>stopwords</w>
<w>streamable</w>
<w>successul</w>
@ -84,6 +89,7 @@
<w>tuple</w>
<w>unicast</w>
<w>unregister</w>
<w>uptime</w>
<w>uuid</w>
<w>versioned</w>
<w>wildcards</w>

View File

@ -28,6 +28,15 @@
</orderEntry>
<orderEntry type="library" exported="" name="jline" level="project" />
<orderEntry type="library" exported="" name="netty" level="project" />
<orderEntry type="module-library" exported="">
<library name="sigar">
<CLASSES>
<root url="jar://$MODULE_DIR$/../../lib/sigar/sigar-1.6.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" scope="TEST" name="testng" level="project" />
<orderEntry type="library" scope="TEST" name="hamcrest" level="project" />
<orderEntry type="module" module-name="test-testng" scope="TEST" />

Binary file not shown.

View File

@ -1,4 +1,4 @@
CLASSPATH=$CLASSPATH:$ES_HOME/lib/*
CLASSPATH=$CLASSPATH:$ES_HOME/lib/*:$ES_HOME/lib/sigar/*
if [ "x$ES_MIN_MEM" = "x" ]; then
ES_MIN_MEM=256

View File

@ -64,6 +64,7 @@ task explodedDist(dependsOn: [configurations.distLib], description: 'Builds a mi
copy { from('bin'); into explodedDistBinDir }
copy { from('config'); into explodedDistConfigDir }
copy { from('lib'); into explodedDistLibDir }
copy {
from('.')
@ -79,6 +80,7 @@ task explodedDist(dependsOn: [configurations.distLib], description: 'Builds a mi
ant.delete { fileset(dir: explodedDistLibDir, includes: "jackson-*.jar") } // no need jackson, we jarjar it
ant.delete { fileset(dir: explodedDistLibDir, includes: "joda-*.jar") } // no need joda, we jarjar it
ant.delete { fileset(dir: explodedDistLibDir, includes: "snakeyaml-*.jar") } // no need snakeyaml, we jarjar it
ant.delete { fileset(dir: explodedDistLibDir, includes: "sigar-*.jar") } // no need sigar directly under lib...
ant.chmod(dir: "$explodedDistDir/bin", perm: "ugo+rx", includes: "**/*")
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
lib/sigar/sigar-1.6.3.jar Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -17,7 +17,6 @@ processResources.doLast {
}
}
manifest.mainAttributes("Implementation-Title": "ElasticSearch", "Implementation-Version": rootProject.version, "Implementation-Date": buildTimeStr)
// no need to use the resource dir
@ -26,6 +25,7 @@ sourceSets.test.resources.srcDirs 'src/test/java'
dependencies {
compile('jline:jline:0.9.94') { transitive = false }
compile files(rootProject.file("lib/sigar/sigar-1.6.3.jar").absolutePath)
compile 'org.slf4j:slf4j-api:1.5.11'
compile('org.slf4j:slf4j-log4j12:1.5.11') { transitive = false }

View File

@ -19,7 +19,7 @@
package org.elasticsearch;
import org.elasticsearch.monitor.jvm.JvmConfig;
import org.elasticsearch.monitor.jvm.JvmInfo;
import java.io.InputStream;
import java.text.SimpleDateFormat;
@ -76,6 +76,6 @@ public class Version {
}
public static void main(String[] args) {
System.out.println("ElasticSearch Version: " + number + " (" + date() + "), JVM: " + JvmConfig.jvmConfig().vmVersion());
System.out.println("ElasticSearch Version: " + number + " (" + date() + "), JVM: " + JvmInfo.jvmInfo().vmVersion());
}
}

View File

@ -19,10 +19,6 @@
package org.elasticsearch.monitor;
import org.elasticsearch.util.guice.inject.AbstractModule;
import org.elasticsearch.util.guice.inject.Scopes;
import org.elasticsearch.util.guice.inject.assistedinject.FactoryProvider;
import org.elasticsearch.util.guice.inject.multibindings.MapBinder;
import org.elasticsearch.monitor.dump.DumpContributorFactory;
import org.elasticsearch.monitor.dump.DumpMonitorService;
import org.elasticsearch.monitor.dump.cluster.ClusterDumpContributor;
@ -30,9 +26,19 @@ import org.elasticsearch.monitor.dump.heap.HeapDumpContributor;
import org.elasticsearch.monitor.dump.summary.SummaryDumpContributor;
import org.elasticsearch.monitor.dump.thread.ThreadDumpContributor;
import org.elasticsearch.monitor.jvm.JvmMonitorService;
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.process.JmxProcessProbe;
import org.elasticsearch.monitor.process.ProcessProbe;
import org.elasticsearch.monitor.process.ProcessService;
import org.elasticsearch.monitor.process.SigarProcessProbe;
import org.elasticsearch.monitor.sigar.SigarService;
import org.elasticsearch.util.guice.inject.AbstractModule;
import org.elasticsearch.util.guice.inject.Scopes;
import org.elasticsearch.util.guice.inject.assistedinject.FactoryProvider;
import org.elasticsearch.util.guice.inject.multibindings.MapBinder;
import org.elasticsearch.util.settings.Settings;
import java.util.Map;
@ -63,6 +69,26 @@ public class MonitorModule extends AbstractModule {
.asEagerSingleton();
bind(MemoryMonitorService.class).asEagerSingleton();
boolean sigarLoaded = false;
try {
settings.getClassLoader().loadClass("org.hyperic.sigar.Sigar");
SigarService sigarService = new SigarService(settings);
if (sigarService.sigarAvailable()) {
bind(SigarService.class).toInstance(sigarService);
bind(ProcessProbe.class).to(SigarProcessProbe.class).asEagerSingleton();
sigarLoaded = true;
}
} catch (Throwable e) {
// no sigar
}
if (!sigarLoaded) {
// bind non sigar implementations
bind(ProcessProbe.class).to(JmxProcessProbe.class).asEagerSingleton();
}
// bind other services
bind(ProcessService.class).asEagerSingleton();
bind(JvmService.class).asEagerSingleton();
bind(JvmMonitorService.class).asEagerSingleton();
MapBinder<String, DumpContributorFactory> tokenFilterBinder

View File

@ -33,11 +33,11 @@ import java.util.HashMap;
import java.util.Map;
/**
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
public class JvmConfig implements Streamable, Serializable {
public class JvmInfo implements Streamable, Serializable {
private static JvmConfig INSTANCE;
private static JvmInfo INSTANCE;
static {
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
@ -52,14 +52,14 @@ public class JvmConfig implements Streamable, Serializable {
} catch (Exception e) {
pid = -1;
}
INSTANCE = new JvmConfig(pid, runtimeMXBean.getVmName(), System.getProperty("java.version"), System.getProperty("java.vendor"),
INSTANCE = new JvmInfo(pid, runtimeMXBean.getVmName(), System.getProperty("java.version"), System.getProperty("java.vendor"),
runtimeMXBean.getStartTime(),
memoryMXBean.getHeapMemoryUsage().getInit(), memoryMXBean.getHeapMemoryUsage().getMax(),
memoryMXBean.getNonHeapMemoryUsage().getInit(), memoryMXBean.getNonHeapMemoryUsage().getMax(),
runtimeMXBean.getInputArguments().toArray(new String[runtimeMXBean.getInputArguments().size()]), runtimeMXBean.getBootClassPath(), runtimeMXBean.getClassPath(), runtimeMXBean.getSystemProperties());
}
public static JvmConfig jvmConfig() {
public static JvmInfo jvmInfo() {
return INSTANCE;
}
@ -89,12 +89,12 @@ public class JvmConfig implements Streamable, Serializable {
private Map<String, String> systemProperties;
private JvmConfig() {
private JvmInfo() {
}
public JvmConfig(long pid, String vmName, String vmVersion, String vmVendor, long startTime,
long memoryHeapInit, long memoryHeapMax, long memoryNonHeapInit, long memoryNonHeapMax,
String[] inputArguments, String bootClassPath, String classPath, Map<String, String> systemProperties) {
public JvmInfo(long pid, String vmName, String vmVersion, String vmVendor, long startTime,
long memoryHeapInit, long memoryHeapMax, long memoryNonHeapInit, long memoryNonHeapMax,
String[] inputArguments, String bootClassPath, String classPath, Map<String, String> systemProperties) {
this.pid = pid;
this.vmName = vmName;
this.vmVersion = vmVersion;
@ -110,62 +110,120 @@ public class JvmConfig implements Streamable, Serializable {
this.systemProperties = systemProperties;
}
/**
* The process id.
*/
public long pid() {
return this.pid;
}
/**
* The process id.
*/
public long getPid() {
return pid;
}
public String vmName() {
return vmName;
}
public String getVmName() {
return vmName;
}
public String vmVersion() {
return vmVersion;
}
public String getVmVersion() {
return vmVersion;
}
public String vmVendor() {
return vmVendor;
}
public String getVmVendor() {
return vmVendor;
}
public long startTime() {
return startTime;
}
public long getStartTime() {
return startTime;
}
public SizeValue memoryHeapInit() {
return new SizeValue(memoryHeapInit);
}
public SizeValue getMemoryHeapInit() {
return memoryHeapInit();
}
public SizeValue memoryHeapMax() {
return new SizeValue(memoryHeapMax);
}
public SizeValue getMemoryHeapMax() {
return memoryHeapMax();
}
public SizeValue memoryNonHeapInit() {
return new SizeValue(memoryNonHeapInit);
}
public SizeValue getMemoryNonHeapInit() {
return memoryNonHeapInit();
}
public SizeValue memoryNonHeapMax() {
return new SizeValue(memoryNonHeapMax);
}
public SizeValue getMemoryNonHeapMax() {
return memoryNonHeapMax();
}
public String[] inputArguments() {
return inputArguments;
}
public String[] getInputArguments() {
return inputArguments;
}
public String bootClassPath() {
return bootClassPath;
}
public String getBootClassPath() {
return bootClassPath;
}
public String classPath() {
return classPath;
}
public String getClassPath() {
return classPath;
}
public Map<String, String> systemProperties() {
return systemProperties;
}
public static JvmConfig readJvmComing(StreamInput in) throws IOException {
JvmConfig jvmConfig = new JvmConfig();
jvmConfig.readFrom(in);
return jvmConfig;
public Map<String, String> getSystemProperties() {
return systemProperties;
}
public static JvmInfo readJvmInfo(StreamInput in) throws IOException {
JvmInfo jvmInfo = new JvmInfo();
jvmInfo.readFrom(in);
return jvmInfo;
}
@Override public void readFrom(StreamInput in) throws IOException {

View File

@ -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.jvm;
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 JvmService extends AbstractComponent {
private final JvmInfo jvmInfo;
@Inject public JvmService(Settings settings) {
super(settings);
this.jvmInfo = JvmInfo.jvmInfo();
}
public JvmInfo info() {
return this.jvmInfo;
}
public JvmStats state() {
return JvmStats.jvmStats();
}
}

View File

@ -32,7 +32,7 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
public class JvmStats implements Streamable, Serializable {
@ -108,42 +108,82 @@ public class JvmStats implements Streamable, Serializable {
return timestamp;
}
public long uptime() {
return uptime;
public long getTimestamp() {
return timestamp;
}
public TimeValue uptime() {
return new TimeValue(uptime);
}
public TimeValue getUptime() {
return uptime();
}
public SizeValue memoryHeapCommitted() {
return new SizeValue(memoryHeapCommitted);
}
public SizeValue getMemoryHeapCommitted() {
return memoryHeapCommitted();
}
public SizeValue memoryHeapUsed() {
return new SizeValue(memoryHeapUsed);
}
public SizeValue getMemoryHeapUsed() {
return memoryHeapUsed();
}
public SizeValue memoryNonHeapCommitted() {
return new SizeValue(memoryNonHeapCommitted);
}
public SizeValue getMemoryNonHeapCommitted() {
return memoryNonHeapCommitted();
}
public SizeValue memoryNonHeapUsed() {
return new SizeValue(memoryNonHeapUsed);
}
public SizeValue getMemoryNonHeapUsed() {
return memoryNonHeapUsed();
}
public int threadCount() {
return threadCount;
}
public int getThreadCount() {
return threadCount;
}
public int peakThreadCount() {
return peakThreadCount;
}
public int getPeakThreadCount() {
return peakThreadCount;
}
public long gcCollectionCount() {
return gcCollectionCount;
}
public long getGcCollectionCount() {
return gcCollectionCount;
}
public TimeValue gcCollectionTime() {
return new TimeValue(gcCollectionTime, TimeUnit.MILLISECONDS);
}
public TimeValue getGcCollectionTime() {
return gcCollectionTime();
}
public static JvmStats readJvmStats(StreamInput in) throws IOException {
JvmStats jvmStats = new JvmStats();
jvmStats.readFrom(in);

View File

@ -0,0 +1,71 @@
/*
* 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.process;
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 ProcessInfo implements Streamable, Serializable {
private long id;
private ProcessInfo() {
}
public ProcessInfo(long id) {
this.id = id;
}
/**
* The process id.
*/
public long id() {
return this.id;
}
/**
* The process id.
*/
public long getId() {
return id();
}
public static ProcessInfo readProcessInfo(StreamInput in) throws IOException {
ProcessInfo info = new ProcessInfo();
info.readFrom(in);
return info;
}
@Override public void readFrom(StreamInput in) throws IOException {
id = in.readLong();
}
@Override public void writeTo(StreamOutput out) throws IOException {
out.writeLong(id);
}
}

View File

@ -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.process;
/**
* @author kimchy (shay.banon)
*/
public interface ProcessProbe {
ProcessInfo processInfo();
ProcessStats processStats();
}

View File

@ -0,0 +1,50 @@
/*
* 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.process;
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 ProcessService extends AbstractComponent {
private final ProcessProbe probe;
private final ProcessInfo info;
@Inject public ProcessService(Settings settings, ProcessProbe probe) {
super(settings);
this.probe = probe;
this.info = probe.processInfo();
logger.trace("Using probe [{}]", probe);
}
public ProcessInfo info() {
return this.info;
}
public ProcessStats stats() {
return probe.processStats();
}
}

View File

@ -0,0 +1,155 @@
/*
* 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.process;
import org.elasticsearch.util.Percent;
import org.elasticsearch.util.SizeValue;
import org.elasticsearch.util.TimeValue;
/**
* @author kimchy (shay.banon)
*/
public class ProcessStats {
double cpuPercent = -1;
long cpuSys = -1;
long cpuUser = -1;
long cpuTotal = -1;
long memTotalVirtual = -1;
long memResident = -1;
long memShare = -1;
long fd;
/**
* Get the Process cpu usage.
*
* <p>Supported Platforms: All.
*/
public Percent cpuPercent() {
return new Percent(cpuPercent);
}
/**
* Get the Process cpu usage.
*
* <p>Supported Platforms: All.
*/
public Percent getCpuPercent() {
return cpuPercent();
}
/**
* Get the Process cpu kernel time.
*
* <p>Supported Platforms: All.
*/
public TimeValue cpuSys() {
return new TimeValue(cpuSys);
}
/**
* Get the Process cpu kernel time.
*
* <p>Supported Platforms: All.
*/
public TimeValue getCpuSys() {
return cpuSys();
}
/**
* Get the Process cpu user time.
*
* <p>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.
*
* <p>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.
*
* <p>Supported Platforms: AIX, HPUX, Linux, Solaris, Win32.
*/
public long fd() {
return fd;
}
public long getFd() {
return fd();
}
}

View File

@ -0,0 +1,75 @@
/*
* 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.process;
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 SigarProcessProbe extends AbstractComponent implements ProcessProbe {
private final SigarService sigarService;
@Inject public SigarProcessProbe(Settings settings, SigarService sigarService) {
super(settings);
this.sigarService = sigarService;
}
@Override public ProcessInfo processInfo() {
return new ProcessInfo(sigarService.sigar().getPid());
}
@Override public ProcessStats processStats() {
Sigar sigar = sigarService.sigar();
ProcessStats stats = new ProcessStats();
try {
ProcCpu cpu = sigar.getProcCpu(sigar.getPid());
stats.cpuPercent = cpu.getPercent();
stats.cpuSys = cpu.getSys();
stats.cpuUser = 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();
} catch (SigarException e) {
// ignore
}
try {
ProcFd fd = sigar.getProcFd(sigar.getPid());
stats.fd = fd.getTotal();
} catch (SigarException e) {
// ignore
}
return stats;
}
}

View File

@ -0,0 +1,64 @@
/*
* 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.sigar;
import org.elasticsearch.util.component.AbstractComponent;
import org.elasticsearch.util.guice.inject.Inject;
import org.elasticsearch.util.settings.Settings;
import org.hyperic.sigar.Sigar;
/**
* @author kimchy (shay.banon)
*/
public class SigarService extends AbstractComponent {
private final Sigar sigar;
@Inject public SigarService(Settings settings) {
super(settings);
Sigar sigar = null;
try {
sigar = new Sigar();
// call it to make sure the library was loaded
sigar.getPid();
} catch (Throwable t) {
logger.debug("Failed to load sigar", t);
if (sigar != null) {
try {
sigar.close();
} catch (Throwable t1) {
// ignore
} finally {
sigar = null;
}
}
}
this.sigar = sigar;
}
public boolean sigarAvailable() {
return sigar != null;
}
public Sigar sigar() {
return this.sigar;
}
}

View File

@ -43,7 +43,7 @@ import org.elasticsearch.jmx.JmxModule;
import org.elasticsearch.jmx.JmxService;
import org.elasticsearch.monitor.MonitorModule;
import org.elasticsearch.monitor.MonitorService;
import org.elasticsearch.monitor.jvm.JvmConfig;
import org.elasticsearch.monitor.jvm.JvmInfo;
import org.elasticsearch.node.Node;
import org.elasticsearch.plugins.PluginsModule;
import org.elasticsearch.plugins.PluginsService;
@ -104,7 +104,7 @@ public final class InternalNode implements Node {
Tuple<Settings, Environment> tuple = InternalSettingsPerparer.prepareSettings(pSettings, loadConfigSettings);
ESLogger logger = Loggers.getLogger(Node.class, tuple.v1().get("name"));
logger.info("{{}}[{}]: Initializing ...", Version.full(), JvmConfig.jvmConfig().pid());
logger.info("{{}}[{}]: Initializing ...", Version.full(), JvmInfo.jvmInfo().pid());
this.pluginsService = new PluginsService(tuple.v1(), tuple.v2());
this.settings = pluginsService.updatedSettings();
@ -140,7 +140,7 @@ public final class InternalNode implements Node {
client = injector.getInstance(Client.class);
logger.info("{{}}[{}]: Initialized", Version.full(), JvmConfig.jvmConfig().pid());
logger.info("{{}}[{}]: Initialized", Version.full(), JvmInfo.jvmInfo().pid());
}
@Override public Settings settings() {
@ -157,7 +157,7 @@ public final class InternalNode implements Node {
}
ESLogger logger = Loggers.getLogger(Node.class, settings.get("name"));
logger.info("{{}}[{}]: Starting ...", Version.full(), JvmConfig.jvmConfig().pid());
logger.info("{{}}[{}]: Starting ...", Version.full(), JvmInfo.jvmInfo().pid());
for (Class<? extends LifecycleComponent> plugin : pluginsService.services()) {
injector.getInstance(plugin).start();
@ -180,7 +180,7 @@ public final class InternalNode implements Node {
}
injector.getInstance(JmxService.class).connectAndRegister(discoService.nodeDescription(), injector.getInstance(NetworkService.class));
logger.info("{{}}[{}]: Started", Version.full(), JvmConfig.jvmConfig().pid());
logger.info("{{}}[{}]: Started", Version.full(), JvmInfo.jvmInfo().pid());
return this;
}
@ -190,7 +190,7 @@ public final class InternalNode implements Node {
return this;
}
ESLogger logger = Loggers.getLogger(Node.class, settings.get("name"));
logger.info("{{}}[{}]: Stopping ...", Version.full(), JvmConfig.jvmConfig().pid());
logger.info("{{}}[{}]: Stopping ...", Version.full(), JvmInfo.jvmInfo().pid());
if (settings.getAsBoolean("http.enabled", true)) {
injector.getInstance(HttpServer.class).stop();
@ -220,7 +220,7 @@ public final class InternalNode implements Node {
Injectors.close(injector);
logger.info("{{}}[{}]: Stopped", Version.full(), JvmConfig.jvmConfig().pid());
logger.info("{{}}[{}]: Stopped", Version.full(), JvmInfo.jvmInfo().pid());
return this;
}
@ -234,7 +234,7 @@ public final class InternalNode implements Node {
}
ESLogger logger = Loggers.getLogger(Node.class, settings.get("name"));
logger.info("{{}}[{}]: Closing ...", Version.full(), JvmConfig.jvmConfig().pid());
logger.info("{{}}[{}]: Closing ...", Version.full(), JvmInfo.jvmInfo().pid());
if (settings.getAsBoolean("http.enabled", true)) {
injector.getInstance(HttpServer.class).close();
@ -269,7 +269,7 @@ public final class InternalNode implements Node {
ThreadLocals.clearReferencesThreadLocals();
logger.info("{{}}[{}]: Closed", Version.full(), JvmConfig.jvmConfig().pid());
logger.info("{{}}[{}]: Closed", Version.full(), JvmInfo.jvmInfo().pid());
}
public Injector injector() {

View File

@ -18,6 +18,7 @@
*/
/**
* Allow to build a {@link Node} using {@link NodeBuilder} which is a node within the cluster.
* Allow to build a {@link org.elasticsearch.node.Node} using {@link org.elasticsearch.node.NodeBuilder} which is a
* node within the cluster.
*/
package org.elasticsearch.node;

View File

@ -0,0 +1,61 @@
/*
* 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.util;
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 Percent implements Streamable, Serializable {
private double value;
public Percent(double value) {
this.value = value;
}
public double value() {
return value;
}
public String toString() {
return format(value);
}
public static String format(double value) {
String p = String.valueOf(value * 100.0);
int ix = p.indexOf(".") + 1;
return p.substring(0, ix) + p.substring(ix, ix + 1) + "%";
}
@Override public void readFrom(StreamInput in) throws IOException {
value = in.readDouble();
}
@Override public void writeTo(StreamOutput out) throws IOException {
out.writeDouble(value);
}
}

View File

@ -53,30 +53,58 @@ public class SizeValue implements Serializable, Streamable {
return sizeUnit.toBytes(size);
}
public long getBytes() {
return bytes();
}
public long kb() {
return sizeUnit.toKB(size);
}
public long getKb() {
return kb();
}
public long mb() {
return sizeUnit.toMB(size);
}
public long getMb() {
return mb();
}
public long gb() {
return sizeUnit.toGB(size);
}
public long getGb() {
return gb();
}
public double kbFrac() {
return ((double) bytes()) / SizeUnit.C1;
}
public double getKbFrac() {
return kbFrac();
}
public double mbFrac() {
return ((double) bytes()) / SizeUnit.C2;
}
public double getMbFrac() {
return mbFrac();
}
public double gbFrac() {
return ((double) bytes()) / SizeUnit.C3;
}
public double getGbFrac() {
return gbFrac();
}
@Override public String toString() {
long bytes = bytes();
double value = bytes;

View File

@ -70,54 +70,106 @@ public class TimeValue implements Serializable, Streamable {
return timeUnit.toNanos(duration);
}
public long getNanos() {
return nanos();
}
public long micros() {
return timeUnit.toMicros(duration);
}
public long getMicros() {
return micros();
}
public long millis() {
return timeUnit.toMillis(duration);
}
public long getMillis() {
return millis();
}
public long seconds() {
return timeUnit.toSeconds(duration);
}
public long getSeconds() {
return seconds();
}
public long minutes() {
return timeUnit.toMinutes(duration);
}
public long getMinutes() {
return minutes();
}
public long hours() {
return timeUnit.toHours(duration);
}
public long getHours() {
return hours();
}
public long days() {
return timeUnit.toDays(duration);
}
public long getDays() {
return days();
}
public double microsFrac() {
return ((double) nanos()) / C1;
}
public double getMicrosFrac() {
return microsFrac();
}
public double millisFrac() {
return ((double) nanos()) / C2;
}
public double getMillisFrac() {
return millisFrac();
}
public double secondsFrac() {
return ((double) nanos()) / C3;
}
public double getSecondsFrac() {
return secondsFrac();
}
public double minutesFrac() {
return ((double) nanos()) / C4;
}
public double getMinutesFrac() {
return minutesFrac();
}
public double hoursFrac() {
return ((double) nanos()) / C5;
}
public double getHoursFrac() {
return hoursFrac();
}
public double daysFrac() {
return ((double) nanos()) / C6;
}
public double getDaysFrac() {
return daysFrac();
}
@Override public String toString() {
long nanos = nanos();
if (nanos == 0) {