Skip to content

Instantly share code, notes, and snippets.

@tomduckering
Created June 21, 2013 16:17
Show Gist options
  • Save tomduckering/5832357 to your computer and use it in GitHub Desktop.
Save tomduckering/5832357 to your computer and use it in GitHub Desktop.
A chef definition to allow you to build up config files for data dog. This example is for JMX...
define :dd_jmx_entry, :jmx_port => [],:extra_config => [] do
include_recipe 'recipe_which_makes_sure_data_dog_is_installed'
app_name = params[:name]
jmx_port = params[:jmx_port]
extra_config = params[:extra_config]
config_file_path = '/etc/dd-agent/conf.d/jmx.yaml'
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',
'type'=>'Memory',
'attribute'=>
{
'HeapMemoryUsage.used'=>
{
'metric_type'=>'gauge',
'alias'=>'jvm.memory.heap.used'
}
}
}
}
app_config['conf'] << memory_bean_config
classloading_bean_config = {
'include'=>
{
'domain'=>'java.lang',
'type'=>'ClassLoading',
'attribute'=>
{
'LoadedClassCount'=>
{
'metric_type'=>'gauge',
'alias'=>'jvm.classloading.classes.loaded'
}
}
}
}
app_config['conf'] << classloading_bean_config
runtime_bean_config = {
'include'=>
{
'domain'=>'java.lang',
'type'=>'Runtime',
'attribute'=>
{
'Uptime'=>
{
'metric_type'=>'counter',
'alias'=>'jvm.runtime.uptime'
}
}
}
}
app_config['conf'] << runtime_bean_config
# Deal with adding extra config...
Chef::Log.info("Adding extra JMX config for #{app_name}: #{extra_config}")
app_config['conf'] = app_config['conf'] + extra_config
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' #This template simply needs to include: <%= @data.to_yaml() %>
cookbook 'columbus_app'
owner 'dd-agent'
group 'root'
mode 0644
variables({:data => global_base_config })
notifies :restart, 'service[datadog-agent]', :delayed
action :nothing
end
end
config_file_template_resource.variables[:data]['instances'] << app_config
#Dummy resource to allow me to put delayed notification to the template
execute 'echo noop dd_jmx_entry' do
notifies :create, "template[#{config_file_path}]", :delayed
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment