Monday, October 28, 2013

New Relic Integration


New Relic Integration
With Java Application deployed on heroku

Step 1: Add new relic add-on to your application

add new relic from addons
From UI: Login > Add-ons > Analytics - new relic > select <YOUR_APP> and Add
From Commandline:  $ heroku addons:add newrelic --app <YOUR_APP>



Step 2: Add dependency

add this following code to pom.xml dependencies
with current latest version in version portion**

<dependency>
<groupId>com.newrelic.agent.java</groupId>
<artifactId>newrelic-agent</artifactId>
<version>X.X.X</version>
<scope>provided</scope>
</dependency>



Step 3: Add plugin

add this following code to pom.xml to add this plugin
with current latest version in version portion**

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>X.X</version>
<executions>
<execution>
<id>copy-new-relic</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>com.newrelic.agent.java</includeGroupIds>
<includeArtifactIds>newrelic-agent</includeArtifactIds>
<stripVersion>true</stripVersion>
</configuration>
</execution>
</executions>
</plugin>

Step 4: Download new relic agent

From UI Go to apps > select your app > go to new relic addon > click on Get start > select language JAVA
at there you can find ‘Download new relic agent’ at there (just download it)

Step 5: Add newrelic.yml to project

form that “newrelic_agentX.X.X.zip” you can find newrelic.yml copy it and paste it at the root level of the project

Step 6: Replace App name

replace the value of ‘app_name’ in newrelic.yml with actual name of your application

Step 7: commit & push

now just commit those changes and push to the heroku application.

Step 8: Enable Java Agent

you need to add java_opts to enable java agent
for heroku you need to follow these commands

Add the following flag to your JAVA_OPTS config var on Heroku:

-javaagent:target/dependency/newrelic-agent.jar

You can get the current value of your config var with:

i/p:
$ heroku config --app <YOUR_APP>
o/p:
...
JAVA_OPTS         => -Xmx384m -Xss512k -XX:+UseCompressedOops
...

Copy the value, add the Java agent flag and app name :
*Make sure to enter your own app name in this example.

i/p:
$ heroku config:set JAVA_OPTS='-Xmx384m -Xss512k -XX:+UseCompressedOops -javaagent:target/dependency/newrelic-agent.jar' NEW_RELIC_APP_NAME="YOUR APP NAME" --app <YOUR_APP>
o/p:
Adding config vars:
   JAVA_OPTS => -Xmx384m -Xss512.../newrelic-agent.jar



Step 9: Restart application and see your application analytics

now just restart your application using following command and then you can see analytics on ui

$ heroku restart --app <YOUR_APP>

Now Go to apps > select your app > go to new relic (from addons)
and you can see the analytics of your application


**You can check current latest version of maven repository by this link

No comments:

Post a Comment