diff --git a/.gitignore b/.gitignore index 5598138..c0603da 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,22 @@ metadata.json +*~ +*# +.#* +\#*# +.*.sw[a-z] +*.un~ +pkg/ + +# Berkshelf +.vagrant +/cookbooks +Berksfile.lock + +# Bundler +Gemfile.lock +bin/* +.bundle/* + +.kitchen/ +.kitchen.local.yml diff --git a/.kitchen.yml b/.kitchen.yml new file mode 100644 index 0000000..a5addb9 --- /dev/null +++ b/.kitchen.yml @@ -0,0 +1,21 @@ +--- +driver: + name: vagrant + +provisioner: + name: chef_zero + +platforms: + - name: ubuntu-10.04 + - name: ubuntu-12.04 + +suites: + - name: default + run_list: + - "recipe[apt]" + - "recipe[collectd]" + attributes: + - name: server + run_list: + - "recipe[apt]" + - "recipe[collectd::server]" diff --git a/Berksfile b/Berksfile new file mode 100644 index 0000000..2e1a070 --- /dev/null +++ b/Berksfile @@ -0,0 +1,3 @@ +source "https://api.berkshelf.com" + +metadata diff --git a/README.md b/README.md index 10d7e5d..bbad530 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,18 @@ Configure and install the [collectd](http://collectd.org/) monitoring daemon. # REQUIREMENTS # -This cookbook has only been tested on Ubuntu 10.04. +This cookbook has only been tested on Ubuntu 10.04 and Mac OS X 10.8. The homebrew cookbook is required to install the collectd package on Mac OS X. To use the `collectd::collectd_web` recipe you need the [apache2](https://github.com/opscode/cookbooks/tree/master/apache2) cookbook. +To use this cookbook on Mac OS X, you need to include the [homebrew](https://github.com/opscode-cookbooks/homebrew) cookbook in your node's run list before including this cookbook. + The [collectd_plugins](https://github.com/coderanger/chef-collectd_plugins) cookbook is not required, but provides many common plugin definitions for easy reuse. # ATTRIBUTES # * collectd.basedir - Base folder for collectd output data. +* collectd.cfg_dir - Base folder for collectd configuration files. * collectd.plugin_dir - Base folder to find plugins. * collectd.types_db - Array of files to read graph type information from. * collectd.interval - Time period in seconds to wait between data reads. diff --git a/attributes/default.rb b/attributes/default.rb index 0c81e17..f02feaf 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -17,12 +17,27 @@ # limitations under the License. # -default[:collectd][:base_dir] = "/var/lib/collectd" -default[:collectd][:plugin_dir] = "/usr/lib/collectd" -default[:collectd][:types_db] = ["/usr/share/collectd/types.db"] default[:collectd][:interval] = 10 default[:collectd][:read_threads] = 5 -default[:collectd][:pkg_name] = "collectd-core" + +case node[:platform_family] +when "mac_os_x" + default[:collectd][:base_dir] = "/usr/local/var/lib/collectd" + default[:collectd][:cfg_dir] = "/usr/local/etc/collectd" + default[:collectd][:cfg_group] = "wheel" + default[:collectd][:plugin_dir] = "/usr/local/lib/collectd" + default[:collectd][:types_db] = ["/usr/local/share/collectd/types.db"] + default[:collectd][:pkg_name] = "collectd" + default[:collectd][:svc_name] = "homebrew.mxcl.collectd" +else + default[:collectd][:base_dir] = "/var/lib/collectd" + default[:collectd][:cfg_dir] = "/etc/collectd" + default[:collectd][:cfg_group] = "root" + default[:collectd][:plugin_dir] = "/usr/lib/collectd" + default[:collectd][:types_db] = ["/usr/share/collectd/types.db"] + default[:collectd][:pkg_name] = "collectd-core" + default[:collectd][:svc_name] = "collectd" +end default[:collectd][:collectd_web][:path] = "/srv/collectd_web" default[:collectd][:collectd_web][:hostname] = "collectd" diff --git a/definitions/collectd_plugin.rb b/definitions/collectd_plugin.rb index 75c665f..6e255a5 100644 --- a/definitions/collectd_plugin.rb +++ b/definitions/collectd_plugin.rb @@ -18,9 +18,9 @@ # define :collectd_plugin, :options => {}, :template => nil, :cookbook => nil do - template "/etc/collectd/plugins/#{params[:name]}.conf" do + template "#{node[:collectd][:cfg_dir]}/plugins/#{params[:name]}.conf" do owner "root" - group "root" + group node[:collectd][:cfg_group] mode "644" if params[:template].nil? source "plugin.conf.erb" @@ -36,7 +36,7 @@ define :collectd_python_plugin, :options => {}, :module => nil, :path => nil do begin - t = resources(:template => "/etc/collectd/plugins/python.conf") + t = resources(:template => "#{node[:collectd][:cfg_dir]}/plugins/python.conf") rescue ArgumentError,Chef::Exceptions::ResourceNotFound collectd_plugin "python" do options :paths=>[node[:collectd][:plugin_dir]], :modules=>{} diff --git a/files/default/service/homebrew.mxcl.collectd.plist b/files/default/service/homebrew.mxcl.collectd.plist new file mode 100644 index 0000000..485a1ad --- /dev/null +++ b/files/default/service/homebrew.mxcl.collectd.plist @@ -0,0 +1,23 @@ + + + + + KeepAlive + + Label + homebrew.mxcl.collectd + ProgramArguments + + /usr/local/Cellar/collectd/5.4.1/sbin/collectd + -f + -C + /usr/local/etc/collectd.conf + + RunAtLoad + + StandardErrorPath + /usr/local/var/log/collectd.log + StandardOutPath + /usr/local/var/log/collectd.log + + diff --git a/metadata.rb b/metadata.rb index 3a0d763..bd60291 100644 --- a/metadata.rb +++ b/metadata.rb @@ -5,4 +5,9 @@ description "Install and configure the collectd monitoring daemon" long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) version "1.0.0" +supports "mac_os_x" supports "ubuntu" +suggests "homebrew" + +# Testing dependencies +depends "apt", ">= 2.4.0" diff --git a/recipes/default.rb b/recipes/default.rb index a34d2a8..913faf0 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -21,49 +21,51 @@ package_name node[:collectd][:pkg_name] end -service "collectd" do - supports :restart => true, :status => true -end - -directory "/etc/collectd" do +directory node[:collectd][:cfg_dir] do owner "root" - group "root" + group node[:collectd][:cfg_group] mode "755" end -directory "/etc/collectd/plugins" do +directory "#{node[:collectd][:cfg_dir]}/plugins" do owner "root" - group "root" + group node[:collectd][:cfg_group] mode "755" end directory node[:collectd][:base_dir] do owner "root" - group "root" + group node[:collectd][:cfg_group] mode "755" recursive true end directory node[:collectd][:plugin_dir] do owner "root" - group "root" + group node[:collectd][:cfg_group] mode "755" recursive true end %w(collectd collection thresholds).each do |file| - template "/etc/collectd/#{file}.conf" do + template "#{node[:collectd][:cfg_dir]}/#{file}.conf" do source "#{file}.conf.erb" owner "root" - group "root" + group node[:collectd][:cfg_group] mode "644" - notifies :restart, resources(:service => "collectd") + notifies :restart, "service[collectd]" + end +end + +if node[:platform_family] == "mac_os_x" + link "/usr/local/etc/collectd.conf" do + to "/usr/local/etc/collectd/collectd.conf" end end ruby_block "delete_old_plugins" do block do - Dir['/etc/collectd/plugins/*.conf'].each do |path| + Dir["#{node[:collectd][:cfg_dir]}/plugins/*.conf"].each do |path| autogen = false File.open(path).each_line do |line| if line.start_with?('#') and line.include?('autogenerated') @@ -84,6 +86,4 @@ end end -service "collectd" do - action [:enable, :start] -end +include_recipe "collectd::service" diff --git a/recipes/service.rb b/recipes/service.rb new file mode 100644 index 0000000..f84ed47 --- /dev/null +++ b/recipes/service.rb @@ -0,0 +1,33 @@ +# +# Cookbook Name:: collectd +# Recipe:: service +# +# Copyright 2010, Atari, Inc +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +if node[:platform_family] == "mac_os_x" + cookbook_file "/System/Library/LaunchDaemons/homebrew.mxcl.collectd.plist" do + source "service/homebrew.mxcl.collectd.plist" + owner "root" + group "wheel" + mode 00644 + end +end + +service "collectd" do + service_name node[:collectd][:svc_name] + supports :restart => true, :status => true + action [:enable, :start] +end diff --git a/templates/default/collectd.conf.erb b/templates/default/collectd.conf.erb index b1e3964..94c0216 100644 --- a/templates/default/collectd.conf.erb +++ b/templates/default/collectd.conf.erb @@ -6,7 +6,7 @@ # You should also read /usr/share/doc/collectd/README.Debian.plugins before # enabling any more plugins. -Hostname "<%= @node[:fqdn] %>" +Hostname "<%= @node[:fqdn] || @node[:hostname] %>" FQDNLookup true BaseDir "<%= @node[:collectd][:base_dir] %>" PluginDir "<%= @node[:collectd][:plugin_dir] %>" @@ -14,5 +14,5 @@ TypesDB "<%= @node[:collectd][:types_db].join('", "') %>" Interval <%= @node[:collectd][:interval] %> ReadThreads <%= @node[:collectd][:read_threads] %> -Include "/etc/collectd/plugins/*.conf" -Include "/etc/collectd/thresholds.conf" +Include "<%= @node[:collectd][:cfg_dir] %>/plugins/*.conf" +Include "<%= @node[:collectd][:cfg_dir] %>/thresholds.conf"