From 61b2774a9edc6fb8aae423590468cedb2d0b441e Mon Sep 17 00:00:00 2001 From: Justin Downing Date: Sun, 13 Apr 2014 14:40:26 -0400 Subject: [PATCH] add librato backend support fix #1 * move backend config to statsd::backends * add aditional parameters for influxdb --- manifests/backends.pp | 22 ++++++++++++ manifests/config.pp | 10 ------ manifests/init.pp | 69 ++++++++++++++++++++++-------------- manifests/params.pp | 56 +++++++++++++++++------------ spec/classes/statsd_spec.rb | 1 + templates/localConfig.js.erb | 21 ++++++++--- 6 files changed, 116 insertions(+), 63 deletions(-) create mode 100644 manifests/backends.pp diff --git a/manifests/backends.pp b/manifests/backends.pp new file mode 100644 index 0000000..404bc66 --- /dev/null +++ b/manifests/backends.pp @@ -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'], + } + } +} diff --git a/manifests/config.pp b/manifests/config.pp index 0b9c432..0ab37cf 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -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', diff --git a/manifests/init.pp b/manifests/init.pp index 378d282..0d2b6de 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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': diff --git a/manifests/params.pp b/manifests/params.pp index c4977e7..7547b8a 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -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': { diff --git a/spec/classes/statsd_spec.rb b/spec/classes/statsd_spec.rb index 195c31b..c74522d 100644 --- a/spec/classes/statsd_spec.rb +++ b/spec/classes/statsd_spec.rb @@ -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') } diff --git a/templates/localConfig.js.erb b/templates/localConfig.js.erb index 74b2e85..ddb4e6b 100644 --- a/templates/localConfig.js.erb +++ b/templates/localConfig.js.erb @@ -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 -%>