Installing New Relic Monitor in a GitLab Omnibus Install

After some discussion on my previous tutorial, it came to light that installing New Relic on GitLab's Omnibus package was quite different to a source install.

What is New Relic?

New Relic is a software analytics company that makes sense of billions of metrics about millions of applications in real time. New Relic's comprehensive SaaS-based solution provides one powerful interface for web and native mobile applications and consolidates the performance monitoring data for any chosen technology in an environment. There are thousands of active customer accounts using New Relic's cloud solution every day to optimize more than 200 billion metrics for 3 million applications. New Relic is pioneering a new category called Software Analytics.

The New Relic agent allows you to track the performance of your application and drill down into each query. It enables you to quickly identify which portions and queries are running slow.

What is an Omnibus package?

Omnibus packages allow you to easily deploy full stack application across multiple operating systems using Chef.

Whats the difference between a manual install and an Omnibus install?

A manual install requires for you to install and configure all of the packages required to run a full application stack. An Omnibus package uses Chef to install and configure a full stack from scratch. You can find more info on the Omnibus project on GitHub here.

Okay, but how do I install it?

The recommended way of enabling New Relic on a GitLab Omnibus install is through environment variables. This ensures that you're able to rebuild and reconfigure/upgrade your Omnibus install without losing your New Relic configuration.

First you'll need to look at your /etc/gitlab/gitlab.rb file and find the section that begins with gitlab_rails['env']. Keep in mind that on a default install this portion is hashed out and looks like this:

# gitlab_rails['env'] = {
#   'BUNDLE_GEMFILE' => "/opt/gitlab/embedded/service/gitlab-rails/Gemfile",
#   'PATH' => "/opt/gitlab/bin:/opt/gitlab/embedded/bin:/bin:/usr/bin"
# }

All you are required to do is add some environment variables for the New Relic ruby monitor to pick up. As per New Relic's documentation any environment variables with the prefix NEW_RELIC_ will be discovered by the agent automatically and override all other configuration methods. Given this, we know that for a basic configuration there are some required values:

  • enabled - so that NewRelic actually runs
  • license_key - so the monitor can be attached to your account
  • app_name - the name that it appears as on your dashboard
  • log_level - and the verbosity of the logging

To find out what all these values should be, you can download a basic newrelic.yml file from your account settings page.

Once obtained all you need to do is fill in the environment variables like so, replacing the below with your own values:

gitlab_rails['env'] = {
  'NEW_RELIC_ENABLED'     => 'true',
  'NEW_RELIC_LICENSE_KEY' => '1a234bcd5e6f7g8hijkl9mn012op34q567890123',
  'NEW_RELIC_APP_NAME'    => 'GitLab - Production',
  'NEW_RELIC_LOG_LEVEL'   => 'info'

For GitLab to pickup your new configuration you need to reconfigure it using gitlab-ctl.

[email protected]:/etc/gitlab# sudo gitlab-ctl reconfigure
Starting Chef Client, version 11.18.0
[ snip ]
Chef Client finished, 2/162 resources updated in 3.757062914 seconds
gitlab Reconfigured!
[email protected]:/etc/gitlab#

Now restart GitLab:

[email protected]:/etc/gitlab# sudo gitlab-ctl restart
ok: run: logrotate: (pid 13392) 0s
ok: run: nginx: (pid 13395) 1s
ok: run: postgresql: (pid 13402) 0s
ok: run: redis: (pid 13410) 1s
ok: run: sidekiq: (pid 13417) 0s
ok: run: unicorn: (pid 13427) 0s
[email protected]:/etc/gitlab#

Hang on, how come I don't have to install the Ruby Gem?!

Thats the best bit about this whole setup, the GitLab team already install the gem by default. GitLab configuration then disables it here, all we're doing with the above configuration is enabling it.


Awesome! After a reconfigure and a restart you should be able to see your New Relic script at the top of your page.

<script type="text/javascript">window.NREUM||(NREUM={});{"beacon":"","errorBeacon":"","licenseKey":"123456789","applicationID":"1234567","transactionName":"123445678946563121245487521","queueTime":0,"applicationTime":123,"ttGuid":"","agentToken":null,"agent":""}</script>  

Once you've refreshed your interface and browsed around a bit you should see metrics flowing into your New Relic dashboard.

Happy logging!

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