Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newrelic plugins #113

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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 cookbooks/newrelic_plugins/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# CHANGELOG for newrelic_plugins

This file is used to list changes made in each version of newrelic_plugins.

## 0.1.0:

* Initial release of newrelic_plugins

- - -
Check the [Markdown Syntax Guide](http://daringfireball.net/projects/markdown/syntax) for help with Markdown.

The [Github Flavored Markdown page](http://github.github.com/github-flavored-markdown/) describes the differences between markdown on github and standard markdown.
31 changes: 31 additions & 0 deletions cookbooks/newrelic_plugins/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# NOTE: Compatible with new Gentoo stack only

------------

newrelic_plugins Cookbook
=========================

Install the newrelic_plugin_agent on your Engine Yard Cloud environment

Usage
-----

1. Make sure that New Relic has been enabled for your environment
2. Include the recipe in the `main/recipes/default.rb` recipe

```
include_recipe 'newrelic_plugins'
```

Customization
-----

By default, the recipe will install the same plugins on every instance. If you
need different ones on different instances, copy the newrelic_plugin_agent.yml
file and enable the relevent ones. Then customize the recipe to write the template
based on the instance role/name.

Example:
- Template file with 'redis' enabled on the 'redis' utility instance(s)
- Template file with 'memcached' enabled on the 'memcached' instance(s)

131 changes: 131 additions & 0 deletions cookbooks/newrelic_plugins/files/default/newrelic_plugin_agent.initd
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#!/bin/bash
# chkconfig: 2345 99 60
# description: newrelic_plugin_agent
# processname: newrelic_plugin_agent
# config: /etc/sysconfig/newrelic_plugin_agent
# pidfile: /var/run/newrelic_plugin_agent.pid

# Source function library.
. /etc/init.d/functions.sh

# Application
APP="/usr/bin/newrelic_plugin_agent"

# Configuration dir
CONFIG_DIR="/etc"

# PID File
PID_FILE="/var/run/newrelic_plugin_agent.pid"

# Additional arguments
OPTS=""

if [ -f /etc/sysconfig/newrelic_plugin_agent ]; then
# Include configuration
. /etc/sysconfig/newrelic_plugin_agent
fi

# Configuration file
CONF="${CONF:-${CONFIG_DIR}/newrelic_plugin_agent.yml}"

if [ ! -f "${CONF}" ]; then
echo -n $"cannot find newrelic_plugin_agent configuration file: '${CONF}'"
failure $"cannot find newrelic_plugin_agent configuration file: '${CONF}'"
echo
exit 1
fi

OPTS="-c ${CONF} ${OPTS}"

dostatus() {
[ -e "${PID_FILE}" ] || return 1

local pid=$(cat ${PID_FILE})
[ -d /proc/${pid} ] || return 1

[ -z "$(grep $APP /proc/${pid}/cmdline)" ] && return 1
return 0
}

start() {
if [ ${EUID} -ne 0 ]; then
echo -n $"you must be root"
failure $"you must be root"
echo
return 1
fi

echo -n $"Starting ${APP}: "

dostatus
if [ $? -eq 0 ]; then
echo -n $"cannot start $APP: already running (pid: $(cat ${PID_FILE}))";
failure $"cannot start $APP: already running (pid: $(cat ${PID_FILE}))";
echo
return 1
fi

${APP} ${OPTS} # && success || failure
RETVAL=$?

echo
return ${RETVAL}
}

stop() {
if [ ${EUID} -ne 0 ]; then
echo -n $"you must be root"
failure $"you must be root"
echo
return 1
fi

echo -n $"Stopping ${APP}: "

dostatus
if [ $? -ne 0 ]; then
echo -n $"cannot stop $APP: not running"
failure $"cannot stop $APP: not running"
echo
return 1
fi

kill `cat ${PID_FILE}`
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f ${PID_FILE}
echo
return $RETVAL
}

restart() {
stop
start
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
dostatus
if [ $? -eq 0 ]; then
echo $"$APP: running"
RETVAL=0
else
echo $"$APP: not running"
RETVAL=1
fi
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
RETVAL=2
;;
esac

exit $RETVAL
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
check process newrelic_plugin_agent
with pidfile /var/run/newrelic_plugin_agent.pid
start program = "/etc/init.d/newrelic_plugin_agent start"
stop program = "/etc/init.d/newrelic_plugin_agent stop"
group newrelic_plugin_agent
50 changes: 50 additions & 0 deletions cookbooks/newrelic_plugins/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
# Cookbook Name:: newrelic_plugins
# Recipe:: default
#
# Copyright 2013, Engine Yard, Inc
#
# All rights reserved - Do Not Redistribute
#

easy_install_package 'pip' do
action :install
end

bash 'install newrelic-plugin-agent' do
user 'root'
code 'pip install newrelic-plugin-agent'
end

template '/etc/newrelic_plugin_agent.yml' do
source 'newrelic_plugin_agent.yml.erb'
owner 'root'
group 'root'
mode 0644
variables(
:license_key => ''
)
end

cookbook_file '/etc/monit.d/newrelic_plugin_agent.monitrc' do
source 'newrelic_plugin_agent.monitrc'
owner 'root'
group 'root'
mode 0644
end

cookbook_file '/etc/init.d/newrelic_plugin_agent' do
source 'newrelic_plugin_agent.initd'
owner 'root'
group 'root'
mode 0755
end

bash 'add to run level' do
user 'root'
code 'rc-update add newrelic_plugin_agent default'
end

execute 'monit reload' do
action :run
end
40 changes: 40 additions & 0 deletions cookbooks/newrelic_plugins/spec/default_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require_relative 'spec_helper'

describe 'newrelic_plugins' do
before do
Fauxhai.mock :path => 'cookbooks/newrelic_plugins/spec/fauxhai.json' do |node|

end
end
let(:chef_run) { ChefSpec::ChefRunner.new.converge 'newrelic_plugins::default' }

it "should install the newrelic-plugin-agent with pip" do
expect(chef_run).to execute_bash_script 'install newrelic-plugin-agent'
end

it "should create the newrelic_plugin_agent.yml template" do
expect(chef_run).to create_file '/etc/newrelic_plugin_agent.yml'
file = chef_run.template '/etc/newrelic_plugin_agent.yml'
expect(file).to be_owned_by 'root', 'root'
end

it "should create the monit file" do
expect(chef_run).to create_cookbook_file '/etc/monit.d/newrelic_plugin_agent.monitrc'
file = chef_run.cookbook_file '/etc/monit.d/newrelic_plugin_agent.monitrc'
expect(file).to be_owned_by 'root', 'root'
end

it "should create the init.d script" do
expect(chef_run).to create_cookbook_file '/etc/init.d/newrelic_plugin_agent'
file = chef_run.cookbook_file '/etc/init.d/newrelic_plugin_agent'
expect(file).to be_owned_by 'root', 'root'
end

it "should add newrelic_plugin_agent to the default run level" do
expect(chef_run).to execute_bash_script 'add to run level'
end

it "should reload monit" do
expect(chef_run).to execute_command 'monit reload'
end
end
Loading