Skip to content
Browse files

initial commit of nrsysmond.rb

  • Loading branch information...
1 parent 2446cc2 commit 8b43d52dad93f94a9bb8f604eff4af466a4e6093 @davidcollom committed Apr 5, 2013
Showing with 46 additions and 0 deletions.
  1. +46 −0 nrsysmond.rb
View
46 nrsysmond.rb
@@ -0,0 +1,46 @@
+set :newrelic_licencekey, 'NEWRELIC LICENCE KEY HERE'
+
+namespace :newrelic do
+ desc 'Installs the newrelic sysmond'
+ namespace :sysmond do
+ task :default do
+ unless remote_file_exists? '/etc/newrelic/nrsysmond.cfg'
+ debian if remote_file_exists? '/etc/debian_version'
+ redhat if remote_file_exists? '/etc/redhat-release'
+ end
+ end
+ task :debian do
+ run 'if [! -e /etc/apt/sources.list.d/newrelic.list ]; then echo "deb http://apt.newrelic.com/debian/ newrelic non-free" > /etc/apt/sources.list.d/newrelic.list; fi'
+ run 'wget -O- http://download.newrelic.com/548C16BF.gpg | sudo apt-key add -'
+ sudo 'apt-get update && apt-get install newrelic-sysmond'
+ configure
+ end
+ task :redhat do
+ sudo "rpm -Uvh http://yum.newrelic.com/pub/newrelic/el5/$(uname -m)/newrelic-repo-5-3.noarch.rpm || true"
+ sudo "yum install -y newrelic-sysmond"
+ configure
+ end
+ desc 'configure the newrelic-sysmond service with the :newrelic_licencekey'
+ task :configure do
+ sudo "/usr/sbin/nrsysmond-config --set license_key=#{newrelic_licencekey}"
+ restart
+ end
+
+ %W{stop start restart}.each do |com|
+ desc "#{com}'s the newrelic-sysmond service"
+ task com.to_sym do
+ sudo "/etc/init.d/newrelic-sysmond #{com}"
+ end
+ end
+ end
+end
+
+def remote_file_exists?(path)
+ results = []
+
+ invoke_command("if [ -e '#{path}' ]; then echo -n 'true'; fi") do |ch, stream, out|
+ results << (out == 'true')
+ end
+
+ results == [true]
+end

0 comments on commit 8b43d52

Please sign in to comment.
Something went wrong with that request. Please try again.