Skip to content

Commit

Permalink
[Feature][JMX] Add JMX support for DataSophon integration (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
leeoo authored Aug 31, 2024
1 parent a74108b commit d40c526
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 10 deletions.
59 changes: 50 additions & 9 deletions bin/datavines-daemon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"

Expand All @@ -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"

Expand All @@ -110,27 +113,65 @@ 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
echo "DataVinesServer did not stop gracefully after $STOP_TIMEOUT seconds: killing with kill -9"
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
Expand Down
14 changes: 13 additions & 1 deletion datavines-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,18 @@
<groupId>cn.easyproject</groupId>
<artifactId>orai18n</artifactId>
</dependency>

<dependency>
<groupId>io.prometheus.jmx</groupId>
<artifactId>jmx_prometheus_javaagent</artifactId>
<version>${jmx_prometheus_javaagent.version}</version>
<exclusions>
<exclusion>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -510,4 +522,4 @@
</plugins>
</build>

</project>
</project>
14 changes: 14 additions & 0 deletions datavines-server/src/main/resources/jmx/jmx_exporter_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
lowercaseOutputLabelNames: true
lowercaseOutputName: true
whitelistObjectNames: ["java.lang:type=OperatingSystem"]
blacklistObjectNames: []
rules:
- pattern: 'java.lang<type=OperatingSystem><>(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<type=OperatingSystem><>((?!process_cpu_time)\w+):'
name: os_$1
type: GAUGE
attrNameSnakeCase: true
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
<javax.mail.version>1.6.2</javax.mail.version>
<oracle.version>19.3.0.0</oracle.version>
<orai18n.version>12.1.0.2.0</orai18n.version>
<jmx_prometheus_javaagent.version>0.20.0</jmx_prometheus_javaagent.version>

<license-maven-plugin.version>3.0</license-maven-plugin.version>
<maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
Expand Down

0 comments on commit d40c526

Please sign in to comment.