diff --git a/bin/datavines-daemon.sh b/bin/datavines-daemon.sh index 6fe0176fc..6b2b645eb 100644 --- a/bin/datavines-daemon.sh +++ b/bin/datavines-daemon.sh @@ -16,7 +16,7 @@ # limitations under the License. # -usage="Usage: datavines-daemon.sh (start|start_container|stop) <''|mysql>" +usage="Usage: datavines-daemon.sh (start|start_container|start_with_jmx|stop|restart_with_jmx|status) <''|mysql>" # if no args specified, show usage if [ $# -le 0 ]; then @@ -71,18 +71,21 @@ cd $DATAVINES_HOME LOG_FILE="-Dlogging.config=classpath:server-logback.xml $springProfileActive" CLASS=io.datavines.server.DataVinesServer +# JMX path +JMX="-javaagent:$DATAVINES_HOME/libs/jmx_prometheus_javaagent-0.20.0.jar=10010:$DATAVINES_CONF_DIR/jmx/jmx_exporter_config.yaml" + case $startStop in (start) [ -w "$DATAVINES_PID_DIR" ] || mkdir -p "$DATAVINES_PID_DIR" if [ -f $pid ]; then if kill -0 `cat $pid` > /dev/null 2>&1; then - echo DataVinesServer running as process `cat $pid`. Stop it first. + echo "DataVinesServer running as process `cat $pid`. Stop it first." exit 1 fi fi - echo starting DataVinesServer, logging to $log + echo "Starting DataVinesServer, logging to $log ..." exec_command="$LOG_FILE $DATAVINES_OPTS -classpath $DATAVINES_CONF_DIR:$DATAVINES_LIB_JARS $CLASS" @@ -96,12 +99,12 @@ case $startStop in if [ -f $pid ]; then if kill -0 `cat $pid` > /dev/null 2>&1; then - echo DataVinesServer running as process `cat $pid`. Stop it first. + echo "DataVinesServer running as process `cat $pid`. Stop it first." exit 1 fi fi - echo starting DataVinesServer, logging to $log + echo "Starting DataVinesServer, logging to $log ..." exec_command="$LOG_FILE $DATAVINES_OPTS -classpath $DATAVINES_CONF_DIR:$DATAVINES_LIB_JARS $CLASS" @@ -110,12 +113,30 @@ case $startStop in echo $! > $pid ;; - (stop) + (start_with_jmx) + [ -w "$DATAVINES_PID_DIR" ] || mkdir -p "$DATAVINES_PID_DIR" + + if [ -f $pid ]; then + if kill -0 `cat $pid` > /dev/null 2>&1; then + echo "DataVinesServer running as process `cat $pid`. Stop it first." + exit 1 + fi + fi + echo "Starting DataVinesServer, logging to $log ..." + + exec_command="$LOG_FILE $DATAVINES_OPTS ${JMX} -classpath $DATAVINES_CONF_DIR:$DATAVINES_LIB_JARS $CLASS" + + echo "nohup $JAVA_HOME/bin/java $exec_command > $log 2>&1 &" + nohup $JAVA_HOME/bin/java $exec_command > $log 2>&1 & + echo $! > $pid + ;; + + (stop) if [ -f $pid ]; then TARGET_PID=`cat $pid` if kill -0 $TARGET_PID > /dev/null 2>&1; then - echo stopping DataVinesServer + echo "Stopping DataVinesServer..." kill $TARGET_PID sleep $STOP_TIMEOUT if kill -0 $TARGET_PID > /dev/null 2>&1; then @@ -123,14 +144,34 @@ case $startStop in kill -9 $TARGET_PID fi else - echo no DataVinesServer to stop + echo "No DataVinesServer to stop." fi rm -f $pid else - echo no DataVinesServer to stop + echo "No DataVinesServer to stop." fi ;; + (status) + if [ -f $pid ]; then + echo "" + echo "Service DataVinesServer is running. It's pid=${pid}" + echo "" + else + echo "" + echo "Service DataVinesServer is not running!" + echo "" + exit 1 + fi + ;; + + (restart_with_jmx) + echo "" + stop + start_with_jmx + echo "........................................Restart with Jmx Successfully........................................" + ;; + (*) echo $usage exit 1 diff --git a/datavines-server/pom.xml b/datavines-server/pom.xml index a660eb58a..5d84382a2 100644 --- a/datavines-server/pom.xml +++ b/datavines-server/pom.xml @@ -472,6 +472,18 @@ cn.easyproject orai18n + + + io.prometheus.jmx + jmx_prometheus_javaagent + ${jmx_prometheus_javaagent.version} + + + org.yaml + snakeyaml + + + @@ -510,4 +522,4 @@ - \ No newline at end of file + diff --git a/datavines-server/src/main/resources/jmx/jmx_exporter_config.yaml b/datavines-server/src/main/resources/jmx/jmx_exporter_config.yaml new file mode 100644 index 000000000..39c07544e --- /dev/null +++ b/datavines-server/src/main/resources/jmx/jmx_exporter_config.yaml @@ -0,0 +1,14 @@ +--- +lowercaseOutputLabelNames: true +lowercaseOutputName: true +whitelistObjectNames: ["java.lang:type=OperatingSystem"] +blacklistObjectNames: [] +rules: + - pattern: 'java.lang<>(committed_virtual_memory|free_physical_memory|free_swap_space|total_physical_memory|total_swap_space)_size:' + name: os_$1_bytes + type: GAUGE + attrNameSnakeCase: true + - pattern: 'java.lang<>((?!process_cpu_time)\w+):' + name: os_$1 + type: GAUGE + attrNameSnakeCase: true diff --git a/pom.xml b/pom.xml index be8920a4b..71787ef15 100644 --- a/pom.xml +++ b/pom.xml @@ -113,6 +113,7 @@ 1.6.2 19.3.0.0 12.1.0.2.0 + 0.20.0 3.0 3.3