Skip to content
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
3 changes: 3 additions & 0 deletions cookbooks/main/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,6 @@
# postgresql9_pg_buffercache "postgres"
# postgresql9_pg_freespacemap "postgres"
#end

# uncomment to include the StatsD-Librato recipe
# require_recipe "statsd-librato"
27 changes: 27 additions & 0 deletions cookbooks/statsd-librato/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# StatsD with Librato Metrics backend

## Overview

This is a simple chef recipe that installs [StatsD](https://github.com/etsy/statsd) with [Librato Metrics](https://metrics.librato.com) backend.

## Requirements

* An active [Librato Metrics](https://metrics.librato.com/sign_up) account.

## Configuration

* Set your [Librato Metrics](https://metrics.librato.com) credentials in ```cookbooks/recipes/defatult.rb```.

```ruby
librato_email = "you@example.com"
librato_token = "your-token-goes-here"
```

## Enabling

* Enable the recipe in ```cookbooks/main/recipes/default.rb```.

```ruby
# uncomment to include the StatsD-Librato recipe
require_recipe "statsd-librato"
```
73 changes: 73 additions & 0 deletions cookbooks/statsd-librato/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#
# Cookbook Name:: statsd-librato
# Recipe:: default
#

# Set your Librato credentials
librato_email = "you@example.com"
librato_token = "your-token-goes-here"

# Set your app name
app_name = "your-app-name-goes-here"

# Set install dir for statsd
src_dir = "/usr/lib/statsd"

statsd_port = 8126

statsd_enabled_env = ['production'].include?(node[:environment][:framework_env])
statsd_enabled_instance = ['app_master', 'app'].include?(node[:instance_role])

if statsd_enabled_env && statsd_enabled_instance
execute "install statsd" do
command "git clone git://github.com/etsy/statsd.git"
cwd "/usr/lib"
not_if { File.exists?("#{src_dir}/.git/")}
user "root"
end

execute "install statsd-librato-backend" do
command "npm install statsd-librato-backend"
cwd "/usr/lib/statsd"
not_if { File.exists?("#{src_dir}/node_modules/statsd-librato-backend/package.json")}
user "root"
end

template "/data/#{app_name}/shared/config/statsd.js" do
owner node[:owner_name]
group node[:owner_name]
mode 0644
source "config.js.erb"
variables({
:statsd_port => port,
:librato_email => librato_email,
:librato_token => librato_token
})
end

template "/data/#{app_name}/shared/statsd" do
owner node[:owner_name]
group node[:owner_name]
mode 0744
source "statsd.erb"
variables({
:src_dir => src_dir,
:app_name => app_name
})
end

template "/etc/monit.d/statsd.monitrc" do
owner node[:owner_name]
group node[:owner_name]
mode 0644
source "monitrc.conf.erb"
variables({
:user => node[:owner_name],
:app_name => app_name
})
end

execute "monit reload" do
action :run
end
end
8 changes: 8 additions & 0 deletions cookbooks/statsd-librato/templates/default/config.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
port: <%= @statsd_port %>,
backends: [ "statsd-librato-backend" ],
librato: {
email: "<%= @librato_email %>",
token: "<%= @librato_token %>"
}
}
5 changes: 5 additions & 0 deletions cookbooks/statsd-librato/templates/default/monitrc.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
check process statsd
with pidfile /data/<%= @app_name %>/shared/pids/statsd.pid
start = "/data/<%= @app_name %>/shared/statsd start" as uid <%= @user %> and gid <%= @user %>
stop = "/data/<%= @app_name %>/shared/statsd stop" as uid <%= @user %> and gid <%= @user %>
group statsd
14 changes: 14 additions & 0 deletions cookbooks/statsd-librato/templates/default/statsd.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

case $1 in
start)
echo $$ > /data/<%= @app_name %>/shared/pids/statsd.pid;
exec 2>&1 node <%= @src_dir %>/stats.js /data/<%= @app_name %>/shared/config/statsd.js
;;
stop)
kill `cat /data/<%= @app_name %>/shared/pids/statsd.pid` ;;
*)
echo "usage: statsd {start|stop}" ;;

esac
exit 0