How to install New Relic Agent in Google App Engine Flexible Environment

og-newrelic-logo

New Relic provides Application Performance Monitoring (APM) for a lot of platforms (AWS, Heroku, etc.) and frameworks (Symphony, Magento, etc.), but there is no much information on the internet so far about steps to install New Relic Agent in Google App Engine (GAE) Flexible Environment (Flex Env), so I did try installing successfully on my production project and then will talk about it here.

Step 1: Create a custom docker image based on Google cloud platform php docker, php nginx image — on local (i.e. mac)

/php-docker/php-nginx/build-scripts/install_new_relic.sh

# A shell script for installing New Relic agent.
set -xe

DEBIAN_FRONTEND=noninteractive echo 'deb http://apt.newrelic.com/debian/ newrelic non-free' | tee /etc/apt/sources.list.d/newrelic.list

DEBIAN_FRONTEND=noninteractive apt-get -y install wget
DEBIAN_FRONTEND=noninteractive wget -O- https://download.newrelic.com/548C16BF.gpg | apt-key add -

DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y vim less
DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends apt-utils

DEBIAN_FRONTEND=noninteractive apt-get install -yq newrelic-php5
DEBIAN_FRONTEND=noninteractive newrelic-install install

/php-docker/php-nginx/Dockerfile

# Setup environment variables for initializing New Relic
ENV NR_INSTALL_SILENT 1
ENV NEW_RELIC_APP_NAME "YourAppName"
ENV NR_APP_NAME "YourAppName"
ENV NR_INSTALL_KEY YourLicenseKey
RUN /bin/bash /build-scripts/install_new_relic.sh

Step 2: Build, tag and upload to Google Cloud Storage (work under application directory) — on local (i.e. mac)

docker build -t php-nginx-new_relic .
docker tag php-nginx-new_relic gcr.io/project-id/php-nginx-new_relic
gcloud docker -- push gcr.io/project-id/php-nginx-new_relic

Step 3: Deploy your project to Google App Engine Flexible Environment — on local (i.e. mac)

gcloud app deploy app.yaml --project project-id --verbosity debug || exit $?

(/YourApp/Dockerfile)

FROM gcr.io/project-id/php-nginx-new_relic

Step 4: ssh to the GAE Flex Env instance and enter docker container — remote GAE Flex Env instance

(Tips: SSH button is located in Google Cloud Platform dashboard, App Engine page, instances sub page, then click the SSH button will let you ssh to the instance)

Step 5: enter docker container — remote GAE Flex Env instance

sudo docker exec -t -i gaeapp /bin/bash

Step 6Install New Relic with installation script manually — remote GAE Flex Env instance docker container gaeapp

wget -r -l1 -nd -A"linux.tar.gz" https://download.newrelic.com/php_agent/release/

gzip -dc newrelic*.tar.gz | tar xf -

cd newrelic-php5*

rm -f /opt/php56/lib/x86_64-linux-gnu/extensions/no-debug-non-zts-20131226/newrelic.so

cp ./agent/x64/newrelic-20131226.so /opt/php56/lib/x86_64-linux-gnu/extensions/no-debug-non-zts-20131226/newrelic.so

cp ./daemon/newrelic-daemon.x64 /usr/bin/newrelic-daemon

(Set your license key and application name. Be sure to replace yourLicenseKey and yourApplicationName with your real license key and the app name you desire.)

sed -i -e 's/"REPLACE_WITH_REAL_KEY"/yourLicenseKey/g' ./scripts/newrelic.ini.template

sed -i -e 's/PHP Application/yourApplicationName/g' ./scripts/newrelic.ini.template

(((cp ./scripts/newrelic.ini.template /opt/php56/lib/ext.enabled:/opt/php56/lib/conf.d:/app/newrelic.ini, it’s suggested by New Relic but complained error for me, so I separate into 3 steps as following)))

cp ./scripts/newrelic.ini.template /opt/php56/lib/ext.enabled/newrelic.ini

cp ./scripts/newrelic.ini.template /opt/php56/lib/conf.d/newrelic.ini

cp ./scripts/newrelic.ini.template /app/newrelic.ini

/usr/bin/newrelic-daemon start

Step 7: Restart everything and reload the page
kill -HUP 1
(Restart your webserver and reload this page. If New Relic is loaded you should see a congratulatory message.)
congrats
Donate $5 to me for a coffee with PayPal and read more professional and interesting technical blog articles. Feel free to visit my web app, WhizWallet, to apply for credit, store or gift cards, DealsPlus to browse daily deals and store coupons to save money.
Follow me @Yaoli0615 at Twitter to get latest tech updates.
Reference:
Caveat and tips:

1. Copy paste in GAE Flex Env docker container: tips to scroll and copy at GAE instance docker container (for debugging by view text file with vim which was configured to install in php-nginx Dockerfile if you need vim)

Mac touchpad to select all in the current screen and use Fn+Shift+Down to go up to previous screen and select again with touchpad until select all content in the text file
2. New Relic to monitor Docker container application
3. dockerizing a php application
4. If you want to install New Relic agent in pure automatic way:

Use runtime:custom and add required piece in your Dockerfile, except for the `/usr/bin/newrelic-daemon start` line.
Then have a file named `additional-supervisord.conf` with the following:

“`

[program:newrelic-daemon]

command = /usr/bin/newrelic-daemon -f

stdout_logfile = /dev/stdout

stdout_logfile_maxbytes=0

stderr_logfile = /dev/stderr

stderr_logfile_maxbytes=0

user = root

autostart = true

autorestart = true

priority = 5

stopwaitsecs = 20

“`

5. If you install New Relic on CentOS, yum and rpm installation don’t work for me, but tar ball file works for me and the command should be

./newrelic-install install

 

not

./newrelic-install

as the doc:

Advertisements

About liyao13

Yao Li is a web and iOS developer, blogger and he has a passion for technology and business. In his blogs, he shares code snippets, tutorials, resources and notes to help people develop their skills. Donate $5 to him for a coffee with PayPal at About Me page and read more professional and interesting technical blog articles. Follow him @Yaoli0615 at Twitter to get latest tech updates.
This entry was posted in CS Research&Application, Uncategorized and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s