Permalink
Browse files

Initial commit of collectd cookbook.

  • Loading branch information...
0 parents commit 6b666ca4ac60f6784a8188f43578857b64194cc8 @coderanger committed Feb 22, 2012
@@ -0,0 +1,92 @@
+# 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::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:
+
+```ruby
+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:
+
+```ruby
+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:
+
+```ruby
+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 (<noah@coderanger.net>)
+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.
@@ -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"
@@ -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
@@ -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
@@ -0,0 +1,7 @@
+maintainer "Noan Kantrowitz"
+maintainer_email "noah@coderanger.net"
+license "Apache 2.0"
+description "Install and configure the collectd monitoring daemon"
+long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
+version "1.0.0"
+supports "ubuntu"
@@ -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
@@ -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"
Oops, something went wrong.

0 comments on commit 6b666ca

Please sign in to comment.