Skip to content

Commit

Permalink
initial support for process monitoring using sigar
Browse files Browse the repository at this point in the history
  • Loading branch information
kimchy committed May 6, 2010
1 parent 5603c4d commit 371bfeb
Show file tree
Hide file tree
Showing 40 changed files with 808 additions and 35 deletions.
6 changes: 6 additions & 0 deletions .idea/dictionaries/kimchy.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/modules/elasticsearch.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bin/elasticsearch.bat
Expand Up @@ -20,7 +20,7 @@ set JAVA_OPTS=^
-XX:+CMSParallelRemarkEnabled^
-XX:+HeapDumpOnOutOfMemoryError

set ES_CLASSPATH=$CLASSPATH;"%ES_HOME%/lib/*"
set ES_CLASSPATH=$CLASSPATH;"%ES_HOME%/lib/*";"%ES_HOME%/lib/sigar/*"
set ES_PARAMS=-Delasticsearch -Des-foreground=yes -Des.path.home="%ES_HOME%"

"%JAVA_HOME%\bin\java" %JAVA_OPTS% %ES_JAVA_OPTS% %ES_PARAMS% -cp "%ES_CLASSPATH%" "org.elasticsearch.bootstrap.Bootstrap"
Expand Down
2 changes: 1 addition & 1 deletion bin/elasticsearch.in.sh
@@ -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
Expand Down
Binary file removed bin/service/exec/elasticsearch-freebsd-x86-32
Binary file not shown.
Binary file removed bin/service/exec/elasticsearch-freebsd-x86-64
Binary file not shown.
Binary file removed bin/service/exec/elasticsearch-linux-ia-64
Binary file not shown.
Binary file removed bin/service/exec/elasticsearch-linux-ppc-32
Binary file not shown.
Binary file removed bin/service/exec/elasticsearch-linux-ppc-64
Binary file not shown.
2 changes: 2 additions & 0 deletions build.gradle
Expand Up @@ -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('.')
Expand All @@ -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: "**/*")
}
Expand Down
Binary file added lib/sigar/libsigar-amd64-linux.so
Binary file not shown.
Binary file added lib/sigar/libsigar-amd64-solaris.so
Binary file not shown.
Binary file added lib/sigar/libsigar-sparc-solaris.so
Binary file not shown.
Binary file added lib/sigar/libsigar-sparc64-solaris.so
Binary file not shown.
Binary file added lib/sigar/libsigar-universal-macosx.dylib
Binary file not shown.
Binary file added lib/sigar/libsigar-universal64-macosx.dylib
Binary file not shown.
Binary file added lib/sigar/libsigar-x86-linux.so
Binary file not shown.
Binary file added lib/sigar/libsigar-x86-solaris.so
Binary file not shown.
Binary file added lib/sigar/sigar-1.6.3.jar
Binary file not shown.
Binary file added lib/sigar/sigar-amd64-winnt.dll
Binary file not shown.
Binary file added lib/sigar/sigar-x86-winnt.dll
Binary file not shown.
Binary file added lib/sigar/sigar-x86-winnt.lib
Binary file not shown.
2 changes: 1 addition & 1 deletion modules/elasticsearch/build.gradle
Expand Up @@ -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
Expand All @@ -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 }
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -76,6 +76,6 @@ public static String full() {
}

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());
}
}
Expand Up @@ -19,20 +19,26 @@

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;
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;
Expand Down Expand Up @@ -63,6 +69,26 @@ public MonitorModule(Settings settings) {
.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
Expand Down
Expand Up @@ -33,11 +33,11 @@
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();
Expand All @@ -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;
}

Expand Down Expand Up @@ -89,12 +89,12 @@ public static JvmConfig jvmConfig() {

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;
Expand All @@ -110,62 +110,120 @@ public JvmConfig(long pid, String vmName, String vmVersion, String vmVendor, lon
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 {
Expand Down
@@ -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();
}
}

0 comments on commit 371bfeb

Please sign in to comment.