Last active
September 8, 2015 05:43
-
-
Save ravibhure/321d4fbdbff7d1886bf7 to your computer and use it in GitHub Desktop.
Install newrelic system daemon for python app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Ref: https://docs.newrelic.com/docs/servers/new-relic-servers-linux/installation-configuration/servers-installation-ubuntu-debian | |
# https://docs.newrelic.com/docs/agents/python-agent/installation-configuration/python-agent-integration | |
# Usage: $0 <your key> | |
YOUR_LICENSE_KEY=$1 | |
# define spinner function for slow tasks | |
spinner() | |
{ | |
local pid=$1 | |
local delay=0.75 | |
local spinstr='|/-\' | |
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do | |
local temp=${spinstr#?} | |
printf " [%c] " "$spinstr" | |
local spinstr=$temp${spinstr%"$temp"} | |
sleep $delay | |
printf "\b\b\b\b\b\b" | |
done | |
printf " \b\b\b\b" | |
} | |
# Configure the New Relic apt repository. | |
echo 'deb http://apt.newrelic.com/debian/ newrelic non-free' | tee /etc/apt/sources.list.d/newrelic.list | |
# Trust the New Relic GPG key. | |
wget -q -O- https://download.newrelic.com/548C16BF.gpg | apt-key add - | |
# Update the local package list. | |
(apt-get -y update > /dev/null 2>&1) & | |
spinner $! | |
# Install Servers for Linux. | |
(apt-get -q -y install newrelic-sysmond > /dev/null 2>&1) & | |
spinner $! | |
if [ -z $YOUR_LICENSE_KEY ] ;then | |
read -ep "Enter your newrelic license key:" YOUR_LICENSE_KEY | |
fi | |
# Configure your New Relic license key. | |
nrsysmond-config --set license_key=$YOUR_LICENSE_KEY | |
echo | |
echo "Optional: You can set the license_key configuration setting directly in /etc/newrelic/nrsysmond.cfg instead." | |
# Start nrsysmond. | |
/etc/init.d/newrelic-sysmond start && echo "NewRelic system agent configuration done and start successful" || echo "Failed to start newrelic system daemon" && exit 1 | |
echo | |
_install_py_agent(){ | |
echo "Starting python agent installation steps ...." | |
# Install newrelic python agent | |
(pip install newrelic > /dev/null 2>&1) & | |
spinner $! | |
# | |
newrelic-admin generate-config $YOUR_LICENSE_KEY newrelic.ini | |
cat > newrelic.ini << EOF | |
[newrelic] | |
license_key = $YOUR_LICENSE_KEY | |
app_name = Python Application | |
monitor_mode = true | |
log_file = /tmp/newrelic-python-agent.log | |
log_level = info | |
ssl = true | |
high_security = false | |
capture_params = false | |
ignored_params = | |
transaction_tracer.enabled = true | |
transaction_tracer.transaction_threshold = apdex_f | |
transaction_tracer.record_sql = obfuscated | |
transaction_tracer.stack_trace_threshold = 0.5 | |
transaction_tracer.explain_enabled = true | |
transaction_tracer.explain_threshold = 0.5 | |
transaction_tracer.function_trace = | |
error_collector.enabled = true | |
error_collector.ignore_errors = | |
browser_monitoring.auto_instrument = true | |
thread_profiler.enabled = true | |
[newrelic:development] | |
monitor_mode = false | |
[newrelic:test] | |
monitor_mode = false | |
[newrelic:staging] | |
app_name = Python Application (Staging) | |
monitor_mode = true | |
[newrelic:production] | |
app_name = Python Application (Production) | |
monitor_mode = true | |
EOF | |
echo "Agent install done, starting newrelic test for python agent" | |
# Testing python agent | |
newrelic-admin validate-config newrelic.ini | |
# your newrelic config ini is here.... | |
echo "your newrelic config ini is here...." | |
echo | |
echo | |
# now add these lines manually to your wsgi init file | |
echo ============================================================= | |
echo "now add these lines manually to your wsgi init file" | |
echo "import newrelic.agent " | |
echo "newrelic.agent.initialize('/some/path/newrelic.ini')" | |
echo ============================================================= | |
} | |
# ref url: | |
echo 'https://docs.newrelic.com/docs/agents/java-agent/installation/java-agent-manual-installation' | |
# Exit with smile | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment