diff --git a/cookbooks/newrelic_plugins/CHANGELOG.md b/cookbooks/newrelic_plugins/CHANGELOG.md new file mode 100644 index 00000000..e7fc6ba2 --- /dev/null +++ b/cookbooks/newrelic_plugins/CHANGELOG.md @@ -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. diff --git a/cookbooks/newrelic_plugins/README.md b/cookbooks/newrelic_plugins/README.md new file mode 100644 index 00000000..b6983938 --- /dev/null +++ b/cookbooks/newrelic_plugins/README.md @@ -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) + diff --git a/cookbooks/newrelic_plugins/files/default/newrelic_plugin_agent.initd b/cookbooks/newrelic_plugins/files/default/newrelic_plugin_agent.initd new file mode 100755 index 00000000..dddbdf18 --- /dev/null +++ b/cookbooks/newrelic_plugins/files/default/newrelic_plugin_agent.initd @@ -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 diff --git a/cookbooks/newrelic_plugins/files/default/newrelic_plugin_agent.monitrc b/cookbooks/newrelic_plugins/files/default/newrelic_plugin_agent.monitrc new file mode 100644 index 00000000..fa72dedc --- /dev/null +++ b/cookbooks/newrelic_plugins/files/default/newrelic_plugin_agent.monitrc @@ -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 diff --git a/cookbooks/newrelic_plugins/recipes/default.rb b/cookbooks/newrelic_plugins/recipes/default.rb new file mode 100644 index 00000000..55290c11 --- /dev/null +++ b/cookbooks/newrelic_plugins/recipes/default.rb @@ -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 diff --git a/cookbooks/newrelic_plugins/spec/default_spec.rb b/cookbooks/newrelic_plugins/spec/default_spec.rb new file mode 100644 index 00000000..7c2c8fc8 --- /dev/null +++ b/cookbooks/newrelic_plugins/spec/default_spec.rb @@ -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 diff --git a/cookbooks/newrelic_plugins/spec/fauxhai.json b/cookbooks/newrelic_plugins/spec/fauxhai.json new file mode 100644 index 00000000..e93f2168 --- /dev/null +++ b/cookbooks/newrelic_plugins/spec/fauxhai.json @@ -0,0 +1,434 @@ +{ + "kernel": { + "name": "Linux", + "release": "3.4.45-amazon-xen", + "version": "#1 SMP Fri May 17 17:56:50 Local time zone must be set--see zic", + "machine": "x86_64", + "modules": { + "ipv6": { + "size": "258465", + "refcount": "20" + } + }, + "os": "GNU/Linux" + }, + "os": "linux", + "os_version": "3.4.45-amazon-xen", + "platform": "gentoo", + "platform_version": "2.1", + "platform_family": "gentoo", + "ohai_time": 1371660529.723438, + "command": { + "ps": "ps -ef" + }, + "dmi": { + }, + "filesystem": { + "rootfs": { + "kb_size": "15481840", + "kb_used": "4739932", + "kb_available": "9955476", + "percent_used": "33%", + "mount": "/", + "fs_type": "rootfs", + "mount_options": [ + "rw" + ] + }, + "/dev/root": { + "kb_size": "15481840", + "kb_used": "4739932", + "kb_available": "9955476", + "percent_used": "33%", + "mount": "/", + "fs_type": "ext4", + "mount_options": [ + "rw", + "relatime", + "data=ordered" + ] + }, + "tmpfs": { + "kb_size": "867920", + "kb_used": "200", + "kb_available": "867720", + "percent_used": "1%", + "mount": "/run", + "fs_type": "tmpfs", + "mount_options": [ + "rw", + "nosuid", + "nodev", + "relatime", + "mode=755" + ] + }, + "udev": { + "kb_size": "10240", + "kb_used": "0", + "kb_available": "10240", + "percent_used": "0%", + "mount": "/dev", + "fs_type": "devtmpfs", + "mount_options": [ + "rw", + "nosuid", + "relatime", + "size=10240k", + "nr_inodes=216800", + "mode=755" + ] + }, + "shm": { + "kb_size": "867920", + "kb_used": "0", + "kb_available": "867920", + "percent_used": "0%", + "mount": "/dev/shm", + "fs_type": "tmpfs", + "mount_options": [ + "rw", + "nosuid", + "nodev", + "noexec", + "relatime" + ] + }, + "cgroup_root": { + "kb_size": "10240", + "kb_used": "0", + "kb_available": "10240", + "percent_used": "0%", + "mount": "/sys/fs/cgroup", + "fs_type": "tmpfs", + "mount_options": [ + "rw", + "nosuid", + "nodev", + "noexec", + "relatime", + "size=10240k", + "mode=755" + ] + }, + "/dev/xvdb": { + "kb_size": "350891748", + "kb_used": "1623556", + "kb_available": "331443912", + "percent_used": "1%", + "mount": "/mnt", + "fs_type": "ext3", + "mount_options": [ + "rw", + "user_xattr" + ], + "uuid": "f1b8188c-4c90-4ec5-ae4c-614c1b1773a3" + }, + "/dev/xvdz1": { + "kb_size": "15481840", + "kb_used": "174396", + "kb_available": "14521012", + "percent_used": "2%", + "mount": "/data", + "fs_type": "ext3", + "mount_options": [ + "rw" + ], + "uuid": "7ee820ef-56c7-461d-ba24-0667aaaa4200" + }, + "/dev/xvdz2": { + "kb_size": "15481840", + "kb_used": "387576", + "kb_available": "14307832", + "percent_used": "3%", + "mount": "/db", + "fs_type": "ext3", + "mount_options": [ + "rw" + ], + "uuid": "3ec63161-19ec-46c2-95f7-1f0cd509c000" + }, + "proc": { + "mount": "/proc", + "fs_type": "proc", + "mount_options": [ + "rw", + "nosuid", + "nodev", + "noexec", + "relatime" + ] + }, + "devpts": { + "mount": "/dev/pts", + "fs_type": "devpts", + "mount_options": [ + "rw", + "nosuid", + "noexec", + "relatime", + "gid=5", + "mode=620", + "ptmxmode=000" + ] + }, + "sysfs": { + "mount": "/sys", + "fs_type": "sysfs", + "mount_options": [ + "rw", + "nosuid", + "nodev", + "noexec", + "relatime" + ] + }, + "openrc": { + "mount": "/sys/fs/cgroup/openrc", + "fs_type": "cgroup", + "mount_options": [ + "rw", + "nosuid", + "nodev", + "noexec", + "relatime", + "release_agent=/lib64/rc/sh/cgroup-release-agent.sh", + "name=openrc" + ] + }, + "cpuset": { + "mount": "/sys/fs/cgroup/cpuset", + "fs_type": "cgroup", + "mount_options": [ + "rw", + "nosuid", + "nodev", + "noexec", + "relatime", + "cpuset" + ] + }, + "cpu": { + "mount": "/sys/fs/cgroup/cpu", + "fs_type": "cgroup", + "mount_options": [ + "rw", + "nosuid", + "nodev", + "noexec", + "relatime", + "cpu" + ] + }, + "cpuacct": { + "mount": "/sys/fs/cgroup/cpuacct", + "fs_type": "cgroup", + "mount_options": [ + "rw", + "nosuid", + "nodev", + "noexec", + "relatime", + "cpuacct" + ] + }, + "devices": { + "mount": "/sys/fs/cgroup/devices", + "fs_type": "cgroup", + "mount_options": [ + "rw", + "nosuid", + "nodev", + "noexec", + "relatime", + "devices" + ] + }, + "freezer": { + "mount": "/sys/fs/cgroup/freezer", + "fs_type": "cgroup", + "mount_options": [ + "rw", + "nosuid", + "nodev", + "noexec", + "relatime", + "freezer" + ] + }, + "blkio": { + "mount": "/sys/fs/cgroup/blkio", + "fs_type": "cgroup", + "mount_options": [ + "rw", + "nosuid", + "nodev", + "noexec", + "relatime", + "blkio" + ] + }, + "perf_event": { + "mount": "/sys/fs/cgroup/perf_event", + "fs_type": "cgroup", + "mount_options": [ + "rw", + "nosuid", + "nodev", + "noexec", + "relatime", + "perf_event" + ] + }, + "/mnt/log": { + "mount": "/var/log", + "fs_type": "none", + "mount_options": [ + "rw", + "bind" + ] + }, + "/db/mysql.d": { + "mount": "/etc/mysql.d", + "fs_type": "none", + "mount_options": [ + "rw", + "bind" + ] + }, + "/dev/xvda1": { + "fs_type": "ext4", + "uuid": "c2d9ec1e-ed87-4b31-93a4-ec2ab9385b91", + "label": "rootfs" + }, + "/dev/xvda3": { + "fs_type": "swap", + "uuid": "efbeed7e-5957-49bb-8e08-6756eeaf591f" + } + }, + "languages": { + "ruby": { + "platform": "x86_64-linux", + "version": "1.9.3", + "release_date": "2013-05-15", + "target": "x86_64-pc-linux-gnu", + "target_cpu": "x86_64", + "target_vendor": "pc", + "target_os": "linux", + "host": "x86_64-pc-linux-gnu", + "host_cpu": "x86_64", + "host_os": "linux-gnu", + "host_vendor": "pc", + "bin_dir": "/usr/local/bin", + "ruby_bin": "/usr/local/bin/ruby", + "gems_dir": "/usr/local/gems", + "gem_bin": "/usr/local/bin/gem" + } + }, + "chef_packages": { + "chef": { + "version": "11.4.4", + "chef_root": "/usr/local/gems/chef-11.4.4/lib" + }, + "ohai": { + "version": "6.16.0", + "ohai_root": "/usr/local/gems/ohai-6.16.0/lib/ohai" + } + }, + "counters": { + "network": { + "interfaces": { + "eth0": { + "rx": { + "bytes": "0", + "packets": "0", + "errors": "0", + "drop": 0, + "overrun": 0, + "frame": 0, + "compressed": 0, + "multicast": 0 + }, + "tx": { + "bytes": "342", + "packets": "0", + "errors": "0", + "drop": 0, + "overrun": 0, + "collisions": "0", + "carrier": 0, + "compressed": 0 + } + } + } + } + }, + "current_user": "fauxhai", + "domain": "local", + "etc": { + "passwd": { + "fauxhai": { + "dir": "/home/fauxhai", + "gid": 0, + "uid": 0, + "shell": "/bin/bash", + "gecos": "Fauxhai" + } + }, + "group": { + "fauxhai": { + "gid": 0, + "members": [ + "fauxhai" + ] + } + } + }, + "hostname": "Fauxhai", + "fqdn": "fauxhai.local", + "ipaddress": "10.0.0.2", + "keys": { + "ssh": { + "host_dsa_public": "ssh-dss AAAAB3NzaC1kc3MAAACBAJFo9BLAw4WKEs5hgipk5m423FzBsDXCZSMcC9ca/om/1VYzMqImixGe3uICDzNFUWxFoLJTQAOccyzo6MXZiQqwWJDLFi5qOSr6w2XcMyE+zd4wOyMoDiVM5fizmG8K3FzrqvGjwBcHcBdOQnavSijoj38DN25J9zhrid5BY4WlAAAAFQDxXrCyG52XCzn3FV4ej38wJBkomQAAAIBovGPJ4mP2P6BK8lHl0PPbktwQbWlpJ13oz6REJFDVcUi7vV26bX/BjQX+ohzZQzljdz1SpUbPc/8nuA4darYkVh91eBi307EN8IdxRHj2eBgp/ZG4yshIebG3WHrwJD/xUjjZ1MRfyDT1ermVi4LvjjPgWDxLZnPpMaR6S1nzgQAAAIEAj0Vd6DCWslvlsZ8+N53HWsqPi3gnx35JoLPz9Z2epkKIKqmEHav+93G3hdfztVa4I4t3phoPniQchYryF5+RNg8hqxKzjNtrIqUYCeuf2NJrksNsH7OZygPHZpqt4kTuwAGZxjxEGfAI0y8DhkU2ntp2LnzRnWH106BQBCmcXwo= fauxhai.local", + "host_rsa_public": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCtLCeqtqr/HbnORckw1ukdLhpfGoOPFi5/esKEokzTqq1gsgQ2V8emmyjfq1i6XXfRtSBxkdlHv/GWdP5wBTuE2G85MzBkVSQPvmwQN8lX/JMPEEtKXkeOo0o92/PiSmvY4eRsdF0mw40Uvg7jtE3f3fxj497kzh5fKtkrHnF4x9gXCbVdr3FqXJfggR5IJwAxToerbK7x/uRS+7YuZI9Pip3tt14nv9ezwXcuGb/tvjWOZINiFl8izVIFKi7sxfTX09p4NgamxRS7TD2Yd0jT8nEoF9UZTsgXcJ1kDSx7N7NxFfNfP6rCdOGRRz4gUhXtsUjG/XkxPeCwZ7A9VnOD fauxhai.local" + } + }, + "macaddress": "11:11:11:11:11:11", + "network": { + "default_gateway": "10.0.0.1", + "default_interface": "eth0", + "eth0": { + "addresses": { + "10.0.0.2": { + "broadcast": "10.0.0.255", + "family": "inet", + "netmask": "255.255.255.0", + "prefixlen": "23", + "scope": "Global" + } + }, + "arp": { + "10.0.0.1": "fe:ff:ff:ff:ff:ff" + }, + "encapsulation": "Ethernet", + "flags": [ + "BROADCAST", + "MULTICAST", + "UP", + "LOWER_UP" + ], + "mtu": "1500", + "number": "0", + "routes": { + "10.0.0.0/255": { + "scope": "link", + "src": "10.0.0.2" + } + }, + "state": "up", + "type": "eth" + } + }, + "uptime": "30 days 15 hours 07 minutes 30 seconds", + "uptime_seconds": 2646450 +} diff --git a/cookbooks/newrelic_plugins/spec/spec_helper.rb b/cookbooks/newrelic_plugins/spec/spec_helper.rb new file mode 100644 index 00000000..468d080e --- /dev/null +++ b/cookbooks/newrelic_plugins/spec/spec_helper.rb @@ -0,0 +1 @@ +require 'chefspec' diff --git a/cookbooks/newrelic_plugins/templates/default/newrelic_plugin_agent.yml.erb b/cookbooks/newrelic_plugins/templates/default/newrelic_plugin_agent.yml.erb new file mode 100644 index 00000000..5584d4b2 --- /dev/null +++ b/cookbooks/newrelic_plugins/templates/default/newrelic_plugin_agent.yml.erb @@ -0,0 +1,99 @@ +%YAML 1.2 +--- + +# Uncomment sections below to enable plugins. Please see documentation at +# https://github.com/MeetMe/newrelic-plugin-agent#installation-instructions for +# further information + +Application: + license_key: <%= @license_key %> + poll_interval: 60 + + #apache_httpd: + # name: hostname + # host: localhost + # port: 80 + # path: /server-status + + #couchdb: + # name: localhost + # host: localhost + # port: 5984 + + #edgecast: + # name: My Edgecase Account + # account: YOUR_ACCOUNT_# + # token: YOUR_API_TOKEN + + #memcached: + # name: localhost + # host: localhost + # port: 11211 + + #mongodb: + # name: hostname + # host: localhost + # port: 27017 + # databases: + # - test + # - yourdbname + + #nginx: + # name: hostname + # host: localhost + # port: 80 + # path: /nginx_stub_status + + # pgbouncer: + # host: localhost + # port: 6000 + # user: stats + + # postgresql: + # host: localhost + # port: 5432 + # user: postgres + # dbname: postgres + + #rabbitmq: + # name: rabbitmq@localhost + # host: localhost + # port: 15672 + # username: guest + # password: guest + + #redis: + # - name: localhost + # host: localhost + # port: 6379 + # db_count: 16 + + #riak: + # name: localhost + # host: node0.riak0.scs.mtmeprod.net + # port: 8098 + + +Daemon: + pidfile: /var/run/newrelic_plugin_agent.pid + +Logging: + formatters: + verbose: + format: '%(levelname) -10s %(asctime)s %(process)-6d %(processName) -15s %(threadName)-10s %(name) -45s %(funcName) -25s L%(lineno)-6d: %(message)s' + handlers: + file: + class : logging.handlers.RotatingFileHandler + formatter: verbose + filename: /var/log/newrelic/newrelic_plugin_agent.log + maxBytes: 10485760 + backupCount: 3 + loggers: + newrelic_plugin_agent: + level: INFO + propagate: True + handlers: [console, file] + requests: + level: ERROR + propagate: True + handlers: [console, file]