Skip to content

Instantly share code, notes, and snippets.

@tomduckering
Last active December 16, 2015 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomduckering/5345788 to your computer and use it in GitHub Desktop.
Save tomduckering/5345788 to your computer and use it in GitHub Desktop.
define :dd_jmx_entry, :jmx_port => [],:extra_config => {} do
include_recipe 'columbus_monitoring::datadog'
app_name = params[:name]
jmx_port = params[:jmx_port]
config_file_path = '/etc/dd-agent/conf.d/jmx.yaml.disabled'
global_base_config = { 'init_config' => nil, 'instances'=> [] }
app_config = { 'host' => 'localhost', 'port' => jmx_port, 'name' => app_name, 'conf'=> [] }
memory_bean_config = {
'include'=>
{
'domain'=>'java.lang',
'bean'=>'Memory',
'attribute'=>
{
'HeapMemoryUsage.used'=>
{
'metric_type'=>'gauge',
'alias'=>'JVMHeapMemoryUsed'
}
}
}
}
app_config['conf'] << memory_bean_config
# Deal with adding extra config...
#if !params[:extra_config].nil?
# app_config['conf'] << params[:extra_config]
#end
config_file_template_resource = nil
begin
config_file_template_resource = resources(:template => config_file_path)
rescue Chef::Exceptions::ResourceNotFound
config_file_template_resource = template config_file_path do
source 'jmx.yaml.erb'
owner 'dd-agent'
group 'root'
mode 0644
cookbook "columbus_app"
variables({:data => global_base_config })
notifies :restart, 'service[datadog-agent]', :delayed
end
end
Chef::Log.debug "Current data is: #{config_file_template_resource.variables[:data]}"
config_file_template_resource.variables[:data]['instances'] << app_config
Chef::Log.debug "After, data is : #{config_file_template_resource.variables[:data]}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment