ScaleScaleScaleScale

Tips / Nginx


How to install Nginx New Relic plugin

New Relic is a performance monitoring software specifically designed to monitor web and mobile applications in real-time on cloud servers, dedicated servers, or hybrid platforms. New Relic provides deep analysis about the performance of your web applications, but it can also give you excellent details about your server performance, including our beloved Nginx web server.

With the information provided by New Relic, you will be able to know what’s going on with your apps or servers, troubleshoot potential issues, and act proactively before things go wrong.

Today we will learn how to install New Relic Nginx plugin so we can have full stats and deep information about our web server usage.

Main Features

  • Active client connections
  • Idle (keepalive) client connections
  • Client connections accept/drop rate
  • Average client requests per second

Requirements

In order to install the Nginx NewRelic plugin, you need:

Installation

Get your Nginx repo from: http://nginx.org/en/linux_packages.html. Once you have installed the Nginx official repo, proceed to install Nginx New Relic plugin.

If you are using RHEL, CentOS, Fedora systems:

yum install nginx-nr-agent

If you are using Debian/Ubuntu systems:

apt-get install nginx-nr-agent

The output should be something like:

----------------------------------------------------------------------
Thanks for using NGINX!

NGINX agent for New Relic is installed. Configuration file is:

/etc/nginx-nr-agent/nginx-nr-agent.ini

Please use "service nginx-nr-agent" to control the agent daemon.

More information about NGINX products is available on:
* http://nginx.com/

----------------------------------------------------------------------

Configuring NGINX New Relic plugin

The configuration file is located at /etc/nginx-nr-agent/nginx-nr-agent.ini

Edit the file and add your new relic license key:

nano -w /etc/nginx-nr-agent/nginx-nr-agent.ini

Now locate this line:

newrelic_license_key=YOUR_LICENSE_KEY_HERE

And replace “YOUR_LICENSE_KEY_HERE” with your real key, example (this is a fake key):

newrelic_license_key=16ad856a34334bc00e36ed5e9d0f8c34232

Add your data sources. Here’s an example:

# data sources settings
[source1]
name=nginxtips.com
url=http://www.scalescale.com/tips/nginx/status

Replace ‘nginxtips.com’ with your real site URL.

Now ensure you have nginx status configured in your nginx site configuration. For example:

# Server status
location = /status {
stub_status on;
allow 127.0.0.1;
allow 12.13.14.15;
deny all;
}

You must allow 127.0.0.1 in order to let the New Relic plugin collect all data. You can also add a second allow line (here we use 12.13.14.15) for your public server IP in case 127.0.0.1 doesn’t fully work.

Testing the New Relic Nginx plugin

The best way to check if this is working is to tail the logs:

tail -f /var/log/nginx-nr-agent.log

If your Nginx plugin is collecting all the information from your status page, you should see something like this:

2015-01-30 13:35:35,764 nginx-nr-agent [INFO]: pushing finished successfully
2015-01-30 13:36:35,824 nginx-nr-agent [INFO]: polling source1
2015-01-30 13:36:35,825 nginx-nr-agent [DEBUG]: getting data from http://nginxtips.com/status (lastupdate=1422642935.660)
2015-01-30 13:36:35,829 nginx-nr-agent [DEBUG]: processing stub status for nginxtips.com
2015-01-30 13:36:35,830 nginx-nr-agent [DEBUG]: update derive conn/accepted: pv=921 cv=1175 rv=4.221 td=60.171
2015-01-30 13:36:35,830 nginx-nr-agent [DEBUG]: update derive conn/dropped: pv=0 cv=0 rv=0.000 td=60.171
2015-01-30 13:36:35,830 nginx-nr-agent [DEBUG]: update gauge conn/active: rv=46.00
2015-01-30 13:36:35,830 nginx-nr-agent [DEBUG]: update gauge conn/idle: rv=43.00
2015-01-30 13:36:35,831 nginx-nr-agent [DEBUG]: update derive reqs/total: pv=977 cv=1240 rv=4.371 td=60.171
2015-01-30 13:36:35,831 nginx-nr-agent [DEBUG]: update gauge reqs/current: rv=3.00
2015-01-30 13:36:35,831 nginx-nr-agent [INFO]: polling source1 finished successfully
2015-01-30 13:36:35,831 nginx-nr-agent [DEBUG]: composing push data for nginxtips.com (6 entries)
2015-01-30 13:36:35,831 nginx-nr-agent [INFO]: pushing 8 metrics for 1 components
2015-01-30 13:36:35,832 nginx-nr-agent [DEBUG]: JSON payload: '{"components": [{"duration": 60, "metrics": {"Component/Connections/Idle[Connections]": 43, "Component/Requests/Total[Requests/sec]": 4.3708429275133778, "Component/Connections/Active[Connections]": 46, "Component/ConnSummary/Active[Connections]": 46, "Component/Requests/Current[Requests]": 3, "Component/ConnSummary/Idle[Connections]": 43, "Component/Connections/Accepted[Connections/sec]": 4.221329566804771, "Component/Connections/Dropped[Connections/sec]": 0.0}, "guid": "com.nginx.newrelic-agent", "name": "nginxtips.com"}], "agent": {"version": "2.0.0"}}'
2015-01-30 13:36:35,936 nginx-nr-agent [DEBUG]: response:
Content-Type: application/json
Content-Length: 16
Connection: close

{"status":"ok"}

How do I start the Nginx New Relic plugin?

It’s really as simple as starting any service on Linux:

service nginx-nr-agent start

This service will run as “nobody” user in your system. But you can also start the plugin by running this command:

/usr/bin/nginx-nr-agent.py

These are the available options for nginx-nr-agent.py command:

-c, --config – path to configuration file
-p, --pidfile – path to PID file
-f, --foreground – do not detach from terminal

If you followed every step in this tutorial, at this point you should have your Nginx New Relic plugin ready showing all the data at New Relic panel > Plugins > Nginx.

Newrelic Nginx Plugin

 

 

 

Popular search terms:

  • https://www scalescale com/tips/nginx/nginx-new-relic-plugin/
  • nginx-nr-agent
  • https://www scalescale com/tips/nginx/nginx-new-relic-plugin/#
  • 2897
profile

Esteban Borges

Linux Geek, Webperf Addict, Nginx Fan. CTO @Infranetworking

  • Dongpt

    Hi,

    What is the license key? Is this non-freeware?

    • You can get the license from NR website from your user account, this plugin is 100% free.

  • Gonzalo

    Hi,

    If you have multiple web servers serving one site and you want to aggregate NGINX statistics, do you simply install this agent on each of the nodes and ensure the “name” in the [source1] section is the same across all web servers?

    • Denis

      It doesn’t seem to work that way. I set up multiple nginx instances report with the same name but in NewRelic web ui it isn’t showing multiple servers and it seems to display one of the server’s data. So seems like the “name” field in the “[source1]” should be unique on every instance

      • I too need to aggregate servers into an Application name too, and New Relic support does not have a solution. The name is just the server hostname, and should be treated as such. This could be solved at the NewRelic level by using labels, but it seems strange to me that this is not a default option in the /etc/nginx-nr-agent/nginx-nr-agent.ini file.

        I also do not see the nginx plugin appear in the “PLUGINS” tab of the NewRelic web console.

  • Hmmm, having trouble installing:

    $ sudo yum install nginx-nr-agent
    Loaded plugins: security
    epel/metalink | 8.1 kB 00:00
    epel | 4.4 kB 00:00
    epel/primary_db | 6.7 MB 00:14
    http://packages.icinga.org/epel/6.4/release/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 – “The requested URL returned error: 404 Not Found”
    Trying other mirror.
    Error: Cannot retrieve repository metadata (repomd.xml) for repository: icinga-stable-release. Please verify its path and try again
    [svitla@api-alpha ~]$

  • Shubham Joshi

    Hi getting this error.

    ubuntu@ip-172-31-2-252:/etc/nginx/sites-available$ tail -f /var/log/nginx-nr-agent.log
    2017-03-29 12:20:07,694 nginx-nr-agent [ERROR]: get_status_data() returned nothing to process
    2017-03-29 12:20:07,694 nginx-nr-agent [ERROR]: polling source1 failed
    2017-03-29 12:20:24,216 nginx-nr-agent [INFO]: exiting
    2017-03-29 12:20:24,281 nginx-nr-agent [INFO]: using configuration from /etc/nginx-nr-agent/nginx-nr-agent.ini
    2017-03-29 12:20:24,281 nginx-nr-agent [INFO]: starting with 1 configured data sources, poll_interval=60
    2017-03-29 12:20:24,281 nginx-nr-agent [INFO]: polling source1
    2017-03-29 12:20:24,281 nginx-nr-agent [DEBUG]: getting data from http://stage.overcart.com/status (lastupdate=0.000)
    2017-03-29 12:20:24,330 nginx-nr-agent [ERROR]: request for http://stage.overcart.com/status returned 403
    2017-03-29 12:20:24,330 nginx-nr-agent [ERROR]: get_status_data() returned nothing to process
    2017-03-29 12:20:24,330 nginx-nr-agent [ERROR]: polling source1 failed
    2017-03-29 12:21:24,385 nginx-nr-agent [INFO]: polling source1
    2017-03-29 12:21:24,386 nginx-nr-agent [DEBUG]: getting data from http://stage.overcart.com/status (lastupdate=0.000)
    2017-03-29 12:21:24,387 nginx-nr-agent [ERROR]: request for http://stage.overcart.com/status returned 403
    2017-03-29 12:21:24,388 nginx-nr-agent [ERROR]: get_status_data() returned nothing to process
    2017-03-29 12:21:24,388 nginx-nr-agent [ERROR]: polling source1 failed

    • Shubham Joshi

      ubuntu@ip-172-31-2-252:/etc$ nginx-nr-agent.py -f start
      2017-03-29 13:13:39,502 nginx-nr-agent [INFO]: using configuration from /etc/nginx-nr-agent/nginx-nr-agent.ini
      2017-03-29 13:13:39,503 nginx-nr-agent [INFO]: starting with 1 configured data sources, poll_interval=60
      2017-03-29 13:13:39,503 nginx-nr-agent [INFO]: polling source1
      2017-03-29 13:13:39,503 nginx-nr-agent [DEBUG]: getting data from http://stage.overcart.com/nginx_stub_status (lastupdate=0.000)
      2017-03-29 13:13:40,050 nginx-nr-agent [ERROR]: request for http://stage.overcart.com/nginx_stub_status returned 404
      2017-03-29 13:13:40,050 nginx-nr-agent [ERROR]: get_status_data() returned nothing to process
      2017-03-29 13:13:40,050 nginx-nr-agent [ERROR]: polling source1 failed