Skip to content

Instantly share code, notes, and snippets.

@marceldegraaf
Created January 24, 2013 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marceldegraaf/4620504 to your computer and use it in GitHub Desktop.
Save marceldegraaf/4620504 to your computer and use it in GitHub Desktop.
Chef recipe to add Newrelic's server monitoring daemon to your Ubuntu instances.
default[:newrelic][:apt_repo_key] = '548C16BF'
default[:newrelic][:license] = 'your-key'
default[:newrelic][:log_level] = 'info'
default[:newrelic][:log_file] = '/var/log/newrelic/nrsysmond.log'
default[:newrelic][:proxy] = nil
default[:newrelic][:ssl] = nil
default[:newrelic][:ssl_ca_bundle] = nil
default[:newrelic][:ssl_ca_path] = nil
default[:newrelic][:pidfile] = "/var/run/nrsysmond.pid"
default[:newrelic][:collector_host] = nil
default[:newrelic][:timeout] = nil
# newrelic/templates/default/nrsysmond.cfg.erb
###################
# Generated by Chef
###################
#
# New Relic Server Monitor configuration file.
#
# Lines that begin with a # are comment lines and are ignored by the server
# monitor. For those options that have command line equivalents, if the
# option is specified on the command line it will over-ride any value set
# in this file.
#
#
# Option : license_key
# Value : 40-character hexadecimal string provided by New Relic. This is
# required in order for the server monitor to start.
# Default: none
#
license_key=<%= node[:newrelic][:license] %>
#
# Option : loglevel
# Value : Level of detail you want in the log file (as defined by the logfile
# setting below. Valid values are (in increasing levels of verbosity):
# error - show errors only
# warning - show errors and warnings
# info - show minimal additional information messages
# verbose - show more detailed information messages
# debug - show debug messages
# verbosedebug - show very detailed debug messages
# Default: error
# Note : Can also be set with the -d command line option.
#
loglevel=<%= node[:newrelic][:log_level] %>
#
# Option : logfile
# Value : Name of the file where the server monitor will store it's log
# messages. The amount of detail stored in this file is controlled
# by the loglevel option (above).
# Default: none. However it is highly recommended you set a value for this.
# Note : Can also be set with the -l command line option.
#
logfile=<%= node[:newrelic][:log_file] %>
#
# Option : proxy
# Value : The name and optional login credentials of the proxy server to use
# for all communication with the New Relic collector. In its simplest
# form this setting is just a hostname[:port] setting. The default
# port if none is specified is 1080. If your proxy requires a user
# name, use the syntax user@host[:port]. If it also requires a
# password use the format user:password@host[:port]. For example:
# fred:secret@proxy.mydomain.com:8181
# Default: none (use a direct connection)
#
<% if node[:newrelic][:proxy].nil? %>
#proxy=
<% else %>
proxy=<%= node[:newrelic][:proxy] %>
<% end %>
#
# Option : ssl
# Value : Whether or not to use the Secure Sockets Layer (SSL) for all
# communication with the New Relic collector. Possible values are
# true/on or false/off. In certain rare cases you may need to modify
# the SSL certificates settings below.
# Default: false
#
<% if node[:newrelic][:ssl].nil? %>
#ssl=false
<% else %>
ssl=<%= node[:newrelic][:ssl] %>
<% end %>
#
# Option : ssl_ca_bundle
# Value : The name of a PEM-encoded Certificate Authority (CA) bundle to use
# for SSL connections. This very rarely needs to be set. The monitor
# will attempt to find the bundle in the most common locations. If
# you need to use SSL and the monitor is unable to locate a CA bundle
# then either set this value or the ssl_ca_path option below.
# Default: /etc/ssl/certs/ca-certificates.crt or
# /etc/pki/tls/certs/ca-bundle.crt
# Note : Can also be set with the -b command line option.
#
<% if node[:newrelic][:ssl_ca_bundle].nil? %>
#ssl_ca_bundle=/path/to/your/bundle.crt
<% else %>
ssl_ca_bundle=<%= node[:newrelic][:ssl_ca_bundle] %>
<% end %>
#
# Option : ssl_ca_path
# Value : If your SSL installation does not use CA bundles, but rather has a
# directory with PEM-encoded Certificate Authority files, set this
# option to the name of the directory that contains all the CA files.
# Default: /etc/ssl/certs
# Note : Can also be set with the -S command line option.
#
<% if node[:newrelic][:ssl_ca_path].nil? %>
#ssl_ca_path=/etc/ssl/certs
<% else %>
ssl_ca_path=<%= node[:newrelic][:ssl_ca_path] %>
<% end %>
#
# Option : pidfile
# Value : Name of a file where the server monitoring daemon will store it's
# process ID (PID). This is used by the startup and shutdown script
# to determine if the monitor is already running, and to start it up
# or shut it down.
# Default: /tmp/nrsysmond.pid
# Note : Can also be set with the -p command line option.
#
<% if node[:newrelic][:pidfile].nil? %>
#pidfile=/var/run/newrelic/nrsysmond.pid
<% else %>
pidfile=<%= node[:newrelic][:pidfile] %>
<% end %>
#
# Option : collector_host
# Value : The name of the New Relic collector to connect to. This should only
# ever be changed on advise from a New Relic support staff member.
# The format is host[:port]. Using a port number of 0 means the default
# port, which is 80 (if not using the ssl option - see below) or 443
# if SSL is enabled. If the port is omitted the default value is used.
# Default: collector.newrelic.com
#
<% if node[:newrelic][:collector_host].nil? %>
#collector_host=collector.newrelic.com
<% else %>
collector_host=<%= node[:newrelic][:collector_host] %>
<% end %>
#
# Option : timeout
# Value : How long the monitor should wait to contact the collector host. If
# the connection cannot be established in this period of time, the
# monitor will progressively back off in 15-second increments, up to
# a maximum of 300 seconds. Once the initial connection has been
# established, this value is reset back to the value specified here
# (or the default). This then sets the maximum time to wait for
# a connection to the collector to report data. There is no back-off
# once the original connection has been made. The value is in seconds.
# Default: 30
#
<% if node[:newrelic][:timeout].nil? %>
#timeout=30
<% else %>
timeout=<%= node[:newrelic][:timeout] %>
<% end %>
# newrelic/recipes/default.rb
package "wget"
#
# Download and approve the Newrelic APT repo GPG key
#
apt_repo_key = node[:newrelic][:apt_repo_key]
if apt_repo_key
apt_key_url = "http://download.newrelic.com/#{apt_repo_key}.gpg"
execute "newrelic-add-repo-key" do
command "wget -O - #{apt_key_url} | apt-key add -"
notifies :run, "execute[newrelic-apt-get-update]", :immediately
not_if "apt-key list | grep #{apt_repo_key}"
end
end
#
# Configure Newrelic APT repo package list
#
remote_file "/etc/apt/sources.list.d/newrelic.list" do
source "http://download.newrelic.com/debian/newrelic.list"
owner "root"
group "root"
mode 0644
notifies :run, "execute[newrelic-apt-get-update]", :immediately
action :create_if_missing
end
#
# Update APT package list
#
execute "newrelic-apt-get-update" do
command "apt-get update"
action :nothing
end
#
# Install the Newrelic server monitor
#
package "newrelic-sysmond" do
action :install
end
template "/etc/newrelic/nrsysmond.cfg" do
source "nrsysmond.cfg.erb"
owner "root"
group "newrelic"
mode 0640
notifies :restart, "service[newrelic-sysmond]"
end
#
# Add init service for Newrelic server monitor
#
service "newrelic-sysmond" do
supports :status => true, :start => true, :stop => true, :restart => true
action [ :enable, :start ] #starts the service if it's not running and enables it to start at system boot time
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment