simplify mx4j configuration

patch by Jay Zhuang; reviewed by jasobrown for CASSANDRA-13578
This commit is contained in:
Jay Zhuang 2017-06-06 17:41:56 -07:00 committed by Jason Brown
parent 4b777d6271
commit 41ef972b18
3 changed files with 26 additions and 8 deletions

View File

@ -1,4 +1,5 @@
4.0
* simplify mx4j configuration (Cassandra-13578)
* Fix trigger example on 4.0 (CASSANDRA-13796)
* force minumum timeout value (CASSANDRA-9375)
* use netty for streaming (CASSANDRA-12229)

View File

@ -282,15 +282,30 @@ JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.password.file=/etc/cassandra/
# See http://wiki.apache.org/cassandra/Operations#Monitoring_with_MX4J
# By default mx4j listens on 0.0.0.0:8081. Uncomment the following lines
# to control its listen address and port.
#MX4J_ADDRESS="-Dmx4jaddress=127.0.0.1"
#MX4J_PORT="-Dmx4jport=8081"
#MX4J_ADDRESS="127.0.0.1"
#MX4J_PORT="8081"
# Cassandra uses SIGAR to capture OS metrics CASSANDRA-7838
# for SIGAR we have to set the java.library.path
# to the location of the native libraries.
JVM_OPTS="$JVM_OPTS -Djava.library.path=$CASSANDRA_HOME/lib/sigar-bin"
JVM_OPTS="$JVM_OPTS $MX4J_ADDRESS"
JVM_OPTS="$JVM_OPTS $MX4J_PORT"
if [ "x$MX4J_ADDRESS" != "x" ]; then
if [[ "$MX4J_ADDRESS" == \-Dmx4jaddress* ]]; then
# Backward compatible with the older style #13578
JVM_OPTS="$JVM_OPTS $MX4J_ADDRESS"
else
JVM_OPTS="$JVM_OPTS -Dmx4jaddress=$MX4J_ADDRESS"
fi
fi
if [ "x$MX4J_PORT" != "x" ]; then
if [[ "$MX4J_PORT" == \-Dmx4jport* ]]; then
# Backward compatible with the older style #13578
JVM_OPTS="$JVM_OPTS $MX4J_PORT"
else
JVM_OPTS="$JVM_OPTS -Dmx4jport=$MX4J_PORT"
fi
fi
JVM_OPTS="$JVM_OPTS $JVM_EXTRA_OPTS"

View File

@ -21,6 +21,7 @@ import java.lang.management.ManagementFactory;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -76,17 +77,18 @@ public class Mx4jTool
private static String getAddress()
{
return System.getProperty("mx4jaddress", FBUtilities.getBroadcastAddress().getHostAddress());
String sAddress = System.getProperty("mx4jaddress");
if (StringUtils.isEmpty(sAddress))
sAddress = FBUtilities.getBroadcastAddress().getHostAddress();
return sAddress;
}
private static int getPort()
{
int port = 8081;
String sPort = System.getProperty("mx4jport");
if (sPort != null && !sPort.equals(""))
{
if (StringUtils.isNotEmpty(sPort))
port = Integer.parseInt(sPort);
}
return port;
}
}