Recently I wanted to install new relic in a Grails 3 app which I distribute through Elastic Beanstalk.
One of the steps described in the new relic documentation is:
In your WAR file, add the newrelic.jar and newrelic.yml files to WEB-INF/lib/.
How to do that in a Grails 3 application?
- Create a folder in the root folder of your application called newrelic
- Copy both files (newrelic.jar and newrelic.yml) to the previously created newrelic folder.
- Add the next snippet to your build.gradle file:
war { from('newrelic') { into 'WEB-INF/lib' include 'newrelic.*' } }
Additionally you would probably want to add to the dependencies block in build.gradle the next line:
compile "org.grails.plugins:newrelic:3.19.2"
This will install the Grails newrelic Plugin to your grails app.
Among other things the plugin will insert an interceptor which names transactions based on your controller/action information.
NewRelicInterceptor – An interceptor matching all requests to automatically name transactions as {controllerName}/{actionName}.
We are done in the grails side, complete the installation guide and you will have new relic configured.
Do you like to read about Groovy/Grails development? Yes, then Subscribe to Groovy Calamari a weekly curated email newsletter about the Groovy ecosystem which I happen to write
Thanks for the shoutout!
For the newrelic.jar and newrelic.yml here is another option that we use.
It will install/configure NewRelic app AND server monitoring on AWS ElasticBeanstalk.
It will also call the NewRelic deployment API each time you start a new env.
1- create a folder src/main/webapp/.ebextensions, a folder src/main/webapp/.ebextensions/files and add the newrelic.jar in it.
2- create a file src/main/webapp/.ebextensions/app.config
container_commands:
newrelic:
command: “bash -x .ebextensions/newrelic.sh”
3- create a file src/main/webapp/.ebextensions/newrelic.sh
#!/bin/sh
# New Relic (Application monitoring)
mkdir /var/lib/newrelic
mv ./.ebextensions/files/newrelic*.jar /var/lib/newrelic/
bash ./.ebextensions/files/newrelic.yml.sh > /var/lib/newrelic/newrelic.yml
# New Relic Agent (Server monitoring)
rpm -Uvh https://yum.newrelic.com/pub/newrelic/el5/x86_64/newrelic-repo-5-3.noarch.rpm
yum -y install newrelic-sysmond
/usr/sbin/nrsysmond-config –set license_key=$NR_LICENSE
/etc/init.d/newrelic-sysmond start
# New Relic deployment event
export AP_VERSION=`cat ./META-INF/grails.build.info | grep info.app.version | cut -d= -f2`
java -jar /var/lib/newrelic/newrelic.jar deployment –revision=$AP_VERSION
4- create a file src/main/webapp/.ebextensions/files/newrelic.yml.sh (to dynamically generate newrelic.yml based on env var)
cat << EOF
common: &default_settings
license_key: '$NR_LICENSE'
enable_auto_transaction_naming: false
app_name: $NR_APPNAME
EOF
Then, in your Beanstalk app config options, add "-javaagent:/var/lib/newrelic/newrelic.jar" to the JVM command line parameter and set NR_LICENSE and NR_APPNAME env properties.
Note: maybe, this is something I should add in the Grails Newrelic plugin README on Github :).
@Sergio
Is this approach still relevant for Grails v3.3.9 and “org.grails.plugins:newrelic:4.9.0” (New Relic Java Agent v4.8.0)?
Or is there more steps involved?
Best regards,