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

Popular posts from this blog

App Localization: The Sri Lankan Way

I cannot believe the fact that the last blog post that I have written was in 2018. So I decided to start writing again, while working in a new work place, Yeah.. Yes! I had to move out from the "bank" and this post that I am writing is something that I did while I was at the "bank". So I got the opportunity to develop a mobile application for both Android and iOS for Sri Lankans where it should have the feature of changing the language of the application. Basically an option to switch the app's language between Sinhala, Tamil & English. At first, I was like "Alright!! Not a big deal. I'll do it." Then came the tricky part. they say they need to switch the language from with in, Basically, app's language cannot have a dependency on the device's region. So this is something that apps like "Pick Me" has done. UX POV this is a quite reasonable functionality when we develop apps for countries like Sri Lanka, where the devi...

Apple September Event: iPhone XS?

Source: Ars Technica   Writing after a very long time from a different workstation at a different company. (Yes, I left that company and yes, i'm writing while i'm at work. *F irst of all  I deserve a break and second of all  Shhhhhhhhhhh!!! * ) Decided to write this as soon as I heard that the Apple has released the official invite for their September Event which as you all know it's their hardware event. (BTW the event is on 12th September at 10 AM PDT) Basically many parties have predicted that they'll be releasing a new Apple Watch, iPhone, high end Mac Mini, and a low budget MacBook Pro. But in this post i'll just stick to the iPhone. WTH happened to iPhoneX So the Apple iPhoneX, which was released last year didn't meet their sales expectations mainly due to the price tag. As a result, Apple decided to launch low price editions of the devices (Thanks to China) due to this reason and hence now we enjoying the 9.7-inch iPad. So yes, as you guessed,...

Android: Unique ID Dilemma

Source: Device ID Despite the fact that I couldn't write anything in the last couple of months due to heavy workload with asshole of teams I decided to write again since I have faced pretty interesting issues over the months. One of that is a Salesforce related issue in Android (Another pretty good story that i'm not suppose to tell *wink*) where I have to come up with a solution which doesn't impact the live version, and during the approach I had to come up with a way where I have to create a unique identifier to identify each device. So in here I'll briefly explain the things I found during that journey. What are our options? If we ask this from most of the developers they might reply saying that we can use Android ID (AKA Android Hardware ID) for this and that's fine, I thought the same thing in the very beginning but I was wrong. So in here I'll explain what are our options, What is the key, what are the pros and cons (The usual sh...