New Relic & Codeship: Measure the impact of your releases
The key to staying on top of your applications is to monitor them. For a little bit of extra monitoring help, Codeship users can easily notify New Relic about each deployment to an application with the following script. This allows users to analyze the correlation between their code releases and the performance of their application.
# !/bin/sh # Notify New Relic about a new deployment # https://docs.newrelic.com/docs/apm/new-relic-apm/maintenance/setting-deployment-notifications#examples # # You have to set the following environment variables in your project configuration # (NEW_RELIC_APP needs to match an existing Application Name in the New Relic APM) # # * NEW_RELIC_API_KEY # * NEW_RELIC_APP # # You have the option to define a revision, a description, and a changelog with the following environment variables # (Defaults are: description = CI_MESSAGE, revision = CI_COMMIT_ID, and an empty changelog). # # * NEW_RELIC_DESCRIPTION (65535 characters or less) # * NEW_RELIC_REVISION (127 characters or less) # * NEW_RELIC_CHANGELOG (65535 characters or less) # # Check required parameters NEW_RELIC_API_KEY=${NEW_RELIC_API_KEY:?'You need to configure the NEW_RELIC_API_KEY environment variable!'} NEW_RELIC_APP=${NEW_RELIC_APP:?'You need to configure the NEW_RELIC_APP environment variable!'} NEW_RELIC_DESCRIPTION=${NEW_RELIC_DESCRIPTION:-$CI_MESSAGE} NEW_RELIC_REVISION=${NEW_RELIC_REVISION:-$CI_COMMIT_ID} NEW_RELIC_CHANGELOG=${NEW_RELIC_CHANGELOG:-} #sanitize semicolons, remove newlines, and replace multiple spaces with a single space NEW_RELIC_APP=$(echo ${NEW_RELIC_APP//;/%3B}|sed ':a;N;$!ba;s/\n/ /g'|tr -s ' ') NEW_RELIC_DESCRIPTION=$(echo ${NEW_RELIC_DESCRIPTION//;/%3B}|sed ':a;N;$!ba;s/\n/ /g'|tr -s ' ') NEW_RELIC_REVISION=$(echo ${NEW_RELIC_REVISION//;/%3B}|sed ':a;N;$!ba;s/\n/ /g'|tr -s ' ') NEW_RELIC_CHANGELOG=$(echo ${NEW_RELIC_CHANGELOG//;/%3B}|sed ':a;N;$!ba;s/\n/ /g'|tr -s ' ') curl https://api.newrelic.com/deployments.xml \ -H "x-api-key:${NEW_RELIC_API_KEY}" \ -d "deployment[app_name]=${NEW_RELIC_APP}" \ -d "deployment[description]=${NEW_RELIC_DESCRIPTION}" \ -d "deployment[revision]=${NEW_RELIC_REVISION}" \ -d "deployment[changelog]=${NEW_RELIC_CHANGELOG}" \ -d "deployment[user]=${CI_COMMITTER_USERNAME}"
Click here to get to the script.
Important Notes
As a prerequisite, install the New Relic Agent on the server that hosts the application. You’ll need to restart the application as well.
New Relic will highlight deployments on the Overview page by inserting a pointer in the time line. As you can see in the screenshot below, each vertical black line indicates a deployment. We’ve also highlighted the annotations to show where each environment variable is visible on the Overview page.
About New Relic
New Relic is a software analytics company that makes sense of billions of metrics across millions of apps. Their goal is to help people who build modern software understand the stories that their data is trying to tell them.
Let us know in the comments if you like more scripts like this one and which one you would like to see next.
Stay up to date
We'll never share your email address and you can opt out at any time, we promise.