Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit of the collectd cookbook.

  • Loading branch information...
commit 20d58e7326bbc73c19c3d5b0ee987efb7a31acef 0 parents
@coderanger coderanger authored
85 README.rdoc
@@ -0,0 +1,85 @@
+= DESCRIPTION:
+
+Configure and install the collectd[http://collectd.org/] monitoring daemon.
+
+= REQUIREMENTS:
+
+This cookbook has only been tested on Ubuntu 10.04.
+
+To use the collectd_web recipe you need the apache2[https://github.com/opscode/cookbooks/tree/master/apache2] cookbook.
+
+The 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.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.
+
+* collectd.collectd_web.path - Location to install collectd_web to. Defaults to /srv/collectd_web.
+* collectd.collectd_web.hostname - Server name to use for collectd_web Apache site.
+
+= USAGE:
+
+Three main recipes are provided:
+* collectd - Install a standalone daemon.
+* collectd::client - Install collectd and configure it to send data to a server.
+* collectd::server - Install collectd and configure it to recieve data from clients.
+
+The client recipe will use the search index to automatically locate the server hosts, so no manual configuration is required.
+
+== Defines:
+
+Several defines are provided to simplfy configuring plugins
+
+=== collectd_plugin:
+
+The +collectd_plugin+ define configures and enables standard collect plugins. Example:
+
+ collectd_plugin "interface" do
+ options :interface=>"lo", :ignore_selected=>true
+ end
+
+The options hash is converted to collectd-style settings automatically. Any symbol key will be converted to camel-case. In the above example :ignore_selected will be output as the
+key "IgnoreSelected". If the key is already a string, this conversion is skipped. If the value is an array, it will be output as a separate line for each element.
+
+=== collectd_python_plugin:
+
+The +collectd_python_plugin+ define configures and enables Python plugins using the collectd-python plugin. Example:
+
+ collectd_python_plugin "redis" do
+ options :host=>servers, :verbose=>true
+ end
+
+Options are interpreted in the same way as with +collectd_plugin+. This define will not deploy the plugin script as well, so be sure to setup a cookbook_file resource
+or other mechanism to handle distribution. Example:
+
+ cookbook_file File.join(node[:collectd][:plugin_dir], "redis.py") do
+ owner "root"
+ group "root"
+ mode "644"
+ end
+
+== Web frontend:
+
+The +collectd::collectd_web+ recipe will automatically deploy the collectd_web[https://github.com/httpdss/collectd-web] frontend using Apache. The
+apache2[https://github.com/opscode/cookbooks/tree/master/apache2] cookbook is required for this and is *not* included automatically as this is an optional
+component, so be sure to configure the node with the correct recipes.
+
+= LICENSE & AUTHOR:
+
+Author:: Noah Kantrowitz (<nkantrowitz@crypticstudios.com>)
+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.
27 attributes/default.rb
@@ -0,0 +1,27 @@
+#
+# Cookbook Name:: collectd
+# Attributes:: default
+#
+# 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.
+#
+
+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][:collectd_web][:path] = "/srv/collectd_web"
+default[:collectd][:collectd_web][:hostname] = "collectd"
52 definitions/collectd_plugin.rb
@@ -0,0 +1,52 @@
+#
+# Cookbook Name:: collectd
+# Definition:: collectd_plugin
+#
+# 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.
+#
+
+define :collectd_plugin, :options => {}, :template => nil, :cookbook => nil do
+ template "/etc/collectd/plugins/#{params[:name]}.conf" do
+ owner "root"
+ group "root"
+ mode "644"
+ if params[:template].blank?
+ source "plugin.conf.erb"
+ cookbook params[:cookbook] || "collectd"
+ else
+ source params[:template]
+ cookbook params[:cookbook]
+ end
+ variables :name=>params[:name], :options=>params[:options]
+ notifies :restart, resources(:service => "collectd")
+ end
+end
+
+define :collectd_python_plugin, :options => {}, :module => nil, :path => nil do
+ begin
+ t = resources(:template => "/etc/collectd/plugins/python.conf")
+ rescue ArgumentError
+ collectd_plugin "python" do
+ options :paths=>[node[:collectd][:plugin_dir]], :modules=>{}
+ template "python_plugin.conf.erb"
+ cookbook "collectd"
+ end
+ retry
+ end
+ if not params[:path].blank?
+ t.variables[:options][:paths] << params[:path]
+ end
+ t.variables[:options][:modules][params[:module] || params[:name]] = params[:options]
+end
47 libraries/default.rb
@@ -0,0 +1,47 @@
+#
+# Cookbook Name:: collectd
+# Library:: default
+#
+# 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.
+#
+
+def collectd_key(option)
+ return option.to_s.split('_').map{|x| x.capitalize}.join() if option.instance_of?(Symbol)
+ "#{option}"
+end
+
+def collectd_option(option)
+ return option if option.instance_of?(Fixnum) || option == true || option == false
+ "\"#{option}\""
+end
+
+def collectd_settings(options, level=0)
+ indent = ' ' * level
+ output = []
+ options.each_pair do |key, value|
+ if value.is_a? Array
+ value.each do |subvalue|
+ output << "#{indent}#{collectd_key(key)} #{collectd_option(subvalue)}"
+ end
+ elsif value.is_a? Hash
+ value.each_pair do |name, suboptions|
+ output << "#{indent}<#{key} \"#{name}\">\n#{collectd_settings(suboptions, level+1)}\n#{indent}</#{key}>"
+ end
+ else
+ output << "#{indent}#{collectd_key(key)} #{collectd_option(value)}"
+ end
+ end
+ output.join("\n")
+end
7 metadata.rb
@@ -0,0 +1,7 @@
+maintainer "Noan Kantrowitz"
+maintainer_email "nkantrowitz@crypticstudios.com"
+license "Apache 2.0"
+description "Install and configure the collectd monitoring daemon"
+long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
+version "1.0.0"
+supports "ubuntu"
33 recipes/client.rb
@@ -0,0 +1,33 @@
+#
+# Cookbook Name:: collectd
+# Recipe:: client
+#
+# 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.
+#
+
+include_recipe "collectd"
+
+servers = []
+search(:node, 'recipes:"collectd::server"') do |n|
+ servers << n['fqdn']
+end
+
+if servers.empty?
+ raise "No servers found. Please configure at least one node with collectd::server."
+end
+
+collectd_plugin "network" do
+ options :server=>servers
+end
49 recipes/collectd_web.rb
@@ -0,0 +1,49 @@
+#
+# Cookbook Name:: collectd
+# Recipe:: collectd_web
+#
+# 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.
+#
+
+include_recipe "collectd"
+include_recipe "apache2"
+
+directory node[:collectd][:collectd_web][:path] do
+ owner "root"
+ group "root"
+ mode "755"
+end
+
+bash "install_collectd_web" do
+ user "root"
+ cwd node[:collectd][:collectd_web][:path]
+ not_if do
+ File.exists?(File.join(node[:collectd][:collectd_web][:path], "index.html"))
+ end
+ code <<-EOH
+ wget --no-check-certificate -O collectd-web.tar.gz https://github.com/httpdss/collectd-web/tarball/master
+ tar --strip-components=1 -xzf collectd-web.tar.gz
+ rm collectd-web.tar.gz
+ EOH
+end
+
+template "/etc/apache2/sites-available/collectd_web.conf" do
+ source "collectd_web.conf.erb"
+ owner "root"
+ group "root"
+ mode "644"
+end
+
+apache_site "collectd_web.conf"
89 recipes/default.rb
@@ -0,0 +1,89 @@
+#
+# Cookbook Name:: collectd
+# Recipe:: default
+#
+# 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.
+#
+
+package "collectd" do
+ package_name "collectd-core"
+end
+
+service "collectd" do
+ supports :restart => true, :status => true
+end
+
+directory "/etc/collectd" do
+ owner "root"
+ group "root"
+ mode "755"
+end
+
+directory "/etc/collectd/plugins" do
+ owner "root"
+ group "root"
+ mode "755"
+end
+
+directory node[:collectd][:base_dir] do
+ owner "root"
+ group "root"
+ mode "755"
+ recursive true
+end
+
+directory node[:collectd][:plugin_dir] do
+ owner "root"
+ group "root"
+ mode "755"
+ recursive true
+end
+
+%w(collectd collection thresholds).each do |file|
+ template "/etc/collectd/#{file}.conf" do
+ source "#{file}.conf.erb"
+ owner "root"
+ group "root"
+ mode "644"
+ notifies :restart, resources(:service => "collectd")
+ end
+end
+
+ruby_block "delete_old_plugins" do
+ block do
+ Dir['/etc/collectd/plugins/*.conf'].each do |path|
+ autogen = false
+ File.open(path).each_line do |line|
+ if line.start_with?('#') and line.include?('autogenerated')
+ autogen = true
+ break
+ end
+ end
+ if autogen
+ begin
+ resources(:template => path)
+ rescue ArgumentError
+ # If the file is autogenerated and has no template it has likely been removed from the run list
+ Chef::Log.info("Deleting old plugin config in #{path}")
+ File.unlink(path)
+ end
+ end
+ end
+ end
+end
+
+service "collectd" do
+ action [:enable, :start]
+end
24 recipes/server.rb
@@ -0,0 +1,24 @@
+#
+# Cookbook Name:: collectd
+# Recipe:: server
+#
+# 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.
+#
+
+include_recipe "collectd"
+
+collectd_plugin "network" do
+ options :listen=>'0.0.0.0'
+end
18 templates/default/collectd.conf.erb
@@ -0,0 +1,18 @@
+# Config file for collectd(1).
+#
+# Some plugins need additional configuration and are disabled by default.
+# Please read collectd.conf(5) for details.
+#
+# You should also read /usr/share/doc/collectd/README.Debian.plugins before
+# enabling any more plugins.
+
+Hostname "<%= @node[:fqdn] %>"
+FQDNLookup true
+BaseDir "<%= @node[:collectd][:base_dir] %>"
+PluginDir "<%= @node[:collectd][:plugin_dir] %>"
+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"
32 templates/default/collectd_web.conf.erb
@@ -0,0 +1,32 @@
+<VirtualHost *:80>
+ ServerName <%= @node[:collectd][:collectd_web][:hostname] %>
+
+ DocumentRoot <%= @node[:collectd][:collectd_web][:path] %>
+ <Directory />
+ Options FollowSymLinks
+ AllowOverride None
+ </Directory>
+ <Directory <%= @node[:collectd][:collectd_web][:path] %>>
+ Options Indexes FollowSymLinks MultiViews
+ AllowOverride None
+ Order allow,deny
+ Allow from all
+ </Directory>
+
+ ScriptAlias /cgi-bin/ <%= @node[:collectd][:collectd_web][:path] %>/cgi-bin/
+ <Directory "<%= @node[:collectd][:collectd_web][:path] %>/cgi-bin">
+ AllowOverride None
+ Options ExecCGI -MultiViews
+ Order allow,deny
+ Allow from all
+ </Directory>
+
+ ErrorLog /var/log/apache2/error.log
+
+ # Possible values include: debug, info, notice, warn, error, crit,
+ # alert, emerg.
+ LogLevel warn
+
+ CustomLog /var/log/apache2/access.log combined
+ ServerSignature On
+</VirtualHost>
2  templates/default/collection.conf.erb
@@ -0,0 +1,2 @@
+datadir: "/var/lib/collectd/rrd/"
+libdir: "/usr/lib/collectd/"
15 templates/default/plugin.conf.erb
@@ -0,0 +1,15 @@
+# This file autogenerated by Chef
+# Do not edit, changes will be overwritten
+LoadPlugin "<%= @name %>"
+
+<% if not @options.empty? %>
+<Plugin "<%= @name %>">
+ <% @options.each_pair do |key, value|
+ if value.is_a? Array
+ value.each do |subvalue| %>
+ <%= collectd_key(key) %> <%= collectd_option(subvalue) %>
+ <% end else %>
+ <%= collectd_key(key) %> <%= collectd_option(value) %>
+ <% end end %>
+</Plugin>
+<% end %>
20 templates/default/python_plugin.conf.erb
@@ -0,0 +1,20 @@
+# This file autogenerated by Chef
+# Do not edit, changes will be overwritten
+<LoadPlugin python>
+ Globals true
+</LoadPlugin>
+
+<Plugin python>
+ <% @options[:paths].each do |path| %>
+ ModulePath "<%= path %>"
+ <% end %>
+ <% @options[:modules].each_key do |mod| %>
+ Import "<%= mod %>"
+ <% end %>
+
+ <% @options[:modules].each_pair do |mod, config| %>
+ <Module "<%= mod %>">
+<%= collectd_settings(config, 2) %>
+ </Module>
+ <% end %>
+</Plugin>
37 templates/default/thresholds.conf.erb
@@ -0,0 +1,37 @@
+# Threshold configuration for collectd(1).
+#
+# See the section "THRESHOLD CONFIGURATION" in collectd.conf(5) for details.
+
+#<Threshold>
+# <Type "counter">
+# WarningMin 0.00
+# WarningMax 1000.00
+# FailureMin 0
+# FailureMax 1200.00
+# Invert false
+# Persist false
+# Instance "some_instance"
+# </Type>
+#
+# <Plugin "interface">
+# Instance "eth0"
+# <Type "if_octets">
+# DataSource "rx"
+# FailureMax 10000000
+# </Type>
+# </Plugin>
+#
+# <Host "hostname">
+# <Type "cpu">
+# Instance "idle"
+# FailureMin 10
+# </Type>
+#
+# <Plugin "memory">
+# <Type "memory">
+# Instance "cached"
+# WarningMin 100000000
+# </Type>
+# </Plugin>
+# </Host>
+#</Threshold>
Please sign in to comment.
Something went wrong with that request. Please try again.