Skip to content
This repository was archived by the owner on Dec 31, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,28 @@
#

default[:collectd][:base_dir] = "/var/lib/collectd"
default[:collectd][:plugin_dir] = "/usr/lib/collectd"

case node['platform']
when "debian","ubuntu"
default[:collectd][:plugin_dir] = "/usr/lib/collectd"
default[:collectd][:config_dir] = "/etc/collectd"
default[:collectd][:config_file] = "/etc/collectd/collectd.conf"
when "redhat","centos","scientific","fedora","suse"
default[:collectd][:plugin_dir] = "/usr/lib64/collectd"
default[:collectd][:config_dir] = "/etc/collectd.d"
default[:collectd][:config_file] = "/etc/collectd.conf"
else
default[:collectd][:plugin_dir] = "/usr/lib/collectd"
default[:collectd][:config_dir] = "/etc/collectd.d"
default[:collectd][:config_file] = "/etc/collectd.conf"
end

default[:collectd][:types_db] = ["/usr/share/collectd/types.db"]
default[:collectd][:interval] = 10
default[:collectd][:read_threads] = 5
default[:collectd][:fqdn_lookup] = "true"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

default[:collectd][:hostname] = node[:fqdn]
default[:collectd][:servers] = []

default[:collectd][:collectd_web][:path] = "/srv/collectd_web"
default[:collectd][:collectd_web][:hostname] = "collectd"
default[:collectd][:collectd_web][:hostname] = "collectd"
4 changes: 2 additions & 2 deletions definitions/collectd_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#

define :collectd_plugin, :options => {}, :template => nil, :cookbook => nil do
template "/etc/collectd/plugins/#{params[:name]}.conf" do
template "#{node[:collectd][:config_dir]}/plugins/#{params[:name]}.conf" do
owner "root"
group "root"
mode "644"
Expand All @@ -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][:config_dir]}/plugins/python.conf")
rescue ArgumentError
collectd_plugin "python" do
options :paths=>[node[:collectd][:plugin_dir]], :modules=>{}
Expand Down
83 changes: 83 additions & 0 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,86 @@
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "1.0.0"
supports "ubuntu"

depends "apache2"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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).


%w{ debian ubuntu centos redhat fedora }.each do |os|
supports os
end

recipe "collectd", "Install a standalone daemon."
recipe "collectd::client", "Install collectd and configure it to send data to a server."
recipe "collectd::server", "Install collectd and configure it to recieve data from clients."
recipe "collectd::collectd_web", "Installs and configures collectd_web."

attribute "collectd/base_dir",
:display_name => "collectd Base Directory",
:description => "The base directory for collectd.",
:required => "optional",
:default => "/var/lib/collectd",
:recipes => [ "collectd::default" ]

attribute "collectd/plugin_dir",
:display_name => "collectd Plugin Directory",
:description => "The plugin directory for collectd.",
:required => "optional",
:default => "/usr/lib/collectd" ,
:recipes => [ "collectd::default" ]

attribute "collectd/types_db",
:display_name => "collectd Types Database",
:description => "The location of the collectd types.db file.",
:required => "optional",
:type => "array",
:default => [ "/usr/share/collectd/types.db" ],
:recipes => [ "collectd::default" ]

attribute "collectd/interval",
:display_name => "collectd Polling Interval",
:description => "The collectd interval setting value.",
:required => "optional",
:default => "20",
:recipes => [ "collectd::default" ]

attribute "collectd/read_threads",
:display_name => "collectd Read Threads",
:description => "The collectd read threads setting value.",
:required => "optional",
:default => "5",
:recipes => [ "collectd::default" ]

#attribute "collectd/servers",
# :display_name => "collectd Servers",
# :description => "The collectd servers to send to as a client.",
# :required => "optional",
# :default => nil,
# :type => "array",
# :recipes => [ "collectd::client" ]

attribute "collectd/hostname",
:display_name => "collectd Hostname",
:description => "The collectd Hostname setting value.",
:required => "optional",
:recipes => [ "collectd::default" ]

attribute "collectd/fqdn_lookup",
:display_name => "collectd FQDNLookup",
:description => "The collectd FQDNLookup setting value.",
:required => "optional",
:recipes => [ "collectd::default" ],
:choice => [ "true", "false" ],
:default => "true"

attribute "collectd/collectd_web/path",
:display_name => "collectd_web path",
:description => "The collectd_web install path.",
:required => "optional",
:default => "/srv/collectd_web",
:recipes => [ "collectd::collectd_web" ]

attribute "collectd/collectd_web/hostname",
:display_name => "collectd_web hostname",
:description => "The collectd_web hostname.",
:required => "optional",
:default => "collectd",
:recipes => [ "collectd::collectd_web" ]
12 changes: 8 additions & 4 deletions recipes/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@

include_recipe "collectd"

servers = []
search(:node, 'recipes:"collectd::server"') do |n|
servers << n['fqdn']
if node['collectd']['servers'] or Chef::Config[:solo]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

servers = node['collectd']['servers']
else
servers = []
search(:node, 'recipes:"collectd::server"') do |n|
servers << n['fqdn']
end
end

if servers.empty?
Expand All @@ -30,4 +34,4 @@

collectd_plugin "network" do
options :server=>servers
end
end
21 changes: 14 additions & 7 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,28 @@
# limitations under the License.
#

package "collectd" do
package_name "collectd-core"
end
package = value_for_platform(
["centos", "redhat", "suse", "fedora" ] => {
"default" => "collectd"
},
["ubuntu", "debian"] => {
"default" => "collectd-core"
},
"default" => "collectd"
)
package package

service "collectd" do
supports :restart => true, :status => true
end

directory "/etc/collectd" do
directory node[:collectd][:config_dir] do
owner "root"
group "root"
mode "755"
end

directory "/etc/collectd/plugins" do
directory "#{node[:collectd][:config_dir]}/plugins" do
owner "root"
group "root"
mode "755"
Expand All @@ -52,7 +59,7 @@
end

%w(collectd collection thresholds).each do |file|
template "/etc/collectd/#{file}.conf" do
template "#{node[:collectd][:config_dir]}/#{file}.conf" do
source "#{file}.conf.erb"
owner "root"
group "root"
Expand All @@ -63,7 +70,7 @@

ruby_block "delete_old_plugins" do
block do
Dir['/etc/collectd/plugins/*.conf'].each do |path|
Dir["#{node[:collectd][:config_dir]}/plugins/*.conf"].each do |path|
autogen = false
File.open(path).each_line do |line|
if line.start_with?('#') and line.include?('autogenerated')
Expand Down
4 changes: 2 additions & 2 deletions templates/default/collectd.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
# You should also read /usr/share/doc/collectd/README.Debian.plugins before
# enabling any more plugins.

Hostname "<%= @node[:fqdn] %>"
FQDNLookup true
Hostname "<%= @node[:collectd][:hostname] %>"
FQDNLookup <%= @node[:collectd][:fqdn_lookup] %>
BaseDir "<%= @node[:collectd][:base_dir] %>"
PluginDir "<%= @node[:collectd][:plugin_dir] %>"
TypesDB "<%= @node[:collectd][:types_db].join('", "') %>"
Expand Down