Skip to content

Commit

Permalink
add librato backend support fix #1
Browse files Browse the repository at this point in the history
* move backend config to statsd::backends
* add aditional parameters for influxdb
  • Loading branch information
jdowning committed Apr 13, 2014
1 parent cd6f4b8 commit 61b2774
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 63 deletions.
22 changes: 22 additions & 0 deletions manifests/backends.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# ==Class: statsd::backends
class statsd::backends {
# If we have an InfluxDB host, install the proper backend
if $statsd::influxdb_host {
exec { 'install-statsd-influxdb-backend':
command => '/usr/bin/npm install --save statsd-influxdb-backend',
cwd => "${statsd::node_module_dir}/statsd",
unless => "/usr/bin/test -d ${statsd::node_module_dir}/statsd/node_modules/statsd-influxdb-backend",
require => Package['statsd'],
}
}

# If we have a Librato token, install the proper backend
if $statsd::librato_email and $statsd::librato_token {
exec { 'install-statsd-librato-backend':
command => '/usr/bin/npm install --save statsd-librato-backend',
cwd => "${statsd::node_module_dir}/statsd",
unless => "/usr/bin/test -d ${statsd::node_module_dir}/statsd/node_modules/statsd-librato-backend",
require => Package['statsd'],
}
}
}
10 changes: 0 additions & 10 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@
$logfile = '/var/log/statsd/statsd.log'
$statsjs = "${statsd::node_module_dir}/statsd/stats.js"

# If we have an InfluxDB host, let's install the proper backend
if $statsd::influxdb_host {
exec { 'install-statsd-influxdb-backend':
command => '/usr/bin/npm install --save statsd-influxdb-backend',
cwd => "${statsd::node_module_dir}/statsd",
unless => "/usr/bin/test -d ${statsd::node_module_dir}/statsd/node_modules/statsd-influxdb-backend",
require => Package['statsd'],
}
}

file { '/etc/statsd':
ensure => directory,
mode => '0755',
Expand Down
69 changes: 42 additions & 27 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,34 +1,49 @@
# == Class statsd
class statsd (
$ensure = $statsd::params::ensure,
$port = $statsd::params::port,
$graphiteHost = $statsd::params::graphiteHost,
$graphiteport = $statsd::params::graphitePort,

$backends = $statsd::params::backends,
$debug = $statsd::params::debug,
$address = $statsd::params::address,
$mgmt_address = $statsd::params::mgmt_address,
$mgmt_port = $statsd::params::mgmt_port,
$statsd_title = $statsd::params::statsd_title,
$healthStatus = $statsd::params::healthStatus,
$dumpMessages = $statsd::params::dumpMessages,
$flushInterval = $statsd::params::flushInterval,
$percentThreshold = $statsd::params::percentThreshold,
$flush_counts = $statsd::params::flush_counts,

$influxdb_host = $statsd::params::influxdb_host,
$influxdb_port = $statsd::params::influxdb_port,
$influxdb_database = $statsd::params::influxdb_database,
$influxdb_username = $statsd::params::influxdb_username,
$influxdb_password = $statsd::params::influxdb_password,

$config = $statsd::params::config,

$node_module_dir = $statsd::params::node_module_dir,
$init_script = $statsd::params::init_script,
$ensure = $statsd::params::ensure,
$node_module_dir = $statsd::params::node_module_dir,

$port = $statsd::params::port,
$address = $statsd::params::address,

$graphiteHost = $statsd::params::graphiteHost,
$graphiteport = $statsd::params::graphitePort,

$backends = $statsd::params::backends,
$debug = $statsd::params::debug,
$mgmt_address = $statsd::params::mgmt_address,
$mgmt_port = $statsd::params::mgmt_port,
$statsd_title = $statsd::params::statsd_title,
$healthStatus = $statsd::params::healthStatus,
$dumpMessages = $statsd::params::dumpMessages,
$flushInterval = $statsd::params::flushInterval,
$percentThreshold = $statsd::params::percentThreshold,
$flush_counts = $statsd::params::flush_counts,

$influxdb_host = $statsd::params::influxdb_host,
$influxdb_port = $statsd::params::influxdb_port,
$influxdb_database = $statsd::params::influxdb_database,
$influxdb_username = $statsd::params::influxdb_username,
$influxdb_password = $statsd::params::influxdb_password,
$influxdb_flush = $statsd::params::influxdb_flush,
$influxdb_proxy = $statsd::params::influxdb_proxy,
$influxdb_proxy_suffix = $statsd::params::influxdb_proxy_suffix,
$influxdb_proxy_flushInterval = $statsd::params::influxdb_proxy_flushInterval,

$librato_email = $statsd::params::librato_email,
$librato_token = $statsd::params::librato_token,
$librato_snapTime = $statsd::params::librato_snapTime,
$librato_countersAsGauges = $statsd::params::librato_countersAsGauges,
$librato_skipInternalMetrics = $statsd::params::librato_skipInternalMetrics,
$librato_retryDelaySecs = $statsd::params::librato_retryDelaySecs,
$librato_postTimeoutSecs = $statsd::params::librato_postTimeoutSecs,

$config = $statsd::params::config,

$init_script = $statsd::params::init_script,
) inherits statsd::params {

class { 'statsd::backends': }
class { 'statsd::config': }

package { 'statsd':
Expand Down
56 changes: 34 additions & 22 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -1,32 +1,44 @@
# == Class statsd::params
class statsd::params {
$ensure = 'present'
$node_module_dir = '/usr/lib/node_modules'
$ensure = 'present'
$node_module_dir = '/usr/lib/node_modules'

$port = '8125'
$port = '8125'
$address = '0.0.0.0'

$graphiteHost = 'localhost'
$graphitePort = '2003'
$graphiteHost = 'localhost'
$graphitePort = '2003'

$backends = [ './backends/graphite' ]
$debug = false
$address = '0.0.0.0'
$mgmt_address = '0.0.0.0'
$mgmt_port = '8126'
$statsd_title = 'statsd'
$healthStatus = 'up'
$dumpMessages = false
$flushInterval = '10000'
$percentThreshold = ['90']
$flush_counts = true
$backends = [ './backends/graphite' ]
$debug = false
$mgmt_address = '0.0.0.0'
$mgmt_port = '8126'
$statsd_title = 'statsd'
$healthStatus = 'up'
$dumpMessages = false
$flushInterval = '10000'
$percentThreshold = ['90']
$flush_counts = true

$influxdb_host = ''
$influxdb_port = '8086'
$influxdb_database = ''
$influxdb_username = 'root'
$influxdb_password = 'root'
$influxdb_host = ''
$influxdb_port = '8086'
$influxdb_database = 'statsd'
$influxdb_username = 'root'
$influxdb_password = 'root'
$influxdb_flush = true
$influxdb_proxy = false
$influxdb_proxy_suffix = 'raw'
$influxdb_proxy_flushInterval = '10000'

$config = { }
$librato_email = ''
$librato_token = ''
$librato_snapTime = '10000'
$librato_countersAsGauges = true
$librato_skipInternalMetrics = true
$librato_retryDelaySecs = '5'
$librato_postTimeoutSecs = '4'

$config = { }

case $::osfamily {
'RedHat', 'Amazon': {
Expand Down
1 change: 1 addition & 0 deletions spec/classes/statsd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
let(:facts) { { :osfamily => 'Debian' } }

it { should contain_class("statsd::params") }
it { should contain_statsd__backends }
it { should contain_statsd__config }
it { should contain_package('statsd').with_ensure('present') }
it { should contain_service('statsd').with_ensure('running') }
Expand Down
21 changes: 17 additions & 4 deletions templates/localConfig.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,28 @@
username: "<%= @influxdb_username %>",
password: "<%= @influxdb_password %>",
flush: {
enable: true
enable: <%= @influxdb_flush %>
},
proxy: {
enable: false,
suffix: "raw",
flushInterval: "<%= @flushInterval %>"
enable: <%= @influxdb_proxy %>,
suffix: "<%= @influxdb_proxy_suffix %>",
flushInterval: "<%= @influxdb_proxy_flushInterval %>"
}
}
<% end -%>

<% if @librato_email && @librato_token -%>
, librato: {
email: "<%= @librato_email %>",
token: "<%= @librato_token %>",
snapTime: "<%= @librato_snapTime %>",
countersAsGauges: "<%= @librato_countersAsGauges %>",
skipInternalMetrics: "<%= @librato_skipInternalMetrics %>",
retryDelaySecs: "<%= @librato_retryDelaySecs %>",
postTimeoutSecs: "<%= @librato_postTimeoutSecs %>"
}
<% end -%>

<% @config.each do |k, v| -%>
, <%= k %>: <%= v %>
<% end -%>
Expand Down

0 comments on commit 61b2774

Please sign in to comment.