Skip to main content

WSO2: Integrate your WSO2 product with New Relic

As you may already know New Relic can be use as a tool for monitoring your java app. It let's you see the whole stack, front to back end in real time. So basically you can get an idea about the CPU,Disk,Memory,N/W usage regarding any WSO2 product realtime once you install New Relic in the instance it self.

Steps


Configuring New Relic with WSO2 is not that hard. All you have to do is follow the below steps that I have mentioned.

  1. Download the New Relic agent from [1]. (In here I have used newrelic-java-3.31.0 with WSO2 AM 1.10.0)
  2. Unzip the agent to <CARBON_HOME>. (So once you unzip it you should be able to access it from <CARBON_HOME>/newrelic)
  3. Change the license key and the application name from <CARBON_HOME>/newrelic/newrelic.yml (License Key will be added automatically when you download the zip file but it is a good practice to check it again. Please refer [2] for more info)
  4. This step is very important. If you're using a Carbon 4.4.x product make sure to change the following in wso2server.sh file, otherwise it will throw you an error when you start the server.

    Replace
    if [ -d "$TMP_DIR" ]; then
    rm -rf "$TMP_DIR"
    fi
    With
    if [ -d "$TMP_DIR" ]; then
    rm -rf "$TMP_DIR"/*
    fi

  5. Add the following line to the same file (wso2server.sh) and start the server.
  6. -javaagent:$CARBON_HOME/newrelic/newrelic.jar \ 
  7. So once you add the above changes, the file will look like this,

    TMP_DIR="$CARBON_HOME"/tmp
    if [ -d "$TMP_DIR" ]; then
    rm -rf "$TMP_DIR"/*
    fi
    
    START_EXIT_STATUS=121
    status=$START_EXIT_STATUS
    
    if [ -z "$JVM_MEM_OPTS" ]; then
       java_version=$("$JAVACMD" -version 2>&1 | awk -F '"' '/version/ {print $2}')
       JVM_MEM_OPTS="-Xms256m -Xmx1024m"
       if [ "$java_version" \< "1.8" ]; then
          JVM_MEM_OPTS="$JVM_MEM_OPTS -XX:MaxPermSize=256m"
       fi
    fi
    echo "Using Java memory options: $JVM_MEM_OPTS"
    
    #To monitor a Carbon server in remote JMX mode on linux host machines, set the below system property.
    #   -Djava.rmi.server.hostname="your.IP.goes.here"
    
    while [ "$status" = "$START_EXIT_STATUS" ]
    do
        $JAVACMD \
        -Xbootclasspath/a:"$CARBON_XBOOTCLASSPATH" \
        $JVM_MEM_OPTS \
        -XX:+HeapDumpOnOutOfMemoryError \
        -XX:HeapDumpPath="$CARBON_HOME/repository/logs/heap-dump.hprof" \
        $JAVA_OPTS \
        -javaagent:$CARBON_HOME/newrelic/newrelic.jar \
        -Dcom.sun.management.jmxremote \
        -classpath "$CARBON_CLASSPATH" \
        -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" \
        -Djava.io.tmpdir="$CARBON_HOME/tmp" \
        -Dcatalina.base="$CARBON_HOME/lib/tomcat" \
        -Dwso2.server.standalone=true \
        -Dcarbon.registry.root=/ \
        -Djava.command="$JAVACMD" \
        -Dcarbon.home="$CARBON_HOME" \
        -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager \
        -Dcarbon.config.dir.path="$CARBON_HOME/repository/conf" \
        -Djava.util.logging.config.file="$CARBON_HOME/repository/conf/etc/logging-bridge.properties" \
        -Dcomponents.repo="$CARBON_HOME/repository/components/plugins" \
        -Dconf.location="$CARBON_HOME/repository/conf"\
        -Dcom.atomikos.icatch.file="$CARBON_HOME/lib/transactions.properties" \
        -Dcom.atomikos.icatch.hide_init_file_path=true \
        -Dorg.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING=false \
        -Dorg.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER=true \
        -Dcom.sun.jndi.ldap.connect.pool.authentication=simple  \
        -Dcom.sun.jndi.ldap.connect.pool.timeout=3000  \
        -Dorg.terracotta.quartz.skipUpdateCheck=true \
        -Djava.security.egd=file:/dev/./urandom \
        -Dfile.encoding=UTF8 \
        -Djava.net.preferIPv4Stack=true \
        -Dcom.ibm.cacheLocalHost=true \
        -DworkerNode=false \
        org.wso2.carbon.bootstrap.Bootstrap $*
        status=$?
    done
If you configure New Relic correctly you will be able to see the following logs at the startup
Aug 7, 2016 06:37:35 +0530 [638 1] com.newrelic INFO: New Relic Agent: Loading configuration file "/Users/SCK/Desktop/WSO2/Blog/wso2am-1.10.0/newrelic/./newrelic.yml"
Aug 7, 2016 06:37:36 +0530 [638 1] com.newrelic INFO: New Relic Agent: Writing to log file: /Users/SCK/Desktop/WSO2/Blog/wso2am-1.10.0/newrelic/logs/newrelic_agent.log
And then you will able to see the stats once you click the "APM" tab in [3].
Refer [4],[5] and [6] for additional details regarding this topic.


[1] https://newrelic.com/java
[2] https://docs.newrelic.com/docs/agents/java-agent/configuration/java-agent-configuration-config-file
[3] https://newrelic.com/
[4] http://blog.lasindu.com/2016/07/wso2-application-and-server-monitoring.html
[5] https://cnapagoda.blogspot.com/2013/03/wso2-carbon-instance-using-new-relic.html

[6] http://lasanthatechlog.blogspot.com/2015/06/integrating-wso2-products-with-new-relic.html

Comments