Permalink
Browse files

Add ability to search for graphite host based on graphite_query attri…

…bute
  • Loading branch information...
1 parent f9aa871 commit 92babe5dc766ad1472958a0e3198a8fd77e23c5c Chris Ferry committed Jun 18, 2013
Showing with 14 additions and 2 deletions.
  1. +3 −1 attributes/default.rb
  2. +11 −1 recipes/default.rb
@@ -5,8 +5,10 @@
default["statsd"]["flush_interval"] = 10000
default["statsd"]["address"] = "0.0.0.0"
default["statsd"]["port"] = 8125
-default["statsd"]["graphite_host"] = "localhost"
+default["statsd"]["graphite_host"] = "127.0.0.1"
default["statsd"]["graphite_port"] = 2003
+default['statsd']['graphite_role'] = 'graphite_server'
+default['statsd']['graphite_query'] = "roles:#{node['statsd']['graphite_role']} AND chef_environment:#{node.chef_environment}"
default["statsd"]["delete_timers"] = false
default["statsd"]["delete_gauges"] = false
View
@@ -12,6 +12,16 @@
action :create
end
+graphite_host = node['statsd']['graphite_host']
+
+unless Chef::Config[:solo]
+ graphite_results = search(:node, node['statsd']['graphite_query'])
+
+ unless graphite_results.empty?
+ graphite_host = graphite_results[0]['ipaddress']
+ end
+end
+
template "#{node["statsd"]["conf_dir"]}/config.js" do
mode "0644"
source "config.js.erb"
@@ -20,7 +30,7 @@
:port => node["statsd"]["port"],
:flush_interval => node["statsd"]["flush_interval"],
:graphite_port => node["statsd"]["graphite_port"],
- :graphite_host => node["statsd"]["graphite_host"],
+ :graphite_host => graphite_host,
:delete_gauges => node["statsd"]["delete_gauges"],
:delete_timers => node["statsd"]["delete_timers"],
:legacy_namespace => node["statsd"]["graphite"]["legacy_namespace"],

0 comments on commit 92babe5

Please sign in to comment.