Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions bin/boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ export LD_LIBRARY_PATH=$APP_ROOT/openresty/lib:$LD_LIBRARY_PATH

$(ruby get_env)

if [ -d .nginx-nr-agent ]
then
export PYTHONPATH=.nginx-nr-agent/lib:$PYTHONPATH
if [ ${#NEW_RELIC_LICENSE_KEY} -eq 0 ]
then
export NEW_RELIC_LICENSE_KEY=$(ruby get_credentials newrelic | grep "license" | awk -F "=" '{print $NF}')
fi
erb .nginx-nr-agent/nginx-nr-agent.ini > .nginx-nr-agent/nginx-nr-agent-final.ini
python .nginx-nr-agent/usr/bin/nginx-nr-agent.py -c .nginx-nr-agent/nginx-nr-agent-final.ini -p `pwd`/.nginx-nr-agent/nginx-nr-agent.pid start
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

starting the python daemon that will monitor the nginx process

fi


conf_file=$APP_ROOT/openresty/nginx/conf/nginx.conf

erb $conf_file > $APP_ROOT/openresty/nginx/conf/nginx-final.conf
Expand Down
13 changes: 12 additions & 1 deletion bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,16 @@ if [[ "$(grep directory: Staticfile)X" != "X" ]]; then
touch openresty/nginx/conf/.enable_directory_index
fi

# If we have a newrelic binding
if [[ $VCAP_SERVICES == *"newrelic"* ]]
then
status "Enabling Newrelic monitoring"
$compile_buildpack_dir/compile-extensions/bin/download_dependency nginx-nr-agent.tar.gz /tmp
tar xzf /tmp/nginx-nr-agent.tar.gz
cp $compile_buildpack_dir/conf/nginx-nr-agent.ini .nginx-nr-agent/nginx-nr-agent.ini
fi


cp $compile_buildpack_bin/boot.sh .
cp $compile_buildpack_bin/get_env .
cp $compile_buildpack_bin/get_env .
cp $compile_buildpack_bin/get_credentials .
17 changes: 17 additions & 0 deletions bin/get_credentials
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'rubygems'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usage

ruby get_credentials newrelic
license=******

ruby get_credentials newrelic this will output all the services that has either the tag newrelic or name as newrelic

require 'json'

raise ArgumentError, "Required first parameter missing" if ARGV.length != 1

service = ARGV[0]

parsed_vcap_services=JSON.parse(ENV['VCAP_SERVICES'])
parsed_vcap_services.each do |key, array|
array.each do |serviceMap|
if ( serviceMap["tags"].index(service) || serviceMap["name"].match(/#{service}/))
serviceMap["credentials"].each do |index,value|
puts index+"="+value.to_s+"\n"
end
end
end
end
7 changes: 5 additions & 2 deletions bin/get_env
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'rubygems'
require 'json'
parsed=JSON.parse(ENV['VCAP_SERVICES'])
parsed.each do |key, array|
parsed_vcap_services=JSON.parse(ENV['VCAP_SERVICES'])
parsed_vcap_services.each do |key, array|
array.each do |serviceMap|
serviceMap["credentials"].each do |index,value|
if !(value.class.method_defined? :flatten)
Expand All @@ -10,3 +10,6 @@ parsed.each do |key, array|
end
end
end

parsed_vcap_application=JSON.parse(ENV['VCAP_APPLICATION'])
print "export vcap_application_name="+parsed_vcap_application["application_name"]
46 changes: 46 additions & 0 deletions conf/nginx-nr-agent.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# global settings
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the nginx-nr-agent.ini configuration to be used to run the nginx-nr-agent

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


[global]
newrelic_license_key=<%= ENV["NEW_RELIC_LICENSE_KEY"] %>
poll_interval=60

# logging settings

[loggers]
keys=root

[handlers]
keys=consoleHandler,fileHandler

[formatters]
keys=simpleFormatter

[logger_root]
level=DEBUG
handlers=consoleHandler,fileHandler

[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=simpleFormatter
args=(sys.stdout,)

[handler_fileHandler]
class=FileHandler
level=DEBUG
formatter=simpleFormatter
args=('<%= ENV["APP_ROOT"] %>/.nginx-nr-agent/logs/nginx-nr-agent.log','a',)

[formatter_simpleFormatter]
format=%(asctime)s %(name)s [%(levelname)s]: %(message)s
datefmt=

# data sources settings

[source1]
<% if ENV["NEW_RELIC_APP_NAME"] %>
name=<%= ENV["NEW_RELIC_APP_NAME"] %>
<% else %>
name=<%= ENV["vcap_application_name"] %>
<% end %>
url=http://localhost:<%= ENV["PORT"] %>/nginx_status
11 changes: 10 additions & 1 deletion conf/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ error_log <%= ENV["APP_ROOT"] %>/openresty/nginx/logs/error.log;
events { worker_connections 1024; }

http {
log_format cloudfoundry '$http_x_forwarded_for - $http_referer - [$time_local] "$request" $status $body_bytes_sent';
log_format cloudfoundry 'Instance-<%= ENV["CF_INSTANCE_INDEX"] %>|$time_local|$http_x_forwarded_for|$upstream_addr|$upstream_response_time|$request|$http_user_agent|$request_time';
access_log <%= ENV["APP_ROOT"] %>/openresty/nginx/logs/access.log cloudfoundry;
default_type application/octet-stream;
include mime.types;
Expand All @@ -28,6 +28,15 @@ http {
listen <%= ENV["PORT"] %>;
server_name localhost;

<% if ENV["NEW_RELIC_LICENSE_KEY"] %>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line will have to be added to any application using this buildpack wanting to be monitored by newrelic

location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
<% end %>

location / {
root <%= ENV["APP_ROOT"] %>/public;
index index.html index.htm Default.htm;
Expand Down
17 changes: 13 additions & 4 deletions manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,21 @@ exclude_files:
url_to_dependency_map:
- match: openresty.tgz
name: openresty
version: 1.8.0
version: 1.7.10.2
- match: nginx-nr-agent.tar.gz
name: nginx-nr-agent
version: 2.0.0.6

dependencies:
- name: openresty
version: 1.8.0
uri: https://raw.githubusercontent.com/muymoo/staticfile-buildpack/files/openresty-1.7.10.1.tar.gz
version: 1.7.10.2
uri: https://raw.githubusercontent.com/muymoo/staticfile-buildpack/files/vendor/openresty-1.7.10.2.tar.gz
cf_stacks:
- cflinuxfs2
md5: ae7ee6fb6891578c6b59c67d85219e81
md5: bd5a79fc76b1238eb9ecc6d23d53f6cc
- name: nginx-nr-agent
version: 2.0.0.6
uri: https://raw.githubusercontent.com/muymoo/staticfile-buildpack/files/vendor/nginx-nr-agent.tar.gz
cf_stacks:
- cflinuxfs2
md5: 1d674e2c403a48743d90830b2c7172b1