MaintenanceGuidelines/Monitoring: newrelic.sh

File newrelic.sh, 1.2 KB (added by Fran Boon, 8 years ago)

Install New Relic monitoring on a Debian server

Line 
1#!/bin/bash
2set -e
3if [[ -z "$1" ]]; then
4 echo -e "What is the path to the Web2Py install? : \c "
5 read WEB2PY
6else
7 WEB2PY=$1
8fi
9if [[ -z "$2" ]]; then
10 echo -e "What is the Applicaton Name? : \c "
11 read APPNAME
12else
13 APPNAME=$2
14fi
15if [[ -z "$3" ]]; then
16 echo -e "What license-key should we use? : \c "
17 read LICENSE
18else
19 LICENSE=$3
20fi
21
22# App Monitoring
23apt-get install -y python-pip
24pip install newrelic
25
26cd $WEB2PY
27newrelic-admin generate-config $LICENSE newrelic.ini
28sed -i "s|Python Application|$APPNAME|" $WEB2PY/newrelic.ini
29#sed -i "s|#log_file|log_file|" $WEB2PY/newrelic.ini
30
31sed -i "/^import gluon.main$/i \
32import newrelic.agent\n\
33newrelic.agent.initialize('newrelic.ini')\n\
34" $WEB2PY/wsgihandler.py
35
36sed -i "/^<\/uwsgi>$/i \
37 <enable-threads\/>\n\
38 <single-interpreter\/>\n\
39 <lazy-apps\/>" $WEB2PY/uwsgi.xml
40
41/etc/init.d/uwsgi-prod restart
42
43# Server Monitoring
44cat << EOF > "/etc/apt/sources.list.d/newrelic.list"
45deb http://apt.newrelic.com/debian/ newrelic non-free
46EOF
47wget -O- http://download.newrelic.com/548C16BF.gpg | apt-key add -
48apt-get update
49apt-get install newrelic-sysmond
50nrsysmond-config --set license_key=$LICENSE
51/etc/init.d/newrelic-sysmond start