How to pass -javagent /path/to/newrelic.jar parameter to the JVM running a HiveMetaStore server

Viewed 263

I try to get a Newrelic java agent to run in a docker container to monitor a HiveMetaStore server running in the docker container.

In order to get the Newrelic agent started during the startup of the JVM I have to pass-javaagent /path/to/newrelic.jar flag to the JVM.

I tried:

hive --service metastore  -javaagent  /path/to/newrelic.jar 

This failed with "Unrecognized Option" in the HiveMetaStore server code, where it should not have ended up at all.

The hive script invokes the bin/ext/metastore.sh script which in turn invokes

exec $HADOOP jar $JAR $CLASS "$@" 

So I tried to patch this invocation:

exec $HADOOP -javaagent /path/to/newrelic.jar jar  $JAR $CLASS "$@" 

This failed as well.

Then I took a deeper look at the hadoop script. Finally function hadoop_java_exec in libexec//hadoop_functions.sh invokes:

exec "${JAVA}" "-Dproc_${command}" ${HADOOP_OPTS} "${class}" "$@"

So I patched this code:

exec "${JAVA}" "-javaagent /path/to/newrelic.jar" "-Dproc_${command}" ${HADOOP_OPTS} "${class}" "$@"

This again failed.

Last but not least I recognized that one can pass java properties via HADOOP _OPTS (in libexec/hadoop_functions.sh):

   function hadoop_finalize_hadoop_opts                        
    {                                               
     hadoop_translate_cygwin_path HADOOP_LOG_DIR
     hadoop_add_param HADOOP_OPTS hadoop.log.dir "-Dhadoop.log.dir=${HADOOP_LOG_DIR}"
     hadoop_add_param HADOOP_OPTS hadoop.log.file "-Dhadoop.log.file=${HADOOP_LOGFILE}"
     …
    }

But I could not figure out how to pass -javaagent:/path/to/newrelic.jar using this mechanism.

Is anyone out there who has tried this before and can help with that ?

My apology if this is a stupid question. Thanks upfront, Ute

1 Answers
function hadoop_finalize_hadoop_opts                        
    {                                               
     hadoop_translate_cygwin_path HADOOP_LOG_DIR
     hadoop_add_param HADOOP_OPTS hadoop.log.dir "-Dhadoop.log.dir=${HADOOP_LOG_DIR}"
     hadoop_add_param HADOOP_OPTS hadoop.log.file "-Dhadoop.log.file=${HADOOP_LOGFILE}"
     …
     hadoop_add _param HADOOP_OPTS java.javaagent -javaagent:${NEWRELIC_AGENT_HOME}\/newrelic.jar
    }

Adding the last statement to got the agent started. I see in the container:

/usr/lib/jvm/default-jvm/bin/java -Dproc_jar -Dproc_metastore , … , NullAppender - javaagent:/opt/newrelic-agent-5.10.0/newrelic.jar   org.apache.hadoop.util.RunJar /opt/apache-hive-3.1.2-bin/lib/hive-metastore-3.1.2.jar org.apache.hadoop.hive.metastore.HiveMetaStore

I don't understand the "NullAppender" yet but at least the agent seems to be running now.

Related