Skip to content
This repository has been archived by the owner on Apr 21, 2020. It is now read-only.

Malnick/haproxy plugin #40

Open
wants to merge 26 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
89 changes: 89 additions & 0 deletions manifests/haproxy.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Install the newrelic haproxy agent
# Example:
# class profiles::newrelic::haproxy_plugin {
#
# $license_key = hiera('newrelic_license_key')
# $haproxy_agents = {
# 'qa_haproxy_internal' => {
# 'uri' => 'http://10.0.3.131:22002/;csv',
# 'proxy' => 'http-in',
# 'proxy_type' => 'FRONTEND',
# }
# }
#
# class { ::newrelic_plugins::haproxy:
# license_key => $license_key,
# haproxy_agents => $haproxy_agents,
# }
#}
#
# Meta
# Author: github/malnick
######################################################

class newrelic_plugins::haproxy (

$license_key,
$base_install = false,
$haproxy_agents = undef,

){

package { 'make':
ensure => present,
}

package { 'newrelic_haproxy_agent':
ensure => present,
provider => 'gem',
require => Package['make','bundler'],
}

package { 'newrelic_plugin':
ensure => present,
provider => 'gem',
require => Package['make','bundler'],
}

package { 'bundler':
ensure => present,
provider => 'gem',
require => Package['make'],
}

file { 'newrelic_haproxy_agent_init':
ensure => file,
path => '/etc/init.d/newrelic_haproxy_plugin',
mode => '0755',
owner => 'root',
group => 'root',
content => template('newrelic_plugins/haproxy/newrelic_haproxy_plugin.erb'),
}

if $base_install {
# If base install then install the standard yml, no config
exec {'base_install':
command => '/usr/local/bin/newrelic_haproxy_agent run',
creates => '/etc/newrelic/newrelic_haproxy_agent.yml',
require => Package['newrelic_haproxy_agent','newrelic_plugin'],
}
}

else {
# If we're using the configured install, ensure haproxy_agents is a hash
validate_hash($haproxy_agents)
# Configure the yaml file - requires that haproxy_agents hash is not empty
file { '/etc/newrelic/newrelic_haproxy_agent.yml':
ensure => file,
mode => '0644',
content => template('newrelic_plugins/haproxy/newrelic_haproxy_agent.yml.erb'),
require => Package['newrelic_haproxy_agent','newrelic_plugin'],
}
}

service { 'newrelic_haproxy_plugin':
ensure => running,
enable => true,
subscribe => File['newrelic_haproxy_agent_init','/etc/newrelic/newrelic_haproxy_agent.yml'],
}
}
36 changes: 36 additions & 0 deletions templates/haproxy/newrelic_haproxy_agent.yml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
##########################
# Managed by Your Mother #
##########################
newrelic:
#
# Update with your New Relic account license key:
#
license_key: <%= @license_key %>
#
# Set to '1' for verbose output, remove for normal output.
# All output goes to stdout/stderr.
#
verbose: 0
#
# Agent Configuration:
#
agents:
<% if @haproxy_agents -%>
<% @haproxy_agents.each do |a,b| -%>
<%= a %>:
# URI of the haproxy CSV stats url. See the 'CSV Export' link on your haproxy stats page (example stats page: http://demo.1wt.eu/).
uri: <%= b['uri'] %>
# The name of the proxy to monitor. Proxies are typically listed in the haproxy.cfg file.
proxy: <%= b['proxy'] %> #http-in
# If multiple proxies have the same name, specify which proxy you want to monitor (ex: 'frontend' or 'backend')."
proxy_type: <%= b['proxy_type'] %> #FRONTEND
# If protected under basic authentication provide the user name
<% if b['user'] -%>
user: <%= b['user'] %>
# If protected under basic authentication provide the password.
password: <%= b['password'] %>
<% end -%>
<% end -%>
<% else %>
<% abort "Must pass haproxy_agents hash" %>
<% end -%>
79 changes: 79 additions & 0 deletions templates/haproxy/newrelic_haproxy_plugin.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/sh

### BEGIN INIT INFO
# Required-Start: $syslog $remote_fs
# Required-Stop: $syslog $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: New Relic <%= @plugin_name %> Plugin
# Description: Controls the New Relic <%= @plugin_name %> Plugin
### END INIT INFO

DESC="New Relic <%= @plugin_name %> Plugin Daemon"
NAME="newrelic_haproxy_agent"
DAEMONDIR=/var/log/
PIDFILE=/var/run/$NAME.pid

get_pid() {
cat "$PIDFILE"
}

is_running() {
[ -f "$PIDFILE" ] && ps `get_pid` > /dev/null 2>&1
}

start() {
if is_running; then
echo "Already Started $NAME"
else
echo "Starting $NAME"
cd $DAEMONDIR
touch $PIDFILE
newrelic_haproxy_agent run >> $DAEMONDIR/newrelic_haproxy_agent.log 2>&1 & echo $! > $PIDFILE
fi
}

status() {
if is_running; then
echo "$NAME $VERSION is running"
else
echo "$NAME $VERSION is stopped"
exit 1
fi
}

stop() {
if is_running; then
echo "Stopping $NAME"
kill `get_pid`
else
echo "$NAME is not running"
fi
}

restart() {
stop
sleep 1
start
}

case "${1}" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
*)
echo "Usage: ${0} {start|stop|restart|status}"
exit 1
;;
esac

exit 0