Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Add support for Chef Solo/RightScale, fill out metadata, more directive support in template #4

Open
wants to merge 15 commits into from

5 participants

Chris Fordham Zach Little Alexander Simonov Noah Kantrowitz Dmytro Shteflyuk
Chris Fordham

The client recipe has been improved to support chef-solo where collectd servers can be specified via a node attribute.

Metadata has been completed (recipes and attribute definitions) as well as adding metadata.json back as this is required for usage on RightScale.

The Hostname and FQDNLookup directives have been added to the template for user specifiable configuration to be more flexible on arbitrary node requirements.

Zach Little

Nice work Chris!

attributes/default.rb
@@ -22,6 +22,9 @@
22 22 default[:collectd][:types_db] = ["/usr/share/collectd/types.db"]
23 23 default[:collectd][:interval] = 10
24 24 default[:collectd][:read_threads] = 5
  25 +default[:collectd][:fqdn_lookup] = "true"
1
Noah Kantrowitz Owner

Is there a particular reason to use a string instead of a real Ruby boolean? Usually nice to use native types when possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
recipes/client.rb
@@ -19,9 +19,13 @@
19 19
20 20 include_recipe "collectd"
21 21
22   -servers = []
23   -search(:node, 'recipes:"collectd::server"') do |n|
24   - servers << n['fqdn']
  22 +if node['collectd']['servers'] or Chef::Config[:solo]
1
Noah Kantrowitz Owner

Rather than just use an empty list in Solo, it would probably be better to raise an error. As I write this, it can probably be more generalized to either solo or client that finding 0 servers should be an error. What do you think of this logic?

servers = if !node[:collectd][:servers].empty?
  node[:collectd][:servers]
elsif !Chef::Config[:solo]
  search(:node, 'recipes:"collectd::server"').map {|n| n['fqdn'] }
else
 []
end
raise "something" if servers.empty?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Alexander Simonov

Any update?

Noah Kantrowitz
Owner

This variable could probably be retitled to be a little clearer, also by default the package resource uses the install action, which isn't globally idempotent since multiple servers can end up with different versions over time depending on what was "latest" when it ran (unless you pin packages some other way).

Noah Kantrowitz

Why did you remove this?

metadata.rb
@@ -5,3 +5,86 @@
5 5 long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
6 6 version "1.0.0"
7 7 supports "ubuntu"
  8 +
  9 +depends "apache2"
2
Dmytro Shteflyuk
kpumuk added a note

It only depends on apache2 if collectd_web is used. We don't use it for example

Chris Fordham
flaccid added a note

@kpumuk Chef doesn't support optional dependencies (in metadata) so technically its a dependency. What the best practice is, I'm not sure but personally I think its better to do this as recipes don't have a mechanism to even check nicely on the cookbook needed (which would also create a lot of extra redundant code in every cookbook that has optional deps).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Chris Fordham

@coderanger I have finally updated this pr! Please let me know if it needs more work before it can be merged. Thanks for your year-long patience :)

Noah Kantrowitz
Owner

Just as a heads up I'm about to get really busy for a week or two, and this no longer cleanly merges, so it may take a while to get it sorted.

Chris Fordham

No problem coderanger. I'll go on standby and look at for any action items I should do. Worse case, I don't mind re-doing the whole thing with a fresh fork, but it would be cool to avoid that if possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
22 attributes/default.rb
@@ -18,10 +18,28 @@
18 18 #
19 19
20 20 default[:collectd][:base_dir] = "/var/lib/collectd"
21   -default[:collectd][:plugin_dir] = "/usr/lib/collectd"
  21 +
  22 +case node['platform']
  23 +when "debian","ubuntu"
  24 + default[:collectd][:plugin_dir] = "/usr/lib/collectd"
  25 + default[:collectd][:config_dir] = "/etc/collectd"
  26 + default[:collectd][:config_file] = "/etc/collectd/collectd.conf"
  27 +when "redhat","centos","scientific","fedora","suse"
  28 + default[:collectd][:plugin_dir] = "/usr/lib64/collectd"
  29 + default[:collectd][:config_dir] = "/etc/collectd.d"
  30 + default[:collectd][:config_file] = "/etc/collectd.conf"
  31 +else
  32 + default[:collectd][:plugin_dir] = "/usr/lib/collectd"
  33 + default[:collectd][:config_dir] = "/etc/collectd.d"
  34 + default[:collectd][:config_file] = "/etc/collectd.conf"
  35 +end
  36 +
22 37 default[:collectd][:types_db] = ["/usr/share/collectd/types.db"]
23 38 default[:collectd][:interval] = 10
24 39 default[:collectd][:read_threads] = 5
  40 +default[:collectd][:fqdn_lookup] = true
  41 +default[:collectd][:hostname] = node[:fqdn]
  42 +default[:collectd][:servers] = []
25 43
26 44 default[:collectd][:collectd_web][:path] = "/srv/collectd_web"
27   -default[:collectd][:collectd_web][:hostname] = "collectd"
  45 +default[:collectd][:collectd_web][:hostname] = "collectd"
4 definitions/collectd_plugin.rb
@@ -18,7 +18,7 @@
18 18 #
19 19
20 20 define :collectd_plugin, :options => {}, :template => nil, :cookbook => nil do
21   - template "/etc/collectd/plugins/#{params[:name]}.conf" do
  21 + template "#{node[:collectd][:config_dir]}/plugins/#{params[:name]}.conf" do
22 22 owner "root"
23 23 group "root"
24 24 mode "644"
@@ -36,7 +36,7 @@
36 36
37 37 define :collectd_python_plugin, :options => {}, :module => nil, :path => nil do
38 38 begin
39   - t = resources(:template => "/etc/collectd/plugins/python.conf")
  39 + t = resources(:template => "#{node[:collectd][:config_dir]}/plugins/python.conf")
40 40 rescue ArgumentError
41 41 collectd_plugin "python" do
42 42 options :paths=>[node[:collectd][:plugin_dir]], :modules=>{}
97 metadata.rb
... ... @@ -1,7 +1,90 @@
1   -maintainer "Noan Kantrowitz"
2   -maintainer_email "noah@coderanger.net"
3   -license "Apache 2.0"
4   -description "Install and configure the collectd monitoring daemon"
5   -long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
6   -version "1.0.0"
7   -supports "ubuntu"
  1 +name "collectd"
  2 +maintainer "Noan Kantrowitz"
  3 +maintainer_email "noah@coderanger.net"
  4 +license "Apache 2.0"
  5 +description "Install and configure the collectd monitoring daemon"
  6 +long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
  7 +version "1.0.0"
  8 +
  9 +depends "apache2"
  10 +
  11 +%w{ debian ubuntu centos redhat fedora }.each do |os|
  12 + supports os
  13 +end
  14 +
  15 +recipe "collectd", "Install a standalone daemon."
  16 +recipe "collectd::client", "Install collectd and configure it to send data to a server."
  17 +recipe "collectd::server", "Install collectd and configure it to recieve data from clients."
  18 +recipe "collectd::collectd_web", "Installs and configures collectd_web."
  19 +
  20 +attribute "collectd/base_dir",
  21 + :display_name => "collectd Base Directory",
  22 + :description => "The base directory for collectd.",
  23 + :required => "optional",
  24 + :default => "/var/lib/collectd",
  25 + :recipes => [ "collectd::default" ]
  26 +
  27 +attribute "collectd/plugin_dir",
  28 + :display_name => "collectd Plugin Directory",
  29 + :description => "The plugin directory for collectd.",
  30 + :required => "optional",
  31 + :default => "/usr/lib/collectd" ,
  32 + :recipes => [ "collectd::default" ]
  33 +
  34 +attribute "collectd/types_db",
  35 + :display_name => "collectd Types Database",
  36 + :description => "The location of the collectd types.db file.",
  37 + :required => "optional",
  38 + :type => "array",
  39 + :default => [ "/usr/share/collectd/types.db" ],
  40 + :recipes => [ "collectd::default" ]
  41 +
  42 +attribute "collectd/interval",
  43 + :display_name => "collectd Polling Interval",
  44 + :description => "The collectd interval setting value.",
  45 + :required => "optional",
  46 + :default => "20",
  47 + :recipes => [ "collectd::default" ]
  48 +
  49 +attribute "collectd/read_threads",
  50 + :display_name => "collectd Read Threads",
  51 + :description => "The collectd read threads setting value.",
  52 + :required => "optional",
  53 + :default => "5",
  54 + :recipes => [ "collectd::default" ]
  55 +
  56 +#attribute "collectd/servers",
  57 +# :display_name => "collectd Servers",
  58 +# :description => "The collectd servers to send to as a client.",
  59 +# :required => "optional",
  60 +# :default => nil,
  61 +# :type => "array",
  62 +# :recipes => [ "collectd::client" ]
  63 +
  64 +attribute "collectd/hostname",
  65 + :display_name => "collectd Hostname",
  66 + :description => "The collectd Hostname setting value.",
  67 + :required => "optional",
  68 + :recipes => [ "collectd::default" ]
  69 +
  70 +attribute "collectd/fqdn_lookup",
  71 + :display_name => "collectd FQDNLookup",
  72 + :description => "The collectd FQDNLookup setting value.",
  73 + :required => "optional",
  74 + :recipes => [ "collectd::default" ],
  75 + :choice => [ "true", "false" ],
  76 + :default => "true"
  77 +
  78 +attribute "collectd/collectd_web/path",
  79 + :display_name => "collectd_web path",
  80 + :description => "The collectd_web install path.",
  81 + :required => "optional",
  82 + :default => "/srv/collectd_web",
  83 + :recipes => [ "collectd::collectd_web" ]
  84 +
  85 +attribute "collectd/collectd_web/hostname",
  86 + :display_name => "collectd_web hostname",
  87 + :description => "The collectd_web hostname.",
  88 + :required => "optional",
  89 + :default => "collectd",
  90 + :recipes => [ "collectd::collectd_web" ]
19 recipes/client.rb
@@ -19,15 +19,20 @@
19 19
20 20 include_recipe "collectd"
21 21
22   -servers = []
23   -search(:node, 'recipes:"collectd::server"') do |n|
24   - servers << n['fqdn']
25   -end
26   -
  22 +servers =
  23 + if !node[:collectd][:servers].empty?
  24 + node[:collectd][:servers]
  25 + elsif !Chef::Config[:solo]
  26 + search(:node, 'recipes:"collectd::server"').map {|n| n['fqdn'] }
  27 + end
27 28 if servers.empty?
28   - raise "No servers found. Please configure at least one node with collectd::server."
  29 + if Chef::Config[:solo]
  30 + raise "No collectd servers found. Please configure at least one server in Chef Solo with collectd['servers']."
  31 + else
  32 + raise "No collectd servers found. Please configure at least one server node using collectd::server."
  33 + end
29 34 end
30 35
31 36 collectd_plugin "network" do
32 37 options :server=>servers
33   -end
  38 +end
21 recipes/default.rb
@@ -17,21 +17,28 @@
17 17 # limitations under the License.
18 18 #
19 19
20   -package "collectd" do
21   - package_name "collectd-core"
22   -end
  20 +package = value_for_platform(
  21 + ["centos", "redhat", "suse", "fedora" ] => {
  22 + "default" => "collectd"
  23 + },
  24 + ["ubuntu", "debian"] => {
  25 + "default" => "collectd-core"
  26 + },
  27 + "default" => "collectd"
  28 +)
  29 +package package
23 30
24 31 service "collectd" do
25 32 supports :restart => true, :status => true
26 33 end
27 34
28   -directory "/etc/collectd" do
  35 +directory node[:collectd][:config_dir] do
29 36 owner "root"
30 37 group "root"
31 38 mode "755"
32 39 end
33 40
34   -directory "/etc/collectd/plugins" do
  41 +directory "#{node[:collectd][:config_dir]}/plugins" do
35 42 owner "root"
36 43 group "root"
37 44 mode "755"
@@ -52,7 +59,7 @@
52 59 end
53 60
54 61 %w(collectd collection thresholds).each do |file|
55   - template "/etc/collectd/#{file}.conf" do
  62 + template "#{node[:collectd][:config_dir]}/#{file}.conf" do
56 63 source "#{file}.conf.erb"
57 64 owner "root"
58 65 group "root"
@@ -63,7 +70,7 @@
63 70
64 71 ruby_block "delete_old_plugins" do
65 72 block do
66   - Dir['/etc/collectd/plugins/*.conf'].each do |path|
  73 + Dir["#{node[:collectd][:config_dir]}/plugins/*.conf"].each do |path|
67 74 autogen = false
68 75 File.open(path).each_line do |line|
69 76 if line.start_with?('#') and line.include?('autogenerated')
4 templates/default/collectd.conf.erb
@@ -6,8 +6,8 @@
6 6 # You should also read /usr/share/doc/collectd/README.Debian.plugins before
7 7 # enabling any more plugins.
8 8
9   -Hostname "<%= @node[:fqdn] %>"
10   -FQDNLookup true
  9 +Hostname "<%= @node[:collectd][:hostname] %>"
  10 +FQDNLookup <%= @node[:collectd][:fqdn_lookup] %>
11 11 BaseDir "<%= @node[:collectd][:base_dir] %>"
12 12 PluginDir "<%= @node[:collectd][:plugin_dir] %>"
13 13 TypesDB "<%= @node[:collectd][:types_db].join('", "') %>"

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.