Installing New Relic Monitor in GitLab

Overview

New Relic is an application, RUM (Real User Monitor) and Server Monitoring solution that enables you to measure the responsiveness of your application ensuring that it is running to level your users appreciate via their App Index Score.

GitLab on the other hand is an opensource git repository application, like Github but you can host it yourself.

Monitoring GitLab to ensure your commits are going through and the frontend is rendering in time for your developers can be difficult, luckily NewRelic has the option to monitor Ruby on Rails applications out of the box!

The only prerequisites you’ll need for this installation is a New Relic account (You can sign up here) and access to your GitLab install via SSH to install the New Relic gem. I’ll also be assuming you followed the GitLab install instructions written by them here and that GitLab lives in /home/git/gitlab

Do you have a GitLab Omnibus install and are wondering how to do this? Check out my new post here!

Installing New Relic

First you need to login to your NewRelic account and add a new host

Select Ruby from the application menu, generate your license  and download your newrelic.yml file

NewRelic - Adding a new host

Next you need to open the file you just downloaded up in a text editor and change the Application Name to something more appropriate, like “GitLab”

app_name: GitLab

Next you need to upload that file to /home/git/gitlab/config/newrelic.yml (Assuming you installed GitLab in it’s default location) and chown it to the git user

cp newrelic.yml /home/git/gitlab/config
chown git:git
/home/git/gitlab/config/newrelic.yml

Now we need to install the NewRelic gem so it can actually monitor the GitLab install. Unfortunately because of how gem bundles work we can’t do this straight to the live production system, but we have to move it out and then move both of the Gemfile and Gemfile.lock files back into place.

First let’s copy our GitLab directory to somewhere else, like /home/testing/

cp -r /home/git/gitlab/* /home/testing/

Now we need to edit our Gemfile to allow the New Relic gem. Find the part that mentions production do and add the newrelic_rpm so it’s something like below

group :production do gem "gitlab_meta", '6.0' gem "newrelic_rpm" end

Now we need to run:

bundle install --deployment --without development test postgres aws --no-deployment

Note: The above command assumes you’re using MySQL and are not on AWS, if you are using either of the above please change the command to suit your setup.

Awesome! We’ve now got the New Relic gem install in our Gemfile and Gemfile.lock which means we can copy them back over the top of our normal GitLab ones and make sure the git user owns them.

cp /home/testing/Gemfile{,.lock} /home/git/gitlab
chown git:git /home/testing/Gemfile{,.lock}
cp /home/git/gitlab/Gemfile{,.lock}

Now we just need to run another bundle install as per GitLab’s install guide here.

sudo -u git -H bundle install --deployment --without development test postgres aws

Note: If you watch closely you should see the NewRelic gem install
It’s also worth noting that you should, like above, ensure that the command is correct for your setup.

Now we just need to restart GitLab and Nginx.

service gitlab restart && service nginx restart

And now you should see something like the below at the top of your page

<script type="text/javascript">window.NREUM||(NREUM={});NREUM.info={"beacon":"beacon-2.newrelic.com","errorBeacon":"jserror.newrelic.com","licenseKey":"123456789","applicationID":"1234567","transactionName":"123445678946563121245487521","queueTime":0,"applicationTime":306,"ttGuid":"","agentToken":null,"agent":"js-agent.newrelic.com/nr-361.min.js"}</script>

Well done! You are now tracking the status of your GitLab application and should see results flying into New Relic in no time!

James Loh

I'm a Sysadmin for a web solutions company deploying clouds across the globe. I learn new things every day.

Australia @itsjloh jloh jloh