Skip to content

Instantly share code, notes, and snippets.

@rahul286
Last active April 12, 2018 03:19
Show Gist options
  • Save rahul286/76d4e8c708e73d460a649f1f15bb819d to your computer and use it in GitHub Desktop.
Save rahul286/76d4e8c708e73d460a649f1f15bb819d to your computer and use it in GitHub Desktop.
newrelic setup

Get NEWRELIC_LICENSE_KEY from https://rpm.newrelic.com/accounts/

export NEWRELIC_LICENSE_KEY=___CHANGE___THIS___TO___NEWRELIC_LICENSE_KEY____
curl -s https://gist.githubusercontent.com/rahul286/76d4e8c708e73d460a649f1f15bb819d/raw/fcf0024655705db5d11013929d200edb82f607e0/install.sh | bash

Stop newrelic

#service newrelic-daemon stop
service newrelic-sysmond stop
service php7.0-fpm stop
cd /root/newrelic-npi && ./npi stop nrmysql
pkill newrelic
#sudo systemctl stop newrelic-infra

Start newrelic

#service newrelic-daemon start
service newrelic-sysmond start
service php7.0-fpm start
cd /root/newrelic-npi && ./npi start nrmysql
newrelic-plugin-agent -c /etc/newrelic/newrelic-plugin-agent.cfg
#sudo systemctl start newrelic-infra

EasyEngine fix

EE enables nginx-default site which doesn't have config to handle /nginx_status or /status. So FPM and Nginx plugin won't send any data.

So edit /etc/nginx/sites-enabled/default and add following line inside default_server block

# Status pages
location /nginx_status {
  stub_status on;
  access_log off;
  include common/acl.conf;
}
location ~ ^/(status|ping) {
  include fastcgi_params;
  fastcgi_pass php7;
  include common/acl.conf;
}

Note: FPM will show status for PHP7. If you are using PHP5, change fastcgi_pass php7; to fastcgi_pass php;

Test

Check output for folllowing requests:

curl localhost/nginx_status
curl localhost/status
# get NEWRELIC_LICENSE_KEY from https://rpm.newrelic.com/accounts/
# export NEWRELIC_LICENSE_KEY=___CHANGE___THIS___TO___NEWRELIC_LICENSE_KEY____
[ -z "$NEWRELIC_LICENSE_KEY" ] && { echo "Please export NEWRELIC_LICENSE_KEY"; exit 1; }
#debian repo
echo 'deb http://apt.newrelic.com/debian/ newrelic non-free' | sudo tee /etc/apt/sources.list.d/newrelic.list
wget -O- https://download.newrelic.com/548C16BF.gpg | sudo apt-key add -
sudo apt-get update
sudo apt-get install newrelic-php5 newrelic-sysmond
#system monitor
nrsysmond-config --set license_key=$NEWRELIC_LICENSE_KEY
service newrelic-sysmond restart
# php-fpm 5.6 config
echo 'newrelic.transaction_tracer.record_sql = "raw"' >> /etc/php/5.6/mods-available/newrelic.ini
echo 'newrelic.transaction_tracer.threshold = "1s"' >> /etc/php/5.6/mods-available/newrelic.ini
echo 'newrelic.framework="wordpress"' >> /etc/php/5.6/mods-available/newrelic.ini
service php5.6-fpm restart
# php-fpm 7.0 config
echo 'newrelic.transaction_tracer.record_sql = "raw"' >> /etc/php/7.0/mods-available/newrelic.ini
echo 'newrelic.transaction_tracer.threshold = "1s"' >> /etc/php/7.0/mods-available/newrelic.ini
echo 'newrelic.framework="wordpress"' >> /etc/php/7.0/mods-available/newrelic.ini
service php7.0-fpm restart
# not needed - newrelic-daemon is started internally by php agent
# cp /etc/newrelic/newrelic.cfg.template /etc/newrelic/newrelic.cfg
# Install npi
cd ~
LICENSE_KEY=$NEWRELIC_LICENSE_KEY && bash -c "$(curl https://download.newrelic.com/npi/release/install-npi-linux-debian-x64.sh)"
cd ~/newrelic-npi
# install java for mysql
apt-get install -y default-jre
# intsall newrelic plugin for mysql
./npi install com.newrelic.plugins.mysql.instance
# setup mysql grants for newrelic agent
mysql < ./plugins/com.newrelic.plugins.mysql.instance/newrelic_mysql_plugin-2.0.0/mysql_user.sql
# stop mysql plugin
./npi stop nrmysql
# remove mysql user and password lines from plugin.json
vim ./plugins/com.newrelic.plugins.mysql.instance/newrelic_mysql_plugin-2.0.0/config/plugin.json
# verify mysql start
./npi start nrmysql --foreground
# normal start
./npi start nrmysql
# verify list
./npi list
#Should see something like:
#root@aws:~/newrelic-npi# ./npi list
#- com.newrelic.plugins.mysql.instance:
# - State:
# Downloaded [x]
# Prepared [x]
# Installed [x]
# Running [x]
# Install https://github.com/MeetMe/newrelic-plugin-agent#installation-instructions plugins
apt-get install -y python-pip
pip install newrelic-plugin-agent
# agent config
# cp /opt/newrelic-plugin-agent/newrelic-plugin-agent.cfg /etc/newrelic/newrelic-plugin-agent.cfg
wget -O /etc/newrelic/newrelic-plugin-agent.cfg https://gist.githubusercontent.com/rahul286/76d4e8c708e73d460a649f1f15bb819d/raw/045e9ea294fcde1993fcb2c968c7bef6f64a2c87/newrelic-plugin-agent.cfg
sed -i.bak "s/NEWRELIC_LICENSE_KEY/${NEWRELIC_LICENSE_KEY}/" /etc/newrelic/newrelic-plugin-agent.cfg
# run agent
newrelic-plugin-agent -c /etc/newrelic/newrelic-plugin-agent.cfg
# get NEWRELIC_LICENSE_KEY from https://rpm.newrelic.com/accounts/
# export NEWRELIC_LICENSE_KEY=___CHANGE___THIS___TO___NEWRELIC_LICENSE_KEY____
[ -z "$NEWRELIC_LICENSE_KEY" ] && { echo "Please export NEWRELIC_LICENSE_KEY"; exit 1; }
#debian repo
echo 'deb http://apt.newrelic.com/debian/ newrelic non-free' | sudo tee /etc/apt/sources.list.d/newrelic.list
wget -O- https://download.newrelic.com/548C16BF.gpg | sudo apt-key add -
sudo apt-get update
sudo apt-get install newrelic-php5 newrelic-sysmond
#system monitor
nrsysmond-config --set license_key=$NEWRELIC_LICENSE_KEY
service newrelic-sysmond restart
# php-fpm 7.0 config (going ahead we wont be using PHP 5.6)
echo 'newrelic.transaction_tracer.record_sql = "raw"' >> /etc/php/7.0/mods-available/newrelic.ini
echo 'newrelic.transaction_tracer.threshold = "1s"' >> /etc/php/7.0/mods-available/newrelic.ini
echo 'newrelic.framework="wordpress"' >> /etc/php/7.0/mods-available/newrelic.ini
service php7.0-fpm restart
# not needed - newrelic-daemon is started internally by php agent
# cp /etc/newrelic/newrelic.cfg.template /etc/newrelic/newrelic.cfg
###############################################################
## newrelic-plugins for fpm status, nginx status, redis metric
###############################################################
# Install https://github.com/MeetMe/newrelic-plugin-agent#installation-instructions plugins
apt-get install -y python-pip
pip install newrelic-plugin-agent
# agent config
# cp /opt/newrelic-plugin-agent/newrelic-plugin-agent.cfg /etc/newrelic/newrelic-plugin-agent.cfg
wget -O /etc/newrelic/newrelic-plugin-agent.cfg https://gist.githubusercontent.com/rahul286/76d4e8c708e73d460a649f1f15bb819d/raw/045e9ea294fcde1993fcb2c968c7bef6f64a2c87/newrelic-plugin-agent.cfg
sed -i.bak "s/NEWRELIC_LICENSE_KEY/${NEWRELIC_LICENSE_KEY}/" /etc/newrelic/newrelic-plugin-agent.cfg
# run agent
newrelic-plugin-agent -c /etc/newrelic/newrelic-plugin-agent.cfg
%YAML 1.2
---
Application:
license_key: NEWRELIC_LICENSE_KEY
wake_interval: 60
#memcached:
# name: localhost
#host: localhost
#port: 11211
# path: /path/to/unix/socket
nginx:
name: nginx
scheme: http
host: localhost
port: 80
path: /nginx_status
php_fpm:
- name: fpm
scheme: http
host: localhost
port: 80
path: /status
query: json
redis:
- name: redis
host: localhost
port: 6379
Daemon:
user: newrelic
pidfile: /var/run/newrelic/newrelic-plugin-agent.pid
Logging:
formatters:
verbose:
format: '%(levelname) -10s %(asctime)s %(process)-6d %(processName) -15s %(threadName)-10s %(name) -45s %(funcName) -25s L%(lineno)-6d: %(message)s'
handlers:
file:
class : logging.handlers.RotatingFileHandler
formatter: verbose
filename: /var/log/newrelic/newrelic-plugin-agent.log
maxBytes: 10485760
backupCount: 3
loggers:
newrelic_plugin_agent:
level: INFO
propagate: True
handlers: [console, file]
requests:
level: ERROR
propagate: True
handlers: [console, file]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment